Fix for conditional question removed answers not being deleted #3481
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.
THIS PR IS GOING TO BE RECREATED WITH RAILS 7 CODE. SO CLOSING THIS.
A Conditional Question (with action: "remove" and in a Phase with multiple sections) for this bug can be described structurally as follows:
Bug Description:
Currently in the code if we answer several questions in a phase in various sections, then subsequently answer an option of a Conditional question that removes some of the questions answered. The removed answers are hidden in UI, but the answers to the hidden questions remain persisted in the database and are hidden in the UI, not cleared. As a result if we change our answer to the same Conditional Question the removed questions with the "stale/old" answers reappear.
Expected Behavior
We would expect the removed questions answers to be deleted from the database and cleared from the UI. So if we change our answer to the same Conditional Question the removed questions should reappear without the "stale/old" answers. Further the removed questions could be in different sections in phase.
Testing
Attached is a script for testing in your development environment and running the content in a Rails console.
Test_script_for_setup_template_with_conditional_question.txt
We found convenient to use the seeds file to populate the database as follows:
We then brought up a Rails console and ran the content of the test script by copying and pasting.

You can view the template we created as the Admin User you logged in as.

Here is the structure of the conditional question we are testing, namely question
"Q2. Will your data be open? THE CONDITIONAL QUESTION"
Testing suggestions
With each branch login as user with email: [email protected] and password: password123 .
Create a plan with organisation Conditional Tests Organisation and no funder, e.g.,
Then fill in answers to following sets of questions:
You can use the same plan for both branches. You just need to fill in the values again to test each time.
Now answer question "Q2. Will your data be open? THE CONDITIONAL QUESTION" with
Yes, No and Don't know
As mentioned above, the branch for issue, should show the expected behaviour: