adds validation for postal codes in Madrid
This commit is contained in:
@@ -14,6 +14,7 @@ class Verification::Residence
|
||||
|
||||
validate :allowed_age
|
||||
validate :document_number_uniqueness
|
||||
validate :postal_code_in_madrid
|
||||
validate :residence_in_madrid
|
||||
|
||||
def initialize(attrs={})
|
||||
@@ -30,10 +31,19 @@ class Verification::Residence
|
||||
residence_verified_at: Time.now)
|
||||
end
|
||||
|
||||
def allowed_age
|
||||
return if errors[:date_of_birth].any?
|
||||
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= 16.years.ago
|
||||
end
|
||||
|
||||
def document_number_uniqueness
|
||||
errors.add(:document_number, I18n.t('errors.messages.taken')) if User.where(document_number: document_number).any?
|
||||
end
|
||||
|
||||
def postal_code_in_madrid
|
||||
errors.add(:postal_code, I18n.t('verification.residence.new.error_not_allowed_postal_code')) unless valid_postal_code?
|
||||
end
|
||||
|
||||
def residence_in_madrid
|
||||
return if errors.any?
|
||||
self.date_of_birth = date_to_string(date_of_birth)
|
||||
@@ -48,11 +58,6 @@ class Verification::Residence
|
||||
self.date_of_birth = string_to_date(date_of_birth)
|
||||
end
|
||||
|
||||
def allowed_age
|
||||
return if errors[:date_of_birth].any?
|
||||
errors.add(:date_of_birth, I18n.t('verification.residence.new.error_not_allowed_age')) unless self.date_of_birth <= 16.years.ago
|
||||
end
|
||||
|
||||
def store_failed_attempt
|
||||
FailedCensusCall.create({
|
||||
user: user,
|
||||
|
||||
Reference in New Issue
Block a user