Check the draft question's answer type is correct for answer type specific routes#2635
Conversation
99ffeb1 to
2c91700
Compare
2c91700 to
f781337
Compare
Add a service with a method to get the start page for adding/editing a question of a given answer type. This is so that we can re-use this code to redirect the user to the correct start page if they try to visit a route for editing a question that does not match the answer type of the draft question. Determine whether to return the new or edit route by looking at the presence of a page_id request param.
Add a before_action that checks the draft question has the expected answer type for the address settings routes. If it doesn't redirect the user to either the start page for adding a new question, or the edit question page for an existing question. Add a private method to PagesController to do the check so this can be reused for other answer-type specific routes.
Add a before_action that checks the draft question has the expected answer type for the date settings routes. If it doesn't redirect the user to either the start page for adding a new question, or the edit question page for an existing question.
Add a before_action that checks the draft question has the expected answer type for the name settings routes. If it doesn't redirect the user to either the start page for adding a new question, or the edit question page for an existing question.
Add a before_action that checks the draft question has the expected answer type for the text question settings routes. If it doesn't redirect the user to either the start page for adding a new question, or the edit question page for an existing question.
Add a before_action that checks the draft question has the expected answer type for the selection question settings routes. If it doesn't redirect the user to either the start page for adding a new question, or the edit question page for an existing question.
f781337 to
6401fe9
Compare
|
|
🎉 A review copy of this PR has been deployed! You can reach it at: https://pr-2635.admin.review.forms.service.gov.uk/ It may take 5 minutes or so for the application to be fully deployed and working. If it still isn't ready For the sign in details and more information, see the review apps wiki page. |
|
Looks good to me, one small thought... I wonder if it's worth deleting the Kapture.2026-03-17.at.15.09.14.mp4To be fair, you'd hope that they'd notice the question text was wrong at some point before making the form live, so it's not a big issue! |
Interesting point - I don't think that's different to the existing behaviour, so maybe a slightly different issue to the one that's being fixed here? I think a better fix for that issue would be to delete the DraftQuestion when the answer type page is submitted if the answer type has changed - but I think that's slightly unrelated to this issue so is it okay not to do that as part of this? |
Ah okay, I didn't realise that it was existing behaviour, I was trying to do something that would result in a |
|
@lfdebrux is this good to be approved now? |
There was a problem hiding this comment.
@stephencdaly woops, sorry, I thought I had, turns out I had written something then forgot to hit the button!
Code changes look good to me, and I've tested they fix the problem described in the ticket.



What problem does this pull request solve?
Trello card: https://trello.com/c/QyQTTwCc
For routes for adding or editing a question that expect to be editing a question of a specific answer type, add a before_action that checks the answer type of the draft question matches the expected answer type. If the answer type does not match:
Doing this avoids raising a NoMethodError when a user attempts to visit a route for an answer type that does not match the DraftQuestion that exists, and prevents any other unexpected errors that may occur.
Things to consider when reviewing