summaryrefslogtreecommitdiff
path: root/app/models/invite_code_validator.rb
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-09-10 18:10:28 +0200
committerankonym <ankonym@gmail.com>2015-09-28 15:12:46 +0200
commitca591b482870c93674aaf454e90f56796da7d87d (patch)
tree7830f477b9942301c01acdb92227ec59e51e2b5f /app/models/invite_code_validator.rb
parentc1cd099089c09b79cb7945be4c3283afed9ab3b3 (diff)
Cleaned up code in invite_code_validator.rb
Diffstat (limited to 'app/models/invite_code_validator.rb')
-rw-r--r--app/models/invite_code_validator.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
index 127dc57..f96ca4a 100644
--- a/app/models/invite_code_validator.rb
+++ b/app/models/invite_code_validator.rb
@@ -3,22 +3,21 @@ class InviteCodeValidator < ActiveModel::Validator
user_invite_code = InviteCode.find_by_invite_code user.invite_code
- if not_existent?(user.invite_code)
+ 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.invite_count)
+ elsif count_greater_than_zero?(user_invite_code)
add_error_to_user("This code has already been used", user)
end
end
private
def not_existent?(code)
- InviteCode.find_by_invite_code(code) == nil
-
+ code == nil
end
def count_greater_than_zero?(code)
- code > 0
+ code.invite_count > 0
end
def add_error_to_user(error, user)