mirror of
https://github.com/internetee/registry.git
synced 2025-05-20 11:19:39 +02:00
Merge branch 'master' into migrate-fabricators-to-factory-bot-factories
# Conflicts: # Gemfile # lib/tasks/dev.rake # spec/models/contact_spec.rb
This commit is contained in:
commit
be959a8471
59 changed files with 2505 additions and 480 deletions
|
@ -28,45 +28,6 @@ RSpec.describe Contact do
|
|||
@contact.updator.should == nil
|
||||
end
|
||||
|
||||
it 'should require country code when org' do
|
||||
@contact.ident_type = 'org'
|
||||
@contact.valid?
|
||||
@contact.errors[:ident_country_code].should == ['is missing']
|
||||
end
|
||||
|
||||
it 'should require country code when priv' do
|
||||
@contact.ident_type = 'priv'
|
||||
@contact.valid?
|
||||
@contact.errors[:ident_country_code].should == ['is missing']
|
||||
end
|
||||
|
||||
it 'should validate correct country code' do
|
||||
@contact.ident = 1
|
||||
@contact.ident_type = 'org'
|
||||
@contact.ident_country_code = 'EE'
|
||||
@contact.valid?
|
||||
|
||||
@contact.errors[:ident_country_code].should == []
|
||||
end
|
||||
|
||||
it 'should require valid country code' do
|
||||
@contact.ident = '123'
|
||||
@contact.ident_type = 'org'
|
||||
@contact.ident_country_code = 'INVALID'
|
||||
@contact.valid?
|
||||
|
||||
expect(@contact.errors).to have_key(:ident)
|
||||
end
|
||||
|
||||
it 'should convert to alpha2 country code' do
|
||||
@contact.ident = 1
|
||||
@contact.ident_type = 'org'
|
||||
@contact.ident_country_code = 'ee'
|
||||
@contact.validate
|
||||
|
||||
@contact.ident_country_code.should == 'EE'
|
||||
end
|
||||
|
||||
it 'should not have any versions' do
|
||||
@contact.versions.should == []
|
||||
end
|
||||
|
@ -119,14 +80,6 @@ RSpec.describe Contact do
|
|||
@contact.domains_present?.should == false
|
||||
end
|
||||
|
||||
it 'org should be valid' do
|
||||
contact = build(:contact, ident_type: 'org', ident: '1' * 8)
|
||||
|
||||
contact.validate
|
||||
|
||||
contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
|
||||
it 'should not overwrite code' do
|
||||
old_code = @contact.code
|
||||
@contact.code = 'CID:REG1:should-not-overwrite-old-code-12345'
|
||||
|
@ -217,31 +170,6 @@ RSpec.describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
context 'as birthday' do
|
||||
before :example do
|
||||
@contact.ident_type = 'birthday'
|
||||
end
|
||||
|
||||
it 'birthday should be valid' do
|
||||
valid = ['2012-12-11', '1990-02-16']
|
||||
valid.each do |date|
|
||||
@contact.ident = date
|
||||
@contact.valid?
|
||||
@contact.errors.full_messages.should match_array([])
|
||||
end
|
||||
end
|
||||
|
||||
it 'birthday should be invalid' do
|
||||
invalid = ['123' '12/12/2012', 'aaaa', '12/12/12', '02-11-1999']
|
||||
invalid.each do |date|
|
||||
@contact.ident = date
|
||||
@contact.valid?
|
||||
@contact.errors.full_messages.should ==
|
||||
["Ident Ident not in valid birthady format, should be YYYY-MM-DD"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'with callbacks' do
|
||||
before :example do
|
||||
# Ensure callbacks are not taken out from other specs
|
||||
|
@ -445,7 +373,7 @@ RSpec.describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'country code validation' do
|
||||
describe 'country code validation', db: false do
|
||||
let(:contact) { described_class.new(country_code: 'test') }
|
||||
|
||||
it 'rejects invalid' do
|
||||
|
@ -455,37 +383,25 @@ RSpec.describe Contact do
|
|||
end
|
||||
end
|
||||
|
||||
describe 'phone validation', db: false do
|
||||
describe 'identifier validation', db: false do
|
||||
let(:contact) { described_class.new }
|
||||
|
||||
it 'rejects absent' do
|
||||
contact.phone = nil
|
||||
it 'rejects invalid' do
|
||||
ident = Contact::Ident.new
|
||||
ident.validate
|
||||
contact.identifier = ident
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
end
|
||||
|
||||
it 'rejects invalid format' do
|
||||
contact.phone = '123'
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
end
|
||||
|
||||
it 'rejects all zeros in country code' do
|
||||
contact.phone = '+000.1'
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
end
|
||||
|
||||
it 'rejects all zeros in phone number' do
|
||||
contact.phone = '+123.0'
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
expect(contact.errors).to be_added(:identifier, :invalid)
|
||||
end
|
||||
|
||||
it 'accepts valid' do
|
||||
contact.phone = '+123.4'
|
||||
ident = Contact::Ident.new(code: 'test', type: 'priv', country_code: 'US')
|
||||
ident.validate
|
||||
contact.identifier = ident
|
||||
contact.validate
|
||||
expect(contact.errors).to_not have_key(:phone)
|
||||
|
||||
expect(contact.errors).to_not be_added(:identifier, :invalid)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -595,4 +511,13 @@ RSpec.describe Contact do
|
|||
expect(domain_names).to eq({ 'test.com' => %i[admin_domain_contact].to_set })
|
||||
end
|
||||
end
|
||||
|
||||
it 'normalizes ident country code', db: false do
|
||||
contact = described_class.new
|
||||
|
||||
contact.ident_country_code = 'ee'
|
||||
contact.validate
|
||||
|
||||
expect(contact.ident_country_code).to eq('EE')
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue