Note that, for everything to work consistently, we need to make sure that the default locale is one of the available locales. Also note that we aren't overwriting the `#save ` method set by globalize. I didn't feel too comfortable changing a monkey-patch which ideally shouldn't be there in the first place, I haven't found a case where `Globalize.locale` is `nil` (since it defaults to `I18n.locale`, which should never be `nil`), so using `I18n.default_locale` probably doesn't affect us.
43 lines
1.3 KiB
Ruby
43 lines
1.3 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 enabled locales" do
|
|
Setting["locales.default"] = "fr"
|
|
Setting["locales.enabled"] = "fr nl"
|
|
|
|
create(:user, locale: "es", subscriptions_token: "mytoken")
|
|
|
|
get :edit, params: { token: "mytoken" }
|
|
|
|
expect(session[:locale]).to eq "fr"
|
|
end
|
|
end
|
|
end
|