diff --git a/app/controllers/tickets_controller.rb b/app/controllers/tickets_controller.rb index 6ee1e7a0e4..b3838937ce 100644 --- a/app/controllers/tickets_controller.rb +++ b/app/controllers/tickets_controller.rb @@ -90,7 +90,8 @@ def edit_person_validators ticket.metadata.tickets_edit_person_fields.each do |edit_person_field| case edit_person_field[:field_name] when TicketsEditPersonField.field_names[:dob] - dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(Date.parse(edit_person_field[:new_value])) + dob_to_validate = Date.parse(edit_person_field[:new_value]) + dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(dob_to_validate, nil, name: ticket.metadata.wca_id) end end diff --git a/lib/results_validators/persons_validator.rb b/lib/results_validators/persons_validator.rb index 6853f8c8ed..c7f41bcca9 100644 --- a/lib/results_validators/persons_validator.rb +++ b/lib/results_validators/persons_validator.rb @@ -41,22 +41,22 @@ def include_persons? true end - def self.dob_validations(dob, competition_id = nil, name = nil) + def self.dob_validations(dob, competition_id = nil, **message_args) validation_issues = [] # Check if DOB is January 1 if dob.month == 1 && dob.day == 1 - validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, name: name) + validation_issues << ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, **message_args) end # Check if DOB is very young, competitor less than 3 years old are extremely rare, so we'd better check these birthdate are correct. if dob.year >= Time.now.year - 3 - validation_issues << ValidationWarning.new(:persons, competition_id, VERY_YOUNG_PERSON_WARNING, name: name) + validation_issues << ValidationWarning.new(:persons, competition_id, VERY_YOUNG_PERSON_WARNING, **message_args) end # Check if DOB is not so young if dob.year <= Time.now.year - 100 - validation_issues << ValidationWarning.new(:persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, name: name) + validation_issues << ValidationWarning.new(:persons, competition_id, NOT_SO_YOUNG_PERSON_WARNING, **message_args) end validation_issues @@ -101,7 +101,7 @@ def run_validation(validator_data) name: p.name) end - PersonsValidator.dob_validations(p.dob, competition.id, p.name).each do |validation| + PersonsValidator.dob_validations(p.dob, competition.id, name: p.name).each do |validation| if validation.is_a?(ValidationError) @errors << validation elsif validation.is_a?(ValidationWarning)