summaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-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!