Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added name argument to validators for ticket validations #10572

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

danieljames-dj
Copy link
Member

One drawback of this is still js cannot replace "%{name}" with name. So, this doesn't fix the UI issue. This should be solved when moved to i18n. This PR aims at sending name parameter for dob_validations method.

@@ -41,22 +41,22 @@ def include_persons?
true
end

def self.dob_validations(dob, competition_id = nil, name = nil)
def self.dob_validations(dob, message_args = {}, competition_id = nil)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can make it more Ruby-esque by something like...

Suggested change
def self.dob_validations(dob, message_args = {}, competition_id = nil)
def self.dob_validations(dob, competition_id = nil, **message_args)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you take this suggestion, then below you can "spread" the parameters into the ValidationIssue class as well: ValidationWarning.new(:persons, competition_id, DOB_0101_WARNING, **message_args)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay done.

@@ -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, { name: p.name }, competition.id).each do |validation|
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For my suggestion above, this could be changed to PersonsValidator.dob_validations(p.dob, competition.id, name: p.name)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@@ -49,7 +49,7 @@ 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_validation_issues = ResultsValidators::PersonsValidator.dob_validations(Date.parse(edit_person_field[:new_value]), { name: ticket.metadata.wca_id })
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you like my other suggestion about the method signature, then this can become...

Suggested change
dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(Date.parse(edit_person_field[:new_value]), { name: ticket.metadata.wca_id })
dob_validation_issues = ResultsValidators::PersonsValidator.dob_validations(Date.parse(edit_person_field[:new_value]), name: ticket.metadata.wca_id)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sidenote: You should probably extract the Date.parse into its own line, helps with debugging :)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
No open projects
Status: No status
Development

Successfully merging this pull request may close these issues.

2 participants