Merge branch 'migrate-fabricators-to-factory-bot-factories' into registry-343

This commit is contained in:
Artur Beljajev 2017-11-15 15:46:54 +02:00
commit 411af16f9c
58 changed files with 2505 additions and 432 deletions

View file

@ -173,6 +173,8 @@ namespace :dev do
end
end
Setting.api_ip_whitelist_enabled = false
Setting.address_processing = false
Setting.registrar_ip_whitelist_enabled = false
ActiveRecord::Base.transaction do

View file

@ -0,0 +1,12 @@
class E164Validator < ActiveModel::EachValidator
def validate_each(record, attribute, _value)
length_validator = ActiveModel::Validations::
LengthValidator.new(maximum: 17, attributes: attribute)
length_validator.validate(record)
format_validator = ActiveModel::Validations::
FormatValidator.new(with: /\+[0-9]{1,3}\.[0-9]{1,14}?/,
attributes: attribute)
format_validator.validate(record)
end
end

View file

@ -0,0 +1,11 @@
class Iso31661Alpha2Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
record.errors.add(attribute, :invalid_iso31661_alpha2) unless valid_country_code?(value)
end
private
def valid_country_code?(country_code)
Country.new(country_code)
end
end

View file

@ -0,0 +1,13 @@
class Iso8601Validator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
if options[:date_only]
record.errors.add(attribute, :invalid_iso8601_date) unless value =~ date_format
end
end
private
def date_format
/\d{4}-\d{2}-\d{2}/
end
end

View file

@ -2,11 +2,11 @@ class PhoneValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
return if record.errors[:phone].any?
splitted_phone = value.split('.')
country_code = splitted_phone.first
phone_number = splitted_phone.second
phone_parts = value.split('.')
country_code = phone_parts.first
subscriber_no = phone_parts.second
if zeros_only?(country_code) || zeros_only?(phone_number)
if zeros_only?(country_code) || zeros_only?(subscriber_no)
record.errors.add(attribute, :invalid)
end
end