mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-28 01:53:25 +00:00
Use instance default locale as the default locale for a new user
This commit is contained in:
@@ -130,12 +130,12 @@ module Spree
|
||||
end
|
||||
|
||||
def build_resource
|
||||
model_class.new(locale: spree_current_user.locale)
|
||||
model_class.new(locale: I18n.default_locale)
|
||||
end
|
||||
|
||||
def user_params
|
||||
::PermittedAttributes::User.new(params).call(
|
||||
%i[enterprise_limit locale show_api_key_view]
|
||||
%i[enterprise_limit show_api_key_view]
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module I18nHelper
|
||||
def locales_available
|
||||
def locale_options
|
||||
OpenFoodNetwork::I18nConfig.available_locales.map do |locale|
|
||||
[t('language_name', locale:), locale]
|
||||
end
|
||||
|
||||
@@ -16,7 +16,7 @@ module PermittedAttributes
|
||||
|
||||
def permitted_attributes
|
||||
[
|
||||
:email, :password, :password_confirmation, :disabled,
|
||||
:email, :locale, :password, :password_confirmation, :disabled,
|
||||
{ webhook_endpoints_attributes: [:id, :url] },
|
||||
]
|
||||
end
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
= hidden_field_tag "user[spree_role_ids][]", ""
|
||||
= f.field_container :locale do
|
||||
= f.label :locale, t(".locale")
|
||||
= f.select :locale, locales_available, class: "fullwidth"
|
||||
= f.select :locale, locale_options, class: "fullwidth"
|
||||
= f.field_container :enterprise_limit do
|
||||
= f.label :enterprise_limit, t(".enterprise_limit")
|
||||
= f.text_field :enterprise_limit, class: "fullwidth"
|
||||
|
||||
@@ -85,7 +85,6 @@ describe Spree::UsersController, type: :controller do
|
||||
params: { user: { email: 'foobar@example.com', password: 'foobar123',
|
||||
password_confirmation: 'foobar123', locale: 'es' } }
|
||||
expect(assigns[:user].new_record?).to be_falsey
|
||||
expect(assigns[:user].reload.locale).to eq('es')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
module AuthenticationHelper
|
||||
include Warden::Test::Helpers
|
||||
|
||||
def login_as_admin(locale: :en)
|
||||
login_as create(:admin_user, locale:)
|
||||
def login_as_admin
|
||||
login_as create(:admin_user)
|
||||
end
|
||||
|
||||
def login_to_admin_section
|
||||
|
||||
@@ -131,72 +131,36 @@ describe "Managing users" do
|
||||
end
|
||||
|
||||
describe "creating a user" do
|
||||
let(:locale) { :en }
|
||||
|
||||
before do
|
||||
login_as_admin(locale:)
|
||||
end
|
||||
|
||||
it "shows no confirmation message to start with" do
|
||||
visit spree.new_admin_user_path
|
||||
expect(page).to have_no_text "Email confirmation is pending"
|
||||
end
|
||||
|
||||
context "when the current user locale is en" do
|
||||
let(:locale) { :en }
|
||||
it "uses the instance default locale for new new user" do
|
||||
visit spree.new_admin_user_path
|
||||
|
||||
it "uses the current user locale for new new user" do
|
||||
visit spree.new_admin_user_path
|
||||
|
||||
expect(page).to have_select('Language', selected: 'English')
|
||||
end
|
||||
|
||||
it "confirms successful creation" do
|
||||
visit spree.new_admin_user_path
|
||||
fill_in "Email", with: "user1@example.org"
|
||||
fill_in "Password", with: "user1Secret"
|
||||
fill_in "Confirm Password", with: "user1Secret"
|
||||
perform_enqueued_jobs do
|
||||
expect do
|
||||
click_button "Create"
|
||||
end.to change { Spree::User.count }.by 1
|
||||
expect(page).to have_text "Created Successfully"
|
||||
expect(page).to have_text "Email confirmation is pending"
|
||||
expect(Spree::User.last.locale).to eq "en"
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.subject).to match(
|
||||
"Please confirm your OFN account"
|
||||
)
|
||||
end
|
||||
end
|
||||
expect(page).to have_select('Language', selected: 'English')
|
||||
end
|
||||
|
||||
context "when the current user locale is es" do
|
||||
let(:locale) { :es }
|
||||
it "confirms successful creation" do
|
||||
visit spree.new_admin_user_path
|
||||
fill_in "Email", with: "user1@example.org"
|
||||
fill_in "Password", with: "user1Secret"
|
||||
fill_in "Confirm Password", with: "user1Secret"
|
||||
select "Español", from: "Language"
|
||||
|
||||
it "uses the current user locale for new new user" do
|
||||
visit spree.new_admin_user_path
|
||||
perform_enqueued_jobs do
|
||||
expect do
|
||||
click_button "Create"
|
||||
end.to change { Spree::User.count }.by 1
|
||||
expect(page).to have_text "Created Successfully"
|
||||
expect(page).to have_text "Email confirmation is pending"
|
||||
|
||||
expect(page).to have_select('Language', selected: 'Español')
|
||||
end
|
||||
expect(Spree::User.last.locale).to eq "es"
|
||||
|
||||
it "confirms successful creation" do
|
||||
visit spree.new_admin_user_path
|
||||
fill_in "Email", with: "user1@example.org"
|
||||
fill_in "Contraseña", with: "user1Secret"
|
||||
fill_in "Confirmar contraseña", with: "user1Secret"
|
||||
perform_enqueued_jobs do
|
||||
expect do
|
||||
click_button "Crear"
|
||||
end.to change { Spree::User.count }.by 1
|
||||
expect(page).to have_text "Creado con éxito"
|
||||
expect(page).to have_text "La confirmación por correo electrónico está pendiente"
|
||||
expect(Spree::User.last.locale).to eq "es"
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.subject).to match(
|
||||
"Por favor, confirma tu cuenta de OFN"
|
||||
)
|
||||
end
|
||||
expect(ActionMailer::Base.deliveries.first.subject).to match(
|
||||
"Por favor, confirma tu cuenta de OFN"
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user