From 76cc852527a117e1cbff7f2ea80afa9033abb422 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 8 Oct 2015 15:37:27 +0200 Subject: Adjust the rake task to make id = invite code This will simplify invite code deletion after running tests. --- app/models/invite_code.rb | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 30a6498..8f69582 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -1,4 +1,3 @@ -require 'coupon_code' class InviteCode < CouchRest::Model::Base use_database 'invite_codes' @@ -14,9 +13,11 @@ class InviteCode < CouchRest::Model::Base def initialize(attributes = {}, options = {}) super(attributes, options) - write_attribute('invite_code', CouponCode.generate) if new? end + def set_invite_code(code) + write_attribute(:invite_code, code) + end end -- cgit v1.2.3 From 2541d08598c2bc4ce04f63b4ed4056ffb044a596 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 8 Oct 2015 17:00:04 +0200 Subject: Fix the InviteCode initialize method so leap_web tests stay green --- app/models/invite_code.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 8f69582..701b663 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -13,6 +13,8 @@ class InviteCode < CouchRest::Model::Base def initialize(attributes = {}, options = {}) super(attributes, options) + write_attribute('invite_code', CouponCode.generate) if new? + end def set_invite_code(code) -- cgit v1.2.3 From 244d6e99bd2a911c68f77ec006a852dffc7d6303 Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 9 Oct 2015 13:06:42 +0200 Subject: Replace Coupon Code gem for invite code creation Replacing the Coupon Code gem with base64/securerandom as suggested by Elijah. --- app/models/invite_code.rb | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 701b663..30d32d6 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -1,3 +1,5 @@ +require 'base64' +require 'securerandom' class InviteCode < CouchRest::Model::Base use_database 'invite_codes' @@ -13,10 +15,14 @@ class InviteCode < CouchRest::Model::Base def initialize(attributes = {}, options = {}) super(attributes, options) - write_attribute('invite_code', CouponCode.generate) if new? + write_attribute('invite_code', generate_invite) if new? end + def generate_invite + Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_\/]/,'')[0..7].scan(/..../).join('-') + end + def set_invite_code(code) write_attribute(:invite_code, code) end -- cgit v1.2.3 From 847887f5ac86f8ea561f21739f683762761fe758 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 12 Oct 2015 15:50:18 +0200 Subject: Remove Coupon Code gem and make invite code = id Id is set = invite code to make it easier to delete the invite codes that get created during the leap platform tests (because this avoids having to look up ttheir id each time). --- app/models/invite_code.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 30d32d6..6fcc427 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -14,18 +14,18 @@ class InviteCode < CouchRest::Model::Base end def initialize(attributes = {}, options = {}) + if !attributes.has_key?("_id") + attributes[:id] = InviteCode.generate_invite + end + super(attributes, options) - write_attribute('invite_code', generate_invite) if new? + write_attribute('invite_code', attributes[:id]) if new? end - def generate_invite + def self.generate_invite Base64.encode64(SecureRandom.random_bytes).downcase.gsub(/[0oil1+_\/]/,'')[0..7].scan(/..../).join('-') end - - def set_invite_code(code) - write_attribute(:invite_code, code) - end end -- cgit v1.2.3 From d38e6ab469630b8f4e72fa859e9aaac14c3033ff Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 9 Oct 2015 13:06:42 +0200 Subject: Replace Coupon Code gem for invite code creation Replacing the Coupon Code gem with base64/securerandom as suggested by Elijah. --- app/models/invite_code.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index 6fcc427..cee4095 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -19,7 +19,7 @@ class InviteCode < CouchRest::Model::Base end super(attributes, options) - + write_attribute('invite_code', attributes[:id]) if new? end -- cgit v1.2.3 From 85161c1bf4f1e830f714e8818e39d7f186914a09 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 12 Oct 2015 15:50:18 +0200 Subject: Remove Coupon Code gem and make invite code = id Id is set = invite code to make it easier to delete the invite codes that get created during the leap platform tests (because this avoids having to look up ttheir id each time). --- app/models/invite_code.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'app/models') diff --git a/app/models/invite_code.rb b/app/models/invite_code.rb index cee4095..6fcc427 100644 --- a/app/models/invite_code.rb +++ b/app/models/invite_code.rb @@ -19,7 +19,7 @@ class InviteCode < CouchRest::Model::Base end super(attributes, options) - + write_attribute('invite_code', attributes[:id]) if new? end -- cgit v1.2.3