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.
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
require "rails_helper"
|
||||
|
||||
describe Management::BaseController do
|
||||
before { session[:manager] = double }
|
||||
|
||||
controller do
|
||||
skip_authorization_check
|
||||
|
||||
def index
|
||||
render plain: I18n.locale
|
||||
end
|
||||
end
|
||||
|
||||
describe "managed_user" do
|
||||
it "returns existent user with session document info if present" do
|
||||
session[:document_type] = "1"
|
||||
@@ -21,4 +31,38 @@ describe Management::BaseController do
|
||||
expect(managed_user.document_number).to eq "333333333E"
|
||||
end
|
||||
end
|
||||
|
||||
describe "#switch_locale" do
|
||||
it "uses the default locale by default" do
|
||||
get :index
|
||||
|
||||
expect(response.body).to eq "en"
|
||||
end
|
||||
|
||||
it "uses the locale in the parameters when it's there" do
|
||||
get :index, params: { locale: :es }
|
||||
|
||||
expect(response.body).to eq "es"
|
||||
end
|
||||
|
||||
it "uses the locale in the session if there are no parameters" do
|
||||
get :index, params: { locale: :es }
|
||||
|
||||
expect(response.body).to eq "es"
|
||||
|
||||
get :index
|
||||
|
||||
expect(response.body).to eq "es"
|
||||
end
|
||||
|
||||
it "uses the locale in the parameters even when it's in the session" do
|
||||
get :index
|
||||
|
||||
expect(response.body).to eq "en"
|
||||
|
||||
get :index, params: { locale: :es }
|
||||
|
||||
expect(response.body).to eq "es"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user