diff --git a/app/models/concerns/epp_errors.rb b/app/models/concerns/epp_errors.rb index fd064dc09..7395732ca 100644 --- a/app/models/concerns/epp_errors.rb +++ b/app/models/concerns/epp_errors.rb @@ -60,16 +60,16 @@ module EppErrors 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]] } - if epp_code_found - message = aggregation.errors.generate_message(attr, error_detail[:error], error_detail) - message = aggregation.errors.full_message(attr, message) + next unless epp_code_found - if attr != :base - message = "#{aggregation.model_name.human} #{message.camelize(:lower)}" - end + message = aggregation.errors.generate_message(attr, error_detail[:error], error_detail) + message = aggregation.errors.full_message(attr, message) - epp_errors << { code: epp_code, msg: message } + if attr != :base + message = "#{aggregation.model_name.human} #{message.camelize(:lower)}" end + + epp_errors << { code: epp_code, msg: message } end end end diff --git a/app/models/epp/contact.rb b/app/models/epp/contact.rb index c60aca64c..a936045f5 100644 --- a/app/models/epp/contact.rb +++ b/app/models/epp/contact.rb @@ -165,8 +165,8 @@ class Epp::Contact < Contact identifier = Ident.new(code: ident, type: ident_frame.attr('type'), - country_code: ident_frame.attr('cc'), - ) + country_code: ident_frame.attr('cc') + ) identifier.validate diff --git a/app/validators/contact/ident/code_validator.rb b/app/validators/contact/ident/code_validator.rb index 25f76f1b1..255867a75 100644 --- a/app/validators/contact/ident/code_validator.rb +++ b/app/validators/contact/ident/code_validator.rb @@ -1,19 +1,20 @@ class Contact::Ident::CodeValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) - if record.country_code == 'EE' - if record.national_id? - record.errors.add(attribute, - :invalid_national_id, - country: record.country) unless valid_national_id_ee?(value) - end + return unless record.country_code == 'EE' - if record.reg_no? - validator = ActiveModel::Validations::FormatValidator.new(with: reg_no_ee_format, - attributes: attribute, - message: :invalid_reg_no, - country: record.country) - validator.validate(record) - end + if record.national_id? && !valid_national_id_ee?(value) + record.errors.add(attribute, + :invalid_national_id, + country: record.country) + end + + if record.reg_no? + validator = ActiveModel::Validations:: + FormatValidator.new(with: reg_no_ee_format, + attributes: attribute, + message: :invalid_reg_no, + country: record.country) + validator.validate(record) end end diff --git a/lib/validators/e164_validator.rb b/lib/validators/e164_validator.rb index ee13db1e9..8bde2112f 100644 --- a/lib/validators/e164_validator.rb +++ b/lib/validators/e164_validator.rb @@ -1,5 +1,5 @@ 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.validate(record)