-
Notifications
You must be signed in to change notification settings - Fork 4
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 a function to age at date #1143
base: master
Are you sure you want to change the base?
Conversation
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.
Seems to work at first sight! However, our pipeline complains. You should see the logs of the pipeline. Perhaps some checks failed or your code does not match our style requirements.
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.
I would approve the changes, but I want to test this beforehand (dates and timezones might give unexpected results). I'm quite busy though, so don't expect me to have done this in a day or two. Perhaps someone else could adjust (or expand?) the test suite to test this edge case (and, especially, if no one else unjustly can sign up).
def underage_at?(event_date) | ||
return true if birth_date.blank? | ||
|
||
return ((18.years.ago + (event_date - Date.today)) < birth_date) |
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.
I think birth_date + 18.years < event_date
would read better (if that's still correct (code)).
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.
I could not create a scenario where someone under the age of 18 could sign up for an activity with alcohol past their 18th birthday. Thus, I think this does not work.
Reproduction steps:
- Log in as
[email protected]
and note your name. - Find an activity that is open to sign up for, note its id.
- Log out and back in as
[email protected]
, and make your user underage. - Set the activity's start and end date one day before the day your user would turn 18, and make the activity 18+.
- Assert that, when loggin in as test, you cannot sign up.
- Log back in as dev, and change the date to start a day later (on test's birthday).
- Logging back in as test, assert that you can sign up. <=== this fails. Same thing if the activity is in 2030.
I now realise the error was 'Could not enroll' instead of 'Could not enrol, its for adults only'. Perhaps something weird is going on. |
Added the function that checks the user's age at the time of the event in stead of at the time of enrollment