summaryrefslogtreecommitdiff
path: root/app/models
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
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')
-rw-r--r--app/models/invite_code_validator.rb3
-rw-r--r--app/models/user.rb2
2 files changed, 3 insertions, 2 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)
diff --git a/app/models/user.rb b/app/models/user.rb
index a4dd132..c0079d5 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -40,7 +40,7 @@ class User < CouchRest::Model::Base
:mx_with_fallback => true
- validates_with InviteCodeValidator
+ validates_with InviteCodeValidator, on: :create
timestamps!