Skip to content
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

Fix I18n::MissingTranslationData exception for checkbox 'none' option #2014

Merged

Conversation

floehopper
Copy link
Contributor

This has been a problem since #2005, but it only came to light after a
production deployment. Here are couple of examples of the exceptions
we saw:

Checkbox questions have an implicit 'none' response if the user doesn't select
any of the checkboxes. CheckboxQuestionPresenter#response_labels translates
the options for display in the 'Previous answers' section at the bottom of the
page.

When the translation fallbacks were removed in #2005, a
I18n::MissingTranslationData was being raised when the user did not select
any checkboxes.

Unfortunately, this commit added a translation for the 'none' option even
though the CheckboxSampleFlow didn't have an explicit :none option.
Note also that the assert_page_has_content was changed to check for 'None'
instead of 'none'.

In this commit, I've removed the translation for the 'none' option which gave
me a failing test which replicated the problem we'd seen in production.

I've fixed the failing test by adding an if/else statement to
CheckboxQuestionPresenter#response_labels which effectively reintroduces
the translation fallback in this very specific case.

I'm not totally happy with this solution, but hopefully it'll do for now.

You can see that the problem is fixed by visiting these two example URLs:

There should be no exception and you should see "none" in the previous answers.

This has been a problem since #2005, but it only came to light after a
production deployment.

Checkbox questions have an implicit 'none' response if the user doesn't select
any of the checkboxes. `CheckboxQuestionPresenter#response_labels` translates
the options for display in the 'Previous answers' section at the bottom of the
page.

When the translation fallbacks were removed in #2005, a
`I18n::MissingTranslationData` was being raised when the user did not select
any checkboxes.

Unfortunately, this commit [1] added a translation for the 'none' option even
though the `CheckboxSampleFlow` [2] didn't have an explicit `:none` option.
Note also that the `assert_page_has_content` was changed to check for 'None'
instead of 'none'.

In this commit, I've removed the translation for the 'none' option which gave
me a failing test which replicated the problem we'd seen in production.

I've fixed the failing test by adding an `if/else` statement to
`CheckboxQuestionPresenter#response_labels` which effectively reintroduces
the translation fallback in this very specific case.

I'm not totally happy with this solution, but hopefully it'll do for now.

[1]: f50ec82
[2]: https://github.com/alphagov/smart-answers/blob/master/test/fixtures/smart_answer_flows/checkbox-sample.rb
@chrisroos
Copy link
Contributor

Looks good to me.

floehopper added a commit that referenced this pull request Oct 15, 2015
…heckbox-question-none-option

Fix I18n::MissingTranslationData exception for checkbox 'none' option
@floehopper floehopper merged commit 8a699db into master Oct 15, 2015
@floehopper floehopper deleted the fix-missing-translations-for-checkbox-question-none-option branch October 15, 2015 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants