mirror of
https://github.com/internetee/registry.git
synced 2025-05-17 01:47:18 +02:00
parent
0f352cab24
commit
d520b5b157
50 changed files with 2462 additions and 323 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
|
17
spec/lib/validators/iso31661_alpha2.rb
Normal file
17
spec/lib/validators/iso31661_alpha2.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2
|
||||
|
||||
RSpec.shared_examples 'iso31661_alpha2' do
|
||||
describe 'validation' do
|
||||
it 'rejects invalid' do
|
||||
model.send("#{attribute}=", 'invalid')
|
||||
model.validate
|
||||
expect(model.errors).to be_added(attribute, :invalid_iso31661_alpha2)
|
||||
end
|
||||
|
||||
it 'accepts valid' do
|
||||
model.send("#{attribute}=", 'US')
|
||||
model.validate
|
||||
expect(model.errors).to_not be_added(attribute, :invalid_iso31661_alpha2)
|
||||
end
|
||||
end
|
||||
end
|
17
spec/lib/validators/iso8601.rb
Normal file
17
spec/lib/validators/iso8601.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
# https://en.wikipedia.org/wiki/ISO_8601
|
||||
|
||||
RSpec.shared_examples 'iso8601' do
|
||||
describe 'validation' do
|
||||
it 'rejects invalid' do
|
||||
model.send("#{attribute}=", '2010-07-0')
|
||||
model.validate
|
||||
expect(model.errors).to be_added(attribute, :invalid_iso8601_date)
|
||||
end
|
||||
|
||||
it 'accepts valid' do
|
||||
model.send("#{attribute}=", '2010-07-05')
|
||||
model.validate
|
||||
expect(model.errors).to_not be_added(attribute, :invalid_iso8601_date)
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue