Merge pull request #4381 from consul/remove_residence_in_madrid

Use more generic names for validation rules
This commit is contained in:
Javi Martín
2021-03-02 14:54:58 +01:00
committed by GitHub
4 changed files with 10 additions and 10 deletions

View File

@@ -1,18 +1,18 @@
require_dependency Rails.root.join("app", "models", "verification", "residence").to_s
class Verification::Residence
validate :postal_code_in_madrid
validate :residence_in_madrid
validate :local_postal_code
validate :local_residence
def postal_code_in_madrid
def local_postal_code
errors.add(:postal_code, I18n.t("verification.residence.new.error_not_allowed_postal_code")) unless valid_postal_code?
end
def residence_in_madrid
def local_residence
return if errors.any?
unless residency_valid?
errors.add(:residence_in_madrid, false)
errors.add(:local_residence, false)
store_failed_attempt
Lock.increase_tries(user)
end

View File

@@ -15,7 +15,7 @@ class Officing::Residence
validates :year_of_birth, presence: true, unless: -> { Setting.force_presence_date_of_birth? }
validate :allowed_age
validate :residence_in_madrid
validate :local_residence
def initialize(attrs = {})
self.date_of_birth = parse_date("date_of_birth", attrs)
@@ -72,12 +72,12 @@ class Officing::Residence
User.find_by(document_number: document_number, document_type: document_type)
end
def residence_in_madrid
def local_residence
return if errors.any?
unless residency_valid?
store_failed_census_call
errors.add(:residence_in_madrid, false)
errors.add(:local_residence, false)
end
end

View File

@@ -1,4 +1,4 @@
<% if @residence.errors[:residence_in_madrid].present? %>
<% if @residence.errors[:local_residence].present? %>
<div id="error_explanation" data-alert class="callout alert" data-closable>
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>

View File

@@ -1,4 +1,4 @@
<% if @residence.errors[:residence_in_madrid].present? %>
<% if @residence.errors[:local_residence].present? %>
<div id="error_explanation" data-alert class="callout alert" data-closable>
<button class="close-button" aria-label="<%= t("application.close") %>" type="button" data-close>