mirror of
https://github.com/internetee/registry.git
synced 2025-07-20 01:36:02 +02:00
Merge branch 'master' of github.com:internetee/registry into rails42
This commit is contained in:
commit
ea7a6a5238
4 changed files with 47 additions and 6 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -17,6 +17,21 @@ describe Contact do
|
|||
expect(@contact.valid?).to be false
|
||||
end
|
||||
|
||||
it 'validates birthday' do
|
||||
invalid = [ '123' '12/12/2012', 'aaaa', '12/12/12', '02-11-1999' ]
|
||||
invalid.each do |date|
|
||||
expect(Fabricate.build(:contact, ident_type: 'birthday', ident: date).valid?).to be false
|
||||
end
|
||||
valid = [ '2012-12-11', '1990-02-16' ]
|
||||
valid.each do |date|
|
||||
expect(Fabricate.build(:contact, ident_type: 'birthday', ident: date).valid?).to be true
|
||||
end
|
||||
end
|
||||
|
||||
it 'doesn\'t validate ico' do
|
||||
expect(Fabricate.build(:contact, ident_type: 'ico', ident: '12312adsadwe').valid?).to be true
|
||||
end
|
||||
|
||||
it 'should return missing parameter error messages' do
|
||||
@contact = Contact.new
|
||||
expect(@contact.valid?).to eq false
|
||||
|
@ -27,7 +42,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
|
||||
|
|
23
spec/requests/contact_v1_spec.rb
Normal file
23
spec/requests/contact_v1_spec.rb
Normal file
|
@ -0,0 +1,23 @@
|
|||
require 'rails_helper'
|
||||
|
||||
describe Repp::ContactV1 do
|
||||
let(:epp_user) { Fabricate(:epp_user) }
|
||||
|
||||
before(:each) { create_settings }
|
||||
|
||||
describe 'GET /repp/v1/contacts' do
|
||||
it 'returns contacts of the current registrar' do
|
||||
Fabricate.times(2, :contact, registrar: epp_user.registrar)
|
||||
Fabricate.times(2, :contact)
|
||||
|
||||
get_with_auth '/repp/v1/contacts', {}, epp_user
|
||||
expect(response.status).to eq(200)
|
||||
|
||||
body = JSON.parse(response.body)
|
||||
expect(body['total_pages']).to eq(1)
|
||||
|
||||
# TODO: Maybe there is a way not to convert from and to json again
|
||||
expect(body['contacts'].to_json).to eq(epp_user.registrar.contacts.to_json)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue