From 5e960512aceedd443c6b299cd6037e4da585e537 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Tue, 18 Dec 2018 15:29:50 +0000 Subject: [PATCH] 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. --- app/controllers/user_registrations_controller.rb | 4 ++++ spec/controllers/user_registrations_controller_spec.rb | 10 ++++++++++ 2 files changed, 14 insertions(+) diff --git a/app/controllers/user_registrations_controller.rb b/app/controllers/user_registrations_controller.rb index cb7cb61684..e8e75dc5ee 100644 --- a/app/controllers/user_registrations_controller.rb +++ b/app/controllers/user_registrations_controller.rb @@ -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 diff --git a/spec/controllers/user_registrations_controller_spec.rb b/spec/controllers/user_registrations_controller_spec.rb index 7ed7951c50..22d14b383f 100644 --- a/spec/controllers/user_registrations_controller_spec.rb +++ b/spec/controllers/user_registrations_controller_spec.rb @@ -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