diff options
-rw-r--r-- | app/models/invite_code_validator.rb | 9 |
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) |