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:
@@ -46,7 +46,7 @@ class ApplicationController < ActionController::Base
|
||||
current_user.update(locale: locale)
|
||||
end
|
||||
|
||||
session[:locale] = locale
|
||||
session[:locale] = locale.to_s
|
||||
I18n.with_locale(locale, &action)
|
||||
end
|
||||
|
||||
|
||||
@@ -41,10 +41,10 @@ class Management::BaseController < ActionController::Base
|
||||
|
||||
def switch_locale(&action)
|
||||
if params[:locale] && I18n.available_locales.include?(params[:locale].to_sym)
|
||||
session[:locale] = params[:locale]
|
||||
session[:locale] = params[:locale].to_s
|
||||
end
|
||||
|
||||
session[:locale] ||= I18n.default_locale
|
||||
session[:locale] ||= I18n.default_locale.to_s
|
||||
|
||||
I18n.with_locale(session[:locale], &action)
|
||||
end
|
||||
|
||||
@@ -32,7 +32,7 @@ class SubscriptionsController < ApplicationController
|
||||
|
||||
def set_user_locale(&action)
|
||||
if params[:locale].blank?
|
||||
session[:locale] = I18n.available_locales.find { |locale| locale == @user.locale&.to_sym }
|
||||
session[:locale] = I18n.available_locales.find { |locale| locale == @user.locale&.to_sym }.to_s
|
||||
end
|
||||
I18n.with_locale(session[:locale], &action)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user