Contact got correct birthday and country code epp errors

This commit is contained in:
Priit Tark 2015-02-18 16:05:57 +02:00
parent 61ee8ef9f5
commit a8e43dd6cc
5 changed files with 15 additions and 10 deletions

View file

@ -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

View file

@ -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

View file

@ -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