Patch autosave associations to support conditional validations #2381
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What
For more details please read NOTE in config/initializers/01_autosave_association_patch.rb
Claim associations are autovalidated by default as long as they're defined. With this change, they're only validated if they're required for a specific step/stage or if they're being submitted through the API.
Ticket
Check your claim page fixes
Why
Rails models that accept nested attributes for some of its associations autosave and validate those associations by default.
What this means in effect is that, even though the application has its own stage/step validation setup for the claims model, as long as an association was previously set in another stage, when submitting data for another stage, that association will still be autosaved and validated. (This is noted more so when one of the stages is submitted as a draft with invalid data for one of the associations and other stage is then submitted with valid data but fails due to the previously submitted association being invalid, even though we're not at the step of validating that association).
How
form_step
, as that information is specifically related with the claim submission process only, and theform_step
is now set only during that flow.validate: <value>
as by default it just checks if is true or not. This way it allows us to control when these associations are actually validated, letting the validations classes behave as expected during the submission flow and only validate the data related with that particular stage. (NOTE: Obviously this patching will potentially have an impact on any future Rails updates)Also, worth of note: