-
Notifications
You must be signed in to change notification settings - Fork 186
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Okay done. |
||||||
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, name: message_args[:name]) | ||||||
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, name: message_args[:name]) | ||||||
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, name: message_args[:name]) | ||||||
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, { name: p.name }, competition.id).each do |validation| | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my suggestion above, this could be changed to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||||||
if validation.is_a?(ValidationError) | ||||||
@errors << validation | ||||||
elsif validation.is_a?(ValidationWarning) | ||||||
|
There was a problem hiding this comment.
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...
There was a problem hiding this comment.
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 :)There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done