summaryrefslogtreecommitdiff
path: root/app/models/invite_code_validator.rb
diff options
context:
space:
mode:
authorazul <azul@leap.se>2015-10-13 15:20:26 +0000
committerazul <azul@leap.se>2015-10-13 15:20:26 +0000
commitfd55d71cd1cbadcc5378601c0c9dfa6292bd4725 (patch)
treec36e96d7deb8191f7bc04c2d509e9f70c6de6754 /app/models/invite_code_validator.rb
parent70073b1ac48f96d3e375630fb7f3904351e0f696 (diff)
parentcb89699283aeb1ef4195a5c99d0319f3232f5db7 (diff)
Merge pull request #201 from Alster-Hamburgers/multi-invite
Allow multi-use invite codes
Diffstat (limited to 'app/models/invite_code_validator.rb')
-rw-r--r--app/models/invite_code_validator.rb7
1 files changed, 4 insertions, 3 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
index f96ca4a..676e4fa 100644
--- a/app/models/invite_code_validator.rb
+++ b/app/models/invite_code_validator.rb
@@ -1,4 +1,5 @@
class InviteCodeValidator < ActiveModel::Validator
+
def validate(user)
user_invite_code = InviteCode.find_by_invite_code user.invite_code
@@ -6,7 +7,7 @@ class InviteCodeValidator < ActiveModel::Validator
if not_existent?(user_invite_code)
add_error_to_user("This is not a valid code", user)
- elsif count_greater_than_zero?(user_invite_code)
+ elsif has_no_uses_left?(user_invite_code)
add_error_to_user("This code has already been used", user)
end
end
@@ -16,8 +17,8 @@ class InviteCodeValidator < ActiveModel::Validator
code == nil
end
- def count_greater_than_zero?(code)
- code.invite_count > 0
+ def has_no_uses_left?(code)
+ code.invite_count >= code.max_uses
end
def add_error_to_user(error, user)