mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 09:27:19 +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
|
||||
|
||||
RSpec.shared_examples 'e164 phone number' do
|
||||
RSpec.shared_examples 'e164' do
|
||||
describe 'validation' do
|
||||
it 'rejects invalid format' do
|
||||
model.send("#{attribute}=", '+.1')
|
|
@ -1,11 +1,11 @@
|
|||
require 'rails_helper'
|
||||
require 'lib/e164_phone_number'
|
||||
require 'lib/validators/e164'
|
||||
|
||||
RSpec.describe Contact do
|
||||
let(:contact) { described_class.new }
|
||||
|
||||
describe 'phone', db: false do
|
||||
it_behaves_like 'e164 phone number' do
|
||||
it_behaves_like 'e164' do
|
||||
let(:model) { contact }
|
||||
let(:attribute) { :phone }
|
||||
end
|
||||
|
@ -29,17 +29,5 @@ RSpec.describe Contact do
|
|||
contact.validate
|
||||
expect(contact.errors).to be_added(:phone, :invalid)
|
||||
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
|
Loading…
Add table
Add a link
Reference in a new issue