-
Notifications
You must be signed in to change notification settings - Fork 13
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
[FYST-1704] Income/ donation forms: Inaccurate date selection #5570
base: main
Are you sure you want to change the base?
[FYST-1704] Income/ donation forms: Inaccurate date selection #5570
Conversation
Heroku app: https://gyr-review-app-5570-2ce2c8acb364.herokuapp.com/ |
28a4708
to
bc93673
Compare
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 someone else @powersurge360 / @tahsinaislam who have worked on date_accessible in the past should review this but I'm trying to understand the code!
send("#{property}_day").to_i, | ||
) | ||
) | ||
end |
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.
what happens if day/month/year attribute is missing? (fails the .present?
check?) Is there validation further down the line that will give an error that the date is invalid b/c something is missing?
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 one of the values is missing, then the date won't get set / updated, and it'll fail the inclusion check in it's model
@@ -33,6 +33,5 @@ class Az321Contribution < ApplicationRecord | |||
validates :date_of_contribution, | |||
inclusion: { | |||
in: TAX_YEAR.beginning_of_year..TAX_YEAR.end_of_year | |||
}, | |||
presence: true | |||
} |
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.
why is the presence check removed?
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.
for this the inclusion validation serves as a presence check as well, as nil
values fall outside of the range. It made it so I didn't have to duplicate the error message
@@ -4,7 +4,6 @@ module DateAccessible | |||
TAX_YEAR = Date.new(Rails.configuration.statefile_current_tax_year) | |||
|
|||
included do | |||
private |
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.
what's the significance of making these not private methods?
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.
The methods from the module are class methods, so they can't be private, and I believe this line has no effect
subject.expiration_date_day = 21 | ||
subject.expiration_date_year = nil | ||
subject.valid? | ||
expect(subject.expiration_date).to eq(Date.new(year, 2, 1)) |
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.
hmm i don't understand this example -- the year is nil
but the date is still set to year
-- is it b/c year
nil
is invalid so therefore it was never written to the expiration date?
also should maybe split into a "it" block to describe what we're trying to test here
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.
that's right, the intent is to say that b/c ``year
nil` is invalid, it won't write to the date. I'll split this out for better clarity on what it's testing
One blocking issue I noticed: This breaks the _year, _month, and _day attr_readers, which means that the forms no longer show the previously entered dates when rendering. To see this, go through a state_id page like Edit: As @arinchoi03 mentioned, @powersurge360 would also be a good pair on this, as he created |
self.define_method("#{property}_day") do | ||
send(property)&.day | ||
end | ||
attr_reader :"#{property}_month", :"#{property}_year", :"#{property}_day" |
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 this is the spot to repair the issue Mike surfaced. I think something like
self.define_method("#{property}_month") do
super || send(property)&.month
end
should do the trick. Or maybe you'll have to retrieve the ivar directly.
With the update to the attr accessors, it appears we're now able to view incorrect fields when rerendering @mrotondo |
0b36b7b
to
097de8d
Compare
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.
Looks great. I left two notes but the only one that I feel is a blocker is translating a validation string in the new default validator for the date.
self.define_method("#{property}_day") do | ||
send(property)&.day | ||
self.instance_variable_get("@#{property}_day") || send(property)&.day |
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.
This will sidestep any other setters, as opposed to calling super
. Intended?
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.
Yes that's the intent - for this setter to default to the instance variable, with a backup of parsing the persisted value
define_method("#{property}_date_valid") do | ||
date = send(property) | ||
if date.present? && !Date.valid_date?(date.year, date.month, date.day) | ||
errors.add(property, :invalid_date, message: "is not a valid calendar 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.
If we're doing validation, should be translated.
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.
absolutely, thanks for the catch
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
Co-authored-by: Hugo Melo <[email protected]>
867a9a4
to
fd87c4b
Compare
Co-authored-by: Hugo Melo <[email protected]>
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.
Issues addressed. Approved.
Co-authored-by: Hugo Melo <[email protected]>
a9e4734
to
4b7f5ba
Compare
Co-authored-by: Hugo Melo <[email protected]>
4b7f5ba
to
e164c23
Compare
Link to pivotal/JIRA issue
Is PM acceptance required? (delete one)
Reminder: merge main into this branch and get green tests before merging to main
What was done?
Update date accessible validations, so that all incoming parts of a date (day, month, and year) are validated together instead of piece by piece. This fixes cases where users enter invalid dates, like Feb 31st.