mirror of
https://github.com/internetee/registry.git
synced 2025-05-16 17:37:17 +02:00
Improve contact phone spec
This commit is contained in:
parent
3038d240f7
commit
c5e1516d89
2 changed files with 3 additions and 15 deletions
29
spec/lib/validators/e164.rb
Normal file
29
spec/lib/validators/e164.rb
Normal file
|
@ -0,0 +1,29 @@
|
|||
# https://en.wikipedia.org/wiki/E.164
|
||||
|
||||
RSpec.shared_examples 'e164' do
|
||||
describe 'validation' do
|
||||
it 'rejects invalid format' do
|
||||
model.send("#{attribute}=", '+.1')
|
||||
model.validate
|
||||
expect(model.errors).to be_added(attribute, :invalid)
|
||||
end
|
||||
|
||||
it 'rejects longer than max length' do
|
||||
model.send("#{attribute}=", '1' * 18)
|
||||
model.validate
|
||||
expect(model.errors).to be_added(attribute, :too_long, count: 17)
|
||||
end
|
||||
|
||||
it 'accepts valid format' do
|
||||
model.send("#{attribute}=", '+123.4')
|
||||
model.validate
|
||||
expect(model.errors).to_not be_added(attribute, :invalid)
|
||||
end
|
||||
|
||||
it 'accepts max length' do
|
||||
model.send("#{attribute}=", '1' * 17)
|
||||
model.validate
|
||||
expect(model.errors).to_not be_added(attribute, :too_long, count: 17)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue