Files
nairobi/spec/controllers/subscriptions_controller_spec.rb
Javi Martín 3e13f93ebd Add controller tests for switch_locale
This way it'll be easier to change it while checking we haven't broken
existing behavior.

While writing the tests, I noticed we were sometimes storing a symbol in
the session while sometimes we were storing a string. So we're adding a
`to_s` call so we always store a string in the session.
2024-06-05 16:10:56 +02:00

32 lines
995 B
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
end
end