diff --git a/app/models/contact.rb b/app/models/contact.rb index abae9e8be..06a819616 100644 --- a/app/models/contact.rb +++ b/app/models/contact.rb @@ -18,12 +18,13 @@ class Contact < ActiveRecord::Base accepts_nested_attributes_for :address, :disclosure - validates :name, :phone, :email, :ident, :address, :registrar, presence: true - - validate :ident_must_be_valid + validates :name, :phone, :email, :ident, :address, :registrar, :ident_type, presence: true validates :phone, format: /\+[0-9]{1,3}\.[0-9]{1,14}?/ # /\+\d{3}\.\d+/ validates :email, format: /@/ + validates :ident, format: /\d{4}-\d{2}-\d{2}/, if: proc { |c| c.ident_type == 'birthday' } + + validate :ident_must_be_valid validates :code, uniqueness: { message: :epp_id_taken } @@ -135,7 +136,8 @@ class Contact < ActiveRecord::Base ], '2005' => [ # Value syntax error [:phone, :invalid], - [:email, :invalid] + [:email, :invalid], + [:ident, :invalid] ] } end diff --git a/spec/epp/contact_spec.rb b/spec/epp/contact_spec.rb index e74264e33..8b247aab5 100644 --- a/spec/epp/contact_spec.rb +++ b/spec/epp/contact_spec.rb @@ -58,7 +58,7 @@ describe 'EPP Contact', epp: true do end it 'successfully saves ident type' do - xml = { ident: { value: '37605030299', attrs: { type: 'birthday' } } } + xml = { ident: { value: '1990-22-12', attrs: { type: 'birthday' } } } epp_request(create_contact_xml(xml), :xml) expect(Contact.last.ident_type).to eq('birthday') end diff --git a/spec/models/contact_spec.rb b/spec/models/contact_spec.rb index 70b11b2b9..7845e54f0 100644 --- a/spec/models/contact_spec.rb +++ b/spec/models/contact_spec.rb @@ -27,7 +27,8 @@ describe Contact do email: ['Required parameter missing - email', 'Email is invalid'], ident: ['Required parameter missing - ident'], address: ['is missing'], - registrar: ['is missing'] + registrar: ['is missing'], + ident_type: ['is missing'] }) end end