Ensure a valid locale is persisted during login

This action has to be performed here and not in I18nHelper, as spree_current_user is not initialized yet during the other checks / setting the selected locale value in the app
This commit is contained in:
Matt-Yorkley
2020-07-02 14:35:02 +02:00
parent 91880cdbec
commit 4e08d2049f
2 changed files with 9 additions and 1 deletions

View File

@@ -6,11 +6,13 @@ module Spree
include Spree::Core::ControllerHelpers::Common
include Spree::Core::ControllerHelpers::Order
include Spree::Core::ControllerHelpers::SSL
include I18nHelper
ssl_required :new, :create, :destroy, :update
ssl_allowed :login_bar
before_action :set_checkout_redirect, only: :create
after_action :ensure_valid_locale, only: :create
def create
authenticate_spree_user!
@@ -48,5 +50,11 @@ module Spree
redirect_to(session["spree_user_return_to"] || default)
session["spree_user_return_to"] = nil
end
def ensure_valid_locale
return unless spree_current_user && !available_locale?(spree_current_user.locale)
spree_current_user.update!(locale: I18n.default_locale)
end
end
end

View File

@@ -161,7 +161,7 @@ feature "Authentication", js: true do
user.update!(locale: "xx")
end
xit "logs in successfully and resets the user's locale to the default" do
it "logs in successfully and resets the user's locale to the default" do
fill_in_and_submit_login_form(user)
expect_logged_in