mirror of
https://github.com/internetee/registry.git
synced 2025-07-22 02:35:57 +02:00
Merge pull request #2102 from internetee/1795-validation-contacts-name
Fix for contact name validation (only for persons)
This commit is contained in:
commit
e00e09713c
3 changed files with 21 additions and 0 deletions
|
@ -28,7 +28,12 @@ class Contact < ApplicationRecord
|
||||||
.where('success = false and verified_at IS NOT NULL')
|
.where('success = false and verified_at IS NOT NULL')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
NAME_REGEXP = /([\u00A1-\u00B3\u00B5-\u00BF\u0021-\u0026\u0028-\u002C\u003A-\u0040]|
|
||||||
|
[\u005B-\u005F\u007B-\u007E\u2040-\u206F\u20A0-\u20BF\u2100-\u218F])/x.freeze
|
||||||
|
|
||||||
validates :name, :email, presence: true
|
validates :name, :email, presence: true
|
||||||
|
validates :name, format: { without: NAME_REGEXP, message: :invalid }, if: -> { priv? }
|
||||||
|
|
||||||
validates :street, :city, :zip, :country_code, presence: true, if: lambda {
|
validates :street, :city, :zip, :country_code, presence: true, if: lambda {
|
||||||
self.class.address_processing?
|
self.class.address_processing?
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,6 +14,7 @@ en:
|
||||||
too_long_contact_code: "Contact code is too long, max 100 characters"
|
too_long_contact_code: "Contact code is too long, max 100 characters"
|
||||||
name:
|
name:
|
||||||
blank: "Required parameter missing - name"
|
blank: "Required parameter missing - name"
|
||||||
|
invalid: "Name is invalid"
|
||||||
phone:
|
phone:
|
||||||
blank: "Required parameter missing - phone"
|
blank: "Required parameter missing - phone"
|
||||||
invalid: "Phone nr is invalid"
|
invalid: "Phone nr is invalid"
|
||||||
|
|
|
@ -32,6 +32,21 @@ class ContactTest < ActiveJob::TestCase
|
||||||
assert contact.invalid?
|
assert contact.invalid?
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_allowed_and_disallowed_symbols_for_name
|
||||||
|
contact = valid_contact
|
||||||
|
contact.name = 'MARY ÄNN O’CONNEŽ-ŠUSLIK'
|
||||||
|
assert contact.valid?
|
||||||
|
contact.name = 'Boğaçhan Çağlayan'
|
||||||
|
assert contact.valid?
|
||||||
|
contact.name = '# "¤ #" ¤ "?'
|
||||||
|
assert contact.invalid?
|
||||||
|
|
||||||
|
contact.country_code = 'FI'
|
||||||
|
contact.ident_type = Contact::ORG
|
||||||
|
contact.ident = '1234'
|
||||||
|
assert contact.valid?
|
||||||
|
end
|
||||||
|
|
||||||
def test_validates_code_format
|
def test_validates_code_format
|
||||||
contact = valid_contact.dup
|
contact = valid_contact.dup
|
||||||
max_length = 100
|
max_length = 100
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue