Files
nairobi/spec/controllers/subscriptions_controller_spec.rb
Javi Martín 709f39c6ce 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`.
2024-06-05 16:10:56 +02:00

40 lines
1.2 KiB
Ruby

require "rails_helper"
describe SubscriptionsController do
describe "GET edit" do
it "returns a 404 code with a wrong token" do
expect { get :edit, params: { token: "non_existent" } }.to raise_error ActiveRecord::RecordNotFound
end
it "doesn't allow access to anonymous users without a token" do
get :edit, params: { token: "" }
expect(response).to redirect_to "/"
expect(flash[:alert]).to eq "You do not have permission to access this page."
end
it "shows the 'not allowed' message in the current locale" do
get :edit, params: { token: "", locale: :es }
expect(response).to redirect_to "/"
expect(flash[:alert]).to eq "No tienes permiso para acceder a esta página."
end
it "uses the user locale where there's no locale in the parameters" do
create(:user, locale: "es", subscriptions_token: "mytoken")
get :edit, params: { token: "mytoken" }
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