From ca591b482870c93674aaf454e90f56796da7d87d Mon Sep 17 00:00:00 2001 From: ankonym Date: Thu, 10 Sep 2015 18:10:28 +0200 Subject: Cleaned up code in invite_code_validator.rb --- app/models/invite_code_validator.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'app') 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) -- cgit v1.2.3