Reset I18n.local for each spec

This avoids a locale setting leaking from one spec to another. It also
means that we don't have to reset the locale in individual specs.

Also:

- `cookies` is reset automatically and we don't need to do that.
- Removed some unused code (German number format and helper methods).
This commit is contained in:
Maikel Linke
2024-04-11 10:05:49 +10:00
parent b2172ef8d8
commit c2c7910357
5 changed files with 8 additions and 40 deletions

View File

@@ -96,6 +96,11 @@ RSpec.configure do |config|
expectations.syntax = :expect
end
# Reset locale for all specs.
config.around(:each) do |example|
I18n.with_locale(:en) { example.run }
end
# Reset all feature toggles to prevent leaking.
config.before(:suite) do
Flipper.features.each(&:remove)

View File

@@ -48,16 +48,9 @@ describe UserRegistrationsController, type: :controller do
end
it "sets user.locale from cookie on create" do
original_i18n_locale = I18n.locale
original_locale_cookie = cookies[:locale]
# changes to +I18n.locale+ will only persist within the +with_locale+ block
I18n.with_locale(original_i18n_locale) do
cookies[:locale] = "pt"
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
expect(assigns[:user].locale).to eq("pt")
cookies[:locale] = original_locale_cookie
end
cookies[:locale] = "pt"
post :create, xhr: true, params: { spree_user: user_params, use_route: :spree }
expect(assigns[:user].locale).to eq("pt")
end
end
end

View File

@@ -10,17 +10,6 @@ describe I18nHelper, type: :helper do
allow(helper).to receive(:cookies) { cookies }
end
# In the real world, the helper is called in every request and sets
# I18n.locale to the chosen locale or the default. For testing purposes we
# have to restore I18n.locale for unit tests that don't call the helper, but
# rely on translated strings.
around do |example|
original_locale = I18n.locale
I18n.with_locale(original_locale) do
example.run
end
end
context "as guest" do
before do
allow(helper).to receive(:spree_current_user) { nil }

View File

@@ -59,16 +59,6 @@ describe Spree::Variant do
end
context "price parsing" do
around(:each) do |spec|
default_locale = I18n.default_locale
I18n.with_locale(default_locale) do
I18n.backend.store_translations(:de,
{ number: { currency: { format: { delimiter: '.',
separator: ',' } } } })
spec.run
end
end
context "price=" do
context "with decimal point" do
it "captures the proper amount for a formatted price" do

View File

@@ -194,15 +194,6 @@ describe '
private
def wait_for_edit_form_to_load_order_cycle(order_cycle)
expect(page).to have_field "order_cycle_name", with: order_cycle.name
end
def select_incoming_variant(supplier, exchange_no, variant)
page.find("table.exchanges tr.supplier-#{supplier.id} td.products").click
check "order_cycle_incoming_exchange_#{exchange_no}_variants_#{variant.id}"
end
def date_warning_msg(nbr = 1)
"This order cycle is linked to %d open subscription orders. Changing this date now will not " \
"affect any orders which have already been placed, but should be avoided if possible. " \