mirror of
https://github.com/internetee/registry.git
synced 2025-07-01 00:33:36 +02:00
parent
7d2d34cb34
commit
bc3962cdfa
4 changed files with 63 additions and 16 deletions
|
@ -1,37 +1,45 @@
|
|||
require 'rails_helper'
|
||||
require 'lib/e164_phone_number'
|
||||
|
||||
RSpec.describe Contact do
|
||||
describe 'phone validation', db: false do
|
||||
let(:contact) { described_class.new }
|
||||
let(:contact) { described_class.new }
|
||||
|
||||
describe 'phone', db: false do
|
||||
it_behaves_like 'e164 phone number' do
|
||||
let(:model) { contact }
|
||||
let(:attribute) { :phone }
|
||||
end
|
||||
end
|
||||
|
||||
describe 'phone validation', db: false do
|
||||
it 'rejects absent' do
|
||||
contact.phone = nil
|
||||
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)
|
||||
expect(contact.errors).to be_added(:phone, :blank)
|
||||
end
|
||||
|
||||
it 'rejects all zeros in country code' do
|
||||
contact.phone = '+000.1'
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
expect(contact.errors).to be_added(:phone, :invalid)
|
||||
end
|
||||
|
||||
it 'rejects all zeros in phone number' do
|
||||
it 'rejects all zeros in subscriber number' do
|
||||
contact.phone = '+123.0'
|
||||
contact.validate
|
||||
expect(contact.errors).to have_key(:phone)
|
||||
expect(contact.errors).to be_added(:phone, :invalid)
|
||||
end
|
||||
|
||||
it 'accepts valid' do
|
||||
contact.phone = '+123.4'
|
||||
it 'translates :blank error message' do
|
||||
contact.phone = nil
|
||||
contact.validate
|
||||
expect(contact.errors).to_not have_key(:phone)
|
||||
expect(contact.errors.generate_message(:phone, :blank)).to eq('Required parameter missing - phone')
|
||||
end
|
||||
|
||||
it 'translates :invalid error message' do
|
||||
contact.phone = nil
|
||||
contact.validate
|
||||
expect(contact.errors.generate_message(:phone, :invalid)).to eq('Phone nr is invalid')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue