summaryrefslogtreecommitdiff
path: root/app/models/invite_code_validator.rb
diff options
context:
space:
mode:
authorankonym <ankonym@gmail.com>2015-08-31 17:15:27 +0200
committerankonym <ankonym@gmail.com>2015-09-28 15:12:45 +0200
commita8f07fb18518fd95fd701e8c0e550a3cd70520b0 (patch)
tree7a2ca500e5626234c4eff3f606b77bd57519c3ce /app/models/invite_code_validator.rb
parent45c3fadd930a474951bd918a50e1ea2b00af75c7 (diff)
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
Diffstat (limited to 'app/models/invite_code_validator.rb')
-rw-r--r--app/models/invite_code_validator.rb3
1 files changed, 2 insertions, 1 deletions
diff --git a/app/models/invite_code_validator.rb b/app/models/invite_code_validator.rb
index 73c333a..d03d510 100644
--- a/app/models/invite_code_validator.rb
+++ b/app/models/invite_code_validator.rb
@@ -3,7 +3,7 @@ class InviteCodeValidator < ActiveModel::Validator
user_invite_code = InviteCode.find_by_invite_code user.invite_code
- if not_existent?(user_invite_code.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)
@@ -18,6 +18,7 @@ class InviteCodeValidator < ActiveModel::Validator
private
def not_existent?(code)
InviteCode.find_by_invite_code(code) == nil
+
end
def count_greater_than_zero?(code)