Set user locale on user registrations #create

This is done so that user.locale is used in the first confirmation email. This also stores user.locale in the DB from registration.
This commit is contained in:
luisramos0
2018-12-18 15:29:50 +00:00
parent a9222665b8
commit 5e960512ac
2 changed files with 14 additions and 0 deletions

View File

@@ -5,9 +5,13 @@ class UserRegistrationsController < Spree::UserRegistrationsController
before_filter :set_checkout_redirect, only: :create
include I18nHelper
before_filter :set_locale
# POST /resource/sign_up
def create
@user = build_resource(params[:spree_user])
@user.locale = I18n.locale.to_s
unless resource.save
return render_error(@user.errors)
end

View File

@@ -48,6 +48,16 @@ describe UserRegistrationsController, type: :controller do
expect(json).to eq({"email" => "test@test.com"})
expect(controller.spree_current_user).to be_nil
end
it "sets user.locale from cookie on create" do
original_locale_cookie = cookies[:locale]
cookies[:locale] = "pt"
xhr :post, :create, spree_user: user_params, use_route: :spree
expect(assigns[:user].locale).to eq("pt")
cookies[:locale] = original_locale_cookie
end
end
context "when registration fails" do