summaryrefslogtreecommitdiff
path: root/test/unit/invite_code_test.rb
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-10-02 16:51:57 +0200
committerankonym <ankonym@gmail.com>2015-10-02 16:51:57 +0200
commit82a33300818dd8f6e06856944fe7c658746efca1 (patch)
treea38234fa3a6e4cca22ad1f7b7a42743a19ec96d4 /test/unit/invite_code_test.rb
parentd45f6c61f6a13be06f1977b857e0cb31e79c5317 (diff)
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.
Diffstat (limited to 'test/unit/invite_code_test.rb')
-rw-r--r--test/unit/invite_code_test.rb36
1 files changed, 34 insertions, 2 deletions
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