-
Notifications
You must be signed in to change notification settings - Fork 1
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
Define steps in ConsentForm #482
Conversation
Replace the `on:` context based validation with conditional validation that relies on specifying a `form_step`. This also makes the validations fire off for previous steps, and at the end for the final `record` step. Unifies the `*_params` methods in the EditController into one `update_params` method. `required_for_step?` takes an optional `exact` parameter, for transient steps like the `school` one that ask a question but don't actually save a field to the database (and shouldn't be re-validated on other steps). Overall approach based on: https://www.joshmcarthur.com/2014/12/23/rails-multistep-forms.html
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 feel like the methods in the model, at least, should have a spec. Can we (and should we) also test that the right validations are triggered at the right time, to test stuff like the school
step having exact
set?
Sorry, I should say that those comments aside, I really like this change ... stuff like sticking the form steps into the model is good, even if at first glance the form step s are a controller concern ... the fact that they are here with the step validations is good. |
Allows us to use .create! as before.
72e8092
to
99a774d
Compare
Allows us to use a more terse syntax for testing validations.
spec/models/consent_form_spec.rb
Outdated
# expect(cf).to validate_comparison_of(:date_of_birth) | ||
# .is_less_than(Time.zone.today) | ||
# .is_greater_than_or_equal_to(22.years.ago.to_date) | ||
# .is_less_than_or_equal_to(3.years.ago.to_date) | ||
# .on(:update) |
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'm not sure why this doesn't work
NoMethodError:
undefined method `validate_comparison_of' for #<RSpec::ExampleGroups::ConsentForm::Validations::WhenFormStepIsDateOfBirth "example at ./spec/models/consent_form_spec.rb:30">
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.
Looked into this ... looks like the most recent version of should-matchers
, 5.3.0 from Dec 2022, doesn't include this matcher. This matcher was added earlier this year and hasn't been released yet. 🤦
3c04d2b
to
cacaf89
Compare
it do | ||
should validate_inclusion_of(:is_this_their_school).in_array( | ||
%w[yes no] | ||
).on(:update) | ||
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.
This is the linter's idea, not mine
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.
Nice. required_for_step
still makes me itch, but
Replace the
on:
context based validation with conditional validation that relies on specifying aform_step
. This also makes the validations fire off for previous steps, and at the end for the finalrecord
step.Unifies the
*_params
methods in the EditController into oneupdate_params
method.required_for_step?
takes an optionalexact
parameter, for transient steps like theschool
one that ask a question but don't actually save a field to the database (and shouldn't be re-validated on other steps).Overall approach based on:
https://www.joshmcarthur.com/2014/12/23/rails-multistep-forms.html