adds validation for postal codes in Madrid
This commit is contained in:
@@ -14,6 +14,7 @@ class Verification::Residence
|
|||||||
|
|
||||||
validate :allowed_age
|
validate :allowed_age
|
||||||
validate :document_number_uniqueness
|
validate :document_number_uniqueness
|
||||||
|
validate :postal_code_in_madrid
|
||||||
validate :residence_in_madrid
|
validate :residence_in_madrid
|
||||||
|
|
||||||
def initialize(attrs={})
|
def initialize(attrs={})
|
||||||
@@ -30,10 +31,19 @@ class Verification::Residence
|
|||||||
residence_verified_at: Time.now)
|
residence_verified_at: Time.now)
|
||||||
end
|
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
|
def document_number_uniqueness
|
||||||
errors.add(:document_number, I18n.t('errors.messages.taken')) if User.where(document_number: document_number).any?
|
errors.add(:document_number, I18n.t('errors.messages.taken')) if User.where(document_number: document_number).any?
|
||||||
end
|
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
|
def residence_in_madrid
|
||||||
return if errors.any?
|
return if errors.any?
|
||||||
self.date_of_birth = date_to_string(date_of_birth)
|
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)
|
self.date_of_birth = string_to_date(date_of_birth)
|
||||||
end
|
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
|
def store_failed_attempt
|
||||||
FailedCensusCall.create({
|
FailedCensusCall.create({
|
||||||
user: user,
|
user: user,
|
||||||
|
|||||||
Reference in New Issue
Block a user