Show more detailed error message for ident of "birthday" type

#569
This commit is contained in:
Artur Beljajev 2017-09-11 23:37:02 +03:00
parent 64439cfcef
commit 4d5830efdf
4 changed files with 5 additions and 5 deletions

View file

@ -25,7 +25,7 @@ class Contact::Ident
[:base, :mismatch], [:base, :mismatch],
[:code, :invalid_national_id], [:code, :invalid_national_id],
[:code, :invalid_reg_no], [:code, :invalid_reg_no],
[:code, :invalid_iso8601], [:code, :invalid_iso8601_date],
[:country_code, :invalid_iso31661_alpha2] [:country_code, :invalid_iso31661_alpha2]
] ]
} }

View file

@ -236,7 +236,7 @@ en:
domain_exists_but_belongs_to_other_registrar: 'Domain exists but belongs to other registrar' domain_exists_but_belongs_to_other_registrar: 'Domain exists but belongs to other registrar'
required_ident_attribute_missing: "Required ident attribute missing: %{key}" required_ident_attribute_missing: "Required ident attribute missing: %{key}"
invalid_iso31661_alpha2: does not conform to ISO 3166-1 alpha-2 standard invalid_iso31661_alpha2: does not conform to ISO 3166-1 alpha-2 standard
invalid_iso8601: does not conform to ISO 8601 standard invalid_iso8601_date: has invalid date format YYYY-MM-DD (ISO 8601)
code: 'Code' code: 'Code'
value: 'Value' value: 'Value'

View file

@ -1,7 +1,7 @@
class Iso8601Validator < ActiveModel::EachValidator class Iso8601Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
if options[:date_only] if options[:date_only]
record.errors.add(attribute, :invalid_iso8601) unless value =~ date_format record.errors.add(attribute, :invalid_iso8601_date) unless value =~ date_format
end end
end end

View file

@ -5,13 +5,13 @@ RSpec.shared_examples 'iso8601' do
it 'rejects invalid' do it 'rejects invalid' do
model.send("#{attribute}=", '2010-07-0') model.send("#{attribute}=", '2010-07-0')
model.validate model.validate
expect(model.errors).to be_added(attribute, :invalid_iso8601) expect(model.errors).to be_added(attribute, :invalid_iso8601_date)
end end
it 'accepts valid' do it 'accepts valid' do
model.send("#{attribute}=", '2010-07-05') model.send("#{attribute}=", '2010-07-05')
model.validate model.validate
expect(model.errors).to_not be_added(attribute, :invalid_iso8601) expect(model.errors).to_not be_added(attribute, :invalid_iso8601_date)
end end
end end
end end