From 0543217b433a8f4809f08018c1a11c20119fa85d Mon Sep 17 00:00:00 2001 From: ankonym Date: Fri, 21 Aug 2015 17:49:36 +0200 Subject: assign random invite code when creating new invite codes --- test/unit/invite_code_test.rb | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/unit/invite_code_test.rb (limited to 'test/unit/invite_code_test.rb') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb new file mode 100644 index 0000000..2684f8e --- /dev/null +++ b/test/unit/invite_code_test.rb @@ -0,0 +1,21 @@ +require 'test_helper' + +class InviteCodeTest < ActiveSupport::TestCase + + test "it is created with an invite code" do + code = InviteCode.new + assert_not_nil code.invite_code + end + + test "the invite code can be read from couch db correctly" do + code1 = InviteCode.new + code1.save + + code2 = InviteCode.find_by__id code1.id + + assert_equal code1.invite_code, code2.invite_code + + end + + +end \ No newline at end of file -- cgit v1.2.3 From 45c3fadd930a474951bd918a50e1ea2b00af75c7 Mon Sep 17 00:00:00 2001 From: ankonym Date: Tue, 25 Aug 2015 14:11:00 +0200 Subject: Make sure codes can only be used once, fix validations We introduced a count on invite codes to make sure that (at the moment) codes can only be used once. (The code will also allow multi-use codes in the future.) Also, some of our validations weren't validating against the correct data, which is now fixed. --- test/unit/invite_code_test.rb | 33 ++++++++++++++++++++++++++++++--- 1 file changed, 30 insertions(+), 3 deletions(-) (limited to 'test/unit/invite_code_test.rb') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index 2684f8e..b6044f4 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -10,12 +10,39 @@ class InviteCodeTest < ActiveSupport::TestCase test "the invite code can be read from couch db correctly" do code1 = InviteCode.new code1.save - code2 = InviteCode.find_by__id code1.id - assert_equal code1.invite_code, code2.invite_code + end + test "the invite code count gets set to 0 upon creation" do + code1 = InviteCode.new + code1.save + assert_equal code1.invite_count, 0 end + # TODO: does the count go up when code gets entered? + test "Invite code count goes up by 1 when the invite code is entered" do + + validator = InviteCodeValidator.new nil + + user = FactoryGirl.build :user + user_code = InviteCode.new + user_code.save + user.invite_code = user_code.invite_code + + + validator.validate(user) + + user_code.reload + assert_equal 1, user_code.invite_count + + end +# +# +# # TODO: count >0 is not accepted for signup + # test "Invite count >0 is not accepted for new account signup" do + + # end + +end -end \ No newline at end of file -- cgit v1.2.3 From a8f07fb18518fd95fd701e8c0e550a3cd70520b0 Mon Sep 17 00:00:00 2001 From: ankonym Date: Mon, 31 Aug 2015 17:15:27 +0200 Subject: Fixes for the invite code validator Validation should only happen for new records User invite code was nil for invalid invite codes Adding missing tests --- test/unit/invite_code_test.rb | 67 ++++++++++++++++++++++++++++++++----------- 1 file changed, 51 insertions(+), 16 deletions(-) (limited to 'test/unit/invite_code_test.rb') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index b6044f4..2c9e33f 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -20,29 +20,64 @@ class InviteCodeTest < ActiveSupport::TestCase assert_equal code1.invite_count, 0 end - # TODO: does the count go up when code gets entered? - test "Invite code count goes up by 1 when the invite code is entered" do + test "Invite code count goes up by 1 when the invite code is entered" do + #TODO but onlz if there are no other errors on the form - validator = InviteCodeValidator.new nil + validator = InviteCodeValidator.new nil - user = FactoryGirl.build :user - user_code = InviteCode.new - user_code.save - user.invite_code = user_code.invite_code + user = FactoryGirl.build :user + user_code = InviteCode.new + user_code.save + user.invite_code = user_code.invite_code + validator.validate(user) - validator.validate(user) + user_code.reload + assert_equal 1, user_code.invite_count - user_code.reload - assert_equal 1, user_code.invite_count + 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 0 is accepted for new account signup" do + validator = InviteCodeValidator.new nil + + user_code = InviteCode.create - end -# -# -# # TODO: count >0 is not accepted for signup - # test "Invite count >0 is not accepted for new account signup" do + 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 end -- cgit v1.2.3 From 2ce3d14cfa77f985b6849dd4431db65e9abd0226 Mon Sep 17 00:00:00 2001 From: Aya Jaff Date: Fri, 4 Sep 2015 14:01:49 +0200 Subject: Fixed the signup bug that wrongly consumes the invite code. --- test/unit/invite_code_test.rb | 16 ---------------- 1 file changed, 16 deletions(-) (limited to 'test/unit/invite_code_test.rb') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index 2c9e33f..1b6a002 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -20,22 +20,6 @@ class InviteCodeTest < ActiveSupport::TestCase assert_equal code1.invite_count, 0 end - test "Invite code count goes up by 1 when the invite code is entered" do - #TODO but onlz if there are no other errors on the form - - validator = InviteCodeValidator.new nil - - user = FactoryGirl.build :user - user_code = InviteCode.new - user_code.save - user.invite_code = user_code.invite_code - - validator.validate(user) - - user_code.reload - assert_equal 1, user_code.invite_count - - end test "Invite count >0 is not accepted for new account signup" do validator = InviteCodeValidator.new nil -- cgit v1.2.3 From c1cd099089c09b79cb7945be4c3283afed9ab3b3 Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 10 Sep 2015 18:09:49 +0200 Subject: Removed the view_by__id from invite code test --- test/unit/invite_code_test.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'test/unit/invite_code_test.rb') diff --git a/test/unit/invite_code_test.rb b/test/unit/invite_code_test.rb index 1b6a002..b17d1bc 100644 --- a/test/unit/invite_code_test.rb +++ b/test/unit/invite_code_test.rb @@ -10,7 +10,7 @@ class InviteCodeTest < ActiveSupport::TestCase test "the invite code can be read from couch db correctly" do code1 = InviteCode.new code1.save - code2 = InviteCode.find_by__id code1.id + code2 = InviteCode.find_by_invite_code code1.invite_code assert_equal code1.invite_code, code2.invite_code end -- cgit v1.2.3