Fix code climate offences

#569
This commit is contained in:
Artur Beljajev 2017-09-04 08:54:54 +03:00
parent 834b13c922
commit 7530dd7b62
4 changed files with 24 additions and 23 deletions

View file

@ -60,7 +60,8 @@ module EppErrors
aggregation.class.epp_code_map.each do |epp_code, attr_to_error| aggregation.class.epp_code_map.each do |epp_code, attr_to_error|
epp_code_found = attr_to_error.any? { |i| i == [attr, error_detail[:error]] } epp_code_found = attr_to_error.any? { |i| i == [attr, error_detail[:error]] }
if epp_code_found next unless epp_code_found
message = aggregation.errors.generate_message(attr, error_detail[:error], error_detail) message = aggregation.errors.generate_message(attr, error_detail[:error], error_detail)
message = aggregation.errors.full_message(attr, message) message = aggregation.errors.full_message(attr, message)
@ -72,7 +73,6 @@ module EppErrors
end end
end end
end end
end
epp_errors epp_errors
end end

View file

@ -165,7 +165,7 @@ class Epp::Contact < Contact
identifier = Ident.new(code: ident, identifier = Ident.new(code: ident,
type: ident_frame.attr('type'), type: ident_frame.attr('type'),
country_code: ident_frame.attr('cc'), country_code: ident_frame.attr('cc')
) )
identifier.validate identifier.validate

View file

@ -1,21 +1,22 @@
class Contact::Ident::CodeValidator < ActiveModel::EachValidator class Contact::Ident::CodeValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value) def validate_each(record, attribute, value)
if record.country_code == 'EE' return unless record.country_code == 'EE'
if record.national_id?
if record.national_id? && !valid_national_id_ee?(value)
record.errors.add(attribute, record.errors.add(attribute,
:invalid_national_id, :invalid_national_id,
country: record.country) unless valid_national_id_ee?(value) country: record.country)
end end
if record.reg_no? if record.reg_no?
validator = ActiveModel::Validations::FormatValidator.new(with: reg_no_ee_format, validator = ActiveModel::Validations::
FormatValidator.new(with: reg_no_ee_format,
attributes: attribute, attributes: attribute,
message: :invalid_reg_no, message: :invalid_reg_no,
country: record.country) country: record.country)
validator.validate(record) validator.validate(record)
end end
end end
end
private private

View file

@ -1,5 +1,5 @@
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) validator = ActiveModel::Validations::LengthValidator.new(maximum: 17, attributes: attribute)
validator.validate(record) validator.validate(record)