We add new method set_user_locale to render the page with the user's preferred locale. Note that we add a condition 'if params[:locale].blank?' to recover the user's preferred locale. This is necessary because it may be the case that the user does not have an associated locale, and when execute '@user.locale' when this value is 'nil', by default returns the default locale. As we do not want this to happen and we want the locale we receive as parameter to prevail in this case.
24 lines
755 B
Ruby
24 lines
755 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
|
|
end
|
|
end
|