From 82a33300818dd8f6e06856944fe7c658746efca1 Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 2 Oct 2015 16:51:57 +0200 Subject: Allow multi-use invite codes Introduce a invite_max_uses property to invite codes to allow admins to set a maximum number of uses for invite codes. --- test/unit/invite_code_test.rb | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index b17d1bc..7e14a03 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -21,11 +21,28 @@ class InviteCodeTest < ActiveSupport::TestCase end - test "Invite count >0 is not accepted for new account signup" do + # test "Invite count >0 is not accepted for new account signup" do + # validator = InviteCodeValidator.new nil + # + # user_code = InviteCode.new + # user_code.invite_count = 1 + # user_code.save + # + # user = FactoryGirl.build :user + # user.invite_code = user_code.invite_code + # + # validator.validate(user) + # + # assert_equal ["This code has already been used"], user.errors[:invite_code] + # + # end + + test "Invite count >= invite max uses is not accepted for new account signup" do validator = InviteCodeValidator.new nil user_code = InviteCode.new user_code.invite_count = 1 + user_code.invite_max_uses = 1 user_code.save user = FactoryGirl.build :user @@ -37,6 +54,22 @@ class InviteCodeTest < ActiveSupport::TestCase end + test "Invite count < invite max uses is accepted for new account signup" do + validator = InviteCodeValidator.new nil + + user_code = InviteCode.create + user_code.invite_count = 0 + user_code.invite_max_uses = 1 + user_code.save + + user = FactoryGirl.build :user + user.invite_code = user_code.invite_code + + validator.validate(user) + + assert_equal [], user.errors[:invite_code] + end + test "Invite count 0 is accepted for new account signup" do validator = InviteCodeValidator.new nil @@ -62,6 +95,5 @@ class InviteCodeTest < ActiveSupport::TestCase end - end -- cgit v1.2.3 From 6f09343e85ab23c4d81f827bbd47a720f3e2cf7b Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 2 Oct 2015 20:58:29 +0200 Subject: Update rake task to allow generation of multi-use invites The rake task now takes a second (optional) argument that sets the number of uses per invite code. If this is omitted, the default number of uses is 1. (This commit also contains some minor code cleanup that removes some stuff that I'd commented out but not removed.) --- test/unit/invite_code_test.rb | 17 ----------------- 1 file changed, 17 deletions(-) (limited to 'test') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index 7e14a03..adaf397 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -20,23 +20,6 @@ class InviteCodeTest < ActiveSupport::TestCase assert_equal code1.invite_count, 0 end - - # test "Invite count >0 is not accepted for new account signup" do - # validator = InviteCodeValidator.new nil - # - # user_code = InviteCode.new - # user_code.invite_count = 1 - # user_code.save - # - # user = FactoryGirl.build :user - # user.invite_code = user_code.invite_code - # - # validator.validate(user) - # - # assert_equal ["This code has already been used"], user.errors[:invite_code] - # - # end - test "Invite count >= invite max uses is not accepted for new account signup" do validator = InviteCodeValidator.new nil -- cgit v1.2.3 From da9608a906d4369afb70e042069e219bc2e2d282 Mon Sep 17 00:00:00 2001 From: ankonym Date: Tue, 6 Oct 2015 13:27:32 +0200 Subject: Integrated feedback on multi-invite codes Removing some superfluous code, mostly, and structuring tests better. --- test/unit/invite_code_test.rb | 57 --------------------------------- test/unit/invite_code_validator_test.rb | 56 ++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+), 57 deletions(-) (limited to 'test') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index adaf397..fd93f2f 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -20,63 +20,6 @@ class InviteCodeTest < ActiveSupport::TestCase assert_equal code1.invite_count, 0 end - test "Invite count >= invite max uses is not accepted for new account signup" do - validator = InviteCodeValidator.new nil - - user_code = InviteCode.new - user_code.invite_count = 1 - user_code.invite_max_uses = 1 - user_code.save - - user = FactoryGirl.build :user - user.invite_code = user_code.invite_code - - validator.validate(user) - - assert_equal ["This code has already been used"], user.errors[:invite_code] - - end - - test "Invite count < invite max uses is accepted for new account signup" do - validator = InviteCodeValidator.new nil - - user_code = InviteCode.create - user_code.invite_count = 0 - user_code.invite_max_uses = 1 - user_code.save - - user = FactoryGirl.build :user - user.invite_code = user_code.invite_code - - validator.validate(user) - - assert_equal [], user.errors[:invite_code] - end - - test "Invite count 0 is accepted for new account signup" do - validator = InviteCodeValidator.new nil - - user_code = InviteCode.create - - user = FactoryGirl.build :user - user.invite_code = user_code.invite_code - - validator.validate(user) - - assert_equal [], user.errors[:invite_code] - end - - test "There is an error message if the invite code does not exist" do - validator = InviteCodeValidator.new nil - - user = FactoryGirl.build :user - user.invite_code = "wrongcode" - - validator.validate(user) - - assert_equal ["This is not a valid code"], user.errors[:invite_code] - - end end diff --git a/test/unit/invite_code_validator_test.rb b/test/unit/invite_code_validator_test.rb index ee8f1b3..62eeae6 100644 --- a/test/unit/invite_code_validator_test.rb +++ b/test/unit/invite_code_validator_test.rb @@ -27,4 +27,60 @@ class InviteCodeValidatorTest < ActiveSupport::TestCase assert_equal errors, invalid_user.errors.messages end end + + + test "Invite count >= invite max uses is not accepted for new account signup" do + validator = InviteCodeValidator.new nil + + user_code = InviteCode.new + user_code.invite_count = 1 + user_code.save + + user = FactoryGirl.build :user + user.invite_code = user_code.invite_code + + validator.validate(user) + + assert_equal ["This code has already been used"], user.errors[:invite_code] + + end + + test "Invite count < invite max uses is accepted for new account signup" do + validator = InviteCodeValidator.new nil + + user_code = InviteCode.create + user_code.save + + user = FactoryGirl.build :user + user.invite_code = user_code.invite_code + + validator.validate(user) + + assert_equal [], user.errors[:invite_code] + end + + test "Invite count 0 is accepted for new account signup" do + validator = InviteCodeValidator.new nil + + user_code = InviteCode.create + + user = FactoryGirl.build :user + user.invite_code = user_code.invite_code + + validator.validate(user) + + assert_equal [], user.errors[:invite_code] + end + + test "There is an error message if the invite code does not exist" do + validator = InviteCodeValidator.new nil + + user = FactoryGirl.build :user + user.invite_code = "wrongcode" + + validator.validate(user) + + assert_equal ["This is not a valid code"], user.errors[:invite_code] + end + end \ No newline at end of file -- cgit v1.2.3