Handle unavailable locales in subscriptions

There was an edge case where a user could configure a locale and then
the application would change the locales to that one would no longer be
available. In that case, we were getting a `I18n::InvalidLocale`
exception when accessing the subscriptions page.

So now, we're defaulting to `I18n.locale`. Note we're using
`I18n.locale`instead of `I18n.default_locale` because `set_user_locale`
is called inside the `switch_locale` block in `ApplicationController`,
which already sets `I18n.locale` based on `I18n.default_locale`.
This commit is contained in:
Javi Martín
2024-05-22 16:53:37 +02:00
parent 3e13f93ebd
commit 709f39c6ce
2 changed files with 13 additions and 1 deletions

View File

@@ -27,5 +27,13 @@ describe SubscriptionsController do
expect(session[:locale]).to eq "es"
end
it "only accepts available locales" do
create(:user, locale: "wl", subscriptions_token: "mytoken")
get :edit, params: { token: "mytoken" }
expect(session[:locale]).to eq "en"
end
end
end