mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user