mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 09:57:23 +02:00
Improve contact phone spec
This commit is contained in:
parent
3038d240f7
commit
c5e1516d89
2 changed files with 3 additions and 15 deletions
|
@ -1,6 +1,6 @@
|
||||||
# https://en.wikipedia.org/wiki/E.164
|
# https://en.wikipedia.org/wiki/E.164
|
||||||
|
|
||||||
RSpec.shared_examples 'e164 phone number' do
|
RSpec.shared_examples 'e164' do
|
||||||
describe 'validation' do
|
describe 'validation' do
|
||||||
it 'rejects invalid format' do
|
it 'rejects invalid format' do
|
||||||
model.send("#{attribute}=", '+.1')
|
model.send("#{attribute}=", '+.1')
|
|
@ -1,11 +1,11 @@
|
||||||
require 'rails_helper'
|
require 'rails_helper'
|
||||||
require 'lib/e164_phone_number'
|
require 'lib/validators/e164'
|
||||||
|
|
||||||
RSpec.describe Contact do
|
RSpec.describe Contact do
|
||||||
let(:contact) { described_class.new }
|
let(:contact) { described_class.new }
|
||||||
|
|
||||||
describe 'phone', db: false do
|
describe 'phone', db: false do
|
||||||
it_behaves_like 'e164 phone number' do
|
it_behaves_like 'e164' do
|
||||||
let(:model) { contact }
|
let(:model) { contact }
|
||||||
let(:attribute) { :phone }
|
let(:attribute) { :phone }
|
||||||
end
|
end
|
||||||
|
@ -29,17 +29,5 @@ RSpec.describe Contact do
|
||||||
contact.validate
|
contact.validate
|
||||||
expect(contact.errors).to be_added(:phone, :invalid)
|
expect(contact.errors).to be_added(:phone, :invalid)
|
||||||
end
|
end
|
||||||
|
|
||||||
it 'translates :blank error message' do
|
|
||||||
contact.phone = nil
|
|
||||||
contact.validate
|
|
||||||
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
|
||||||
end
|
end
|
Loading…
Add table
Add a link
Reference in a new issue