Added model test and created helper for E.164 phone format testing

This commit is contained in:
Sergei Tsõganov 2022-01-07 16:05:13 +02:00 committed by Sergei Tsõganov
parent 8c8e9c8619
commit d361288329
3 changed files with 55 additions and 31 deletions

View file

@ -0,0 +1,37 @@
module PhoneFormatHelperTest
# https://en.wikipedia.org/wiki/E.164
def assert_phone_format(contact)
contact.phone = '+.1'
assert contact.invalid?
contact.phone = '+123.'
assert contact.invalid?
contact.phone = '+1.123456789123456'
assert contact.invalid?
contact.phone = '+134.1234567891234'
assert contact.invalid?
contact.phone = '+000.1'
assert contact.invalid?
contact.phone = '+123.0'
assert contact.invalid?
contact.phone = '+1.2'
assert contact.valid?
contact.phone = '+123.4'
assert contact.valid?
contact.phone = '+1.12345678912345'
assert contact.valid?
contact.phone = '+134.123456789123'
assert contact.valid?
contact.phone = '+134.00000000'
assert contact.invalid?
end
end