From a8e43dd6cc4755eab9d43463bbb59c62a5587ba2 Mon Sep 17 00:00:00 2001 From: Priit Tark Date: Wed, 18 Feb 2015 16:05:57 +0200 Subject: [PATCH] Contact got correct birthday and country code epp errors --- app/models/contact.rb | 6 ++++-- app/models/epp/contact.rb | 3 ++- app/views/admin/contacts/index.haml | 10 +++++----- config/locales/en.yml | 3 ++- spec/models/contact_spec.rb | 3 ++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/app/models/contact.rb b/app/models/contact.rb index 37b562ff6..722e4de33 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -18,7 +18,9 @@ class Contact < ActiveRecord::Base # Phone nr validation is very minimam in order to support legacy requirements validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ validates :email, format: /@/ - validates :ident, format: /\d{4}-\d{2}-\d{2}/, if: proc { |c| c.ident_type == 'birthday' } + validates :ident, + format: { with: /\d{4}-\d{2}-\d{2}/, message: :invalid_birthday_format }, + if: proc { |c| c.ident_type == 'birthday' } validates :ident_country_code, presence: true, if: proc { |c| %w(bic priv).include? c.ident_type } validates :code, uniqueness: { message: :epp_id_taken } validate :ident_valid_format? @@ -80,7 +82,7 @@ class Contact < ActiveRecord::Base case ident_country_code when 'EE' code = Isikukood.new(ident) - errors.add(:ident, :not_valid_EE_identity_format) unless code.valid? + errors.add(:ident, :invalid_EE_identity_format) unless code.valid? end end end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index b2184eba8..57eccbf2c 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -71,7 +71,8 @@ class Epp::Contact < Contact [:phone, :invalid], [:email, :invalid], [:ident, :invalid], - [:ident, :not_valid_EE_identity_format] + [:ident, :invalid_EE_identity_format], + [:ident, :invalid_birthday_format] ] } end diff --git a/app/views/admin/contacts/index.haml b/app/views/admin/contacts/index.haml index b8704a696..3f437d62d 100644 --- a/app/views/admin/contacts/index.haml +++ b/app/views/admin/contacts/index.haml @@ -30,12 +30,12 @@ %th{class: 'col-xs-2'} = sort_link(@q, 'code', t(:code)) %tbody - - @contacts.each do |x| + - @contacts.each do |contact| %tr - %td= link_to(x, admin_contact_path(x)) - %td= x.ident - %td= x.email - %td= x.code + %td= link_to(contact, admin_contact_path(contact)) + %td= "#{contact.ident} #{ident_indicator(contact)}" + %td= contact.email + %td= contact.code .row .col-md-12 = paginate @contacts diff --git a/config/locales/en.yml b/config/locales/en.yml index ea38733b2..3adea8723 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -45,7 +45,8 @@ en: invalid: "Email is invalid" ident: blank: "Required parameter missing - ident" - not_valid_EE_identity_format: "Ident not in valid Estonian identity format." + invalid_EE_identity_format: "Ident not in valid Estonian identity format." + invalid_birthday_format: "Ident not in valid birthady format, should be YYYY-MM-DD" domains: exist: 'Object association prohibits operation' diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 0b00e8737..d605e9781 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -149,7 +149,8 @@ describe Contact do invalid.each do |date| @contact.ident = date @contact.valid? - @contact.errors.full_messages.should == ["Ident is invalid"] + @contact.errors.full_messages.should == + ["Ident Ident not in valid birthady format, should be YYYY-MM-DD"] end end end