Fix code climate offences

#569
This commit is contained in:
Artur Beljajev 2017-09-04 09:02:37 +03:00
parent 7530dd7b62
commit 3de5a0b51b
2 changed files with 13 additions and 11 deletions

View file

@ -7,7 +7,7 @@ class Contact::Ident
validates :code, presence: true, code: true validates :code, presence: true, code: true
validates :code, iso8601: { date_only: true }, if: :birthday? validates :code, iso8601: { date_only: true }, if: :birthday?
validates :type, presence: true, inclusion: { in: Proc.new { types } } validates :type, presence: true, inclusion: { in: proc { types } }
validates :country_code, presence: true, iso31661_alpha2: true validates :country_code, presence: true, iso31661_alpha2: true
validate :mismatched validate :mismatched
@ -16,15 +16,15 @@ class Contact::Ident
'2003' => [ '2003' => [
[:code, :blank], [:code, :blank],
[:type, :blank], [:type, :blank],
[:country_code, :blank], [:country_code, :blank]
], ],
'2005' => [ '2005' => [
[:base, :mismatch], [:base, :mismatch],
[:code, :invalid_national_id], [:code, :invalid_national_id],
[:code, :invalid_reg_no], [:code, :invalid_reg_no],
[:code, :invalid_iso8601], [:code, :invalid_iso8601],
[:country_code, :invalid_iso31661_alpha2], [:country_code, :invalid_iso31661_alpha2]
], ]
} }
end end
@ -36,7 +36,7 @@ class Contact::Ident
def self.mismatches def self.mismatches
[ [
Mismatch.new('birthday', Country.new('EE')), Mismatch.new('birthday', Country.new('EE'))
] ]
end end
@ -63,7 +63,7 @@ class Contact::Ident
private private
# https://github.com/rails/rails/issues/1513 # https://github.com/rails/rails/issues/1513
def validation_context=(value); end def validation_context=(_value); end
def mismatched def mismatched
mismatched = self.class.mismatches.include?(Mismatch.new(type, country)) mismatched = self.class.mismatches.include?(Mismatch.new(type, country))

View file

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