Skip to content

armgit / spree

Public Imported from GitHub
0

Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.

Additional tests

Damian Legawiec3b5395412639
diff --git a/backend/app/controllers/spree/admin/stores_controller.rb b/backend/app/controllers/spree/admin/stores_controller.rb
index 2d1bc754c0..b0e2916df1 100644
--- a/backend/app/controllers/spree/admin/stores_controller.rb
+++ b/backend/app/controllers/spree/admin/stores_controller.rb
@@ -5,6 +5,7 @@ module Spree
before_action :set_default_currency, only: :new
before_action :set_default_locale, only: :new
before_action :normalize_supported_currencies, only: [:create, :update]
+ before_action :normalize_supported_locales, only: [:create, :update]
before_action :set_default_country_id, only: :new
before_action :load_all_countries, only: [:new, :edit, :update, :create]
before_action :load_all_zones, only: %i[new edit]
@@ -127,6 +128,12 @@ module Spree
end
end
+ def normalize_supported_locales
+ if params[:store][:supported_locales]&.is_a?(Array)
+ params[:store][:supported_locales] = params[:store][:supported_locales].compact.uniq.reject(&:blank?).join(',')
+ end
+ end
+
def set_default_country_id
@store.default_country_id = Spree::Config[:default_country_id]
end
diff --git a/backend/spec/features/admin/configuration/stores_spec.rb b/backend/spec/features/admin/configuration/stores_spec.rb
index 3089eb4c0a..8215b6301f 100644
--- a/backend/spec/features/admin/configuration/stores_spec.rb
+++ b/backend/spec/features/admin/configuration/stores_spec.rb
@@ -8,6 +8,15 @@ describe 'Stores admin', type: :feature, js: true do
let!(:no_limits) { create(:zone, name: 'No Limits') }
describe 'visiting the stores page' do
+ before do
+ store.update(
+ name: 'My Store',
+ url: 'example.com',
+ supported_currencies: 'USD,EUR',
+ supported_locales: 'fr,de'
+ )
+ end
+
it 'is on the stores page' do
visit spree.admin_stores_path
@@ -15,8 +24,10 @@ describe 'Stores admin', type: :feature, js: true do
row_count = store_table.all(:css, 'tr').size
expect(row_count).to eq 2
expect(Spree::Store.count).to eq 1
- expect(store_table).to have_content(store.name)
- expect(store_table).to have_content(store.url)
+ expect(store_table).to have_content('My Store')
+ expect(store_table).to have_content('example.com')
+ expect(store_table).to have_content('USD, EUR')
+ expect(store_table).to have_content('fr, de')
end
end
@@ -73,14 +84,27 @@ describe 'Stores admin', type: :feature, js: true do
page.fill_in 'store_code', with: 'spree'
page.fill_in 'store_mail_from_address', with: '[email protected]'
page.fill_in 'store_customer_support_email', with: '[email protected]'
- select2 'EUR', from: 'Currency'
+ select2 'EUR', from: 'Default currency'
+ select2_clear from: 'Supported Currencies'
+ select2_search 'GBP', from: 'Supported Currencies'
+ select2_select 'GBP', from: 'Supported Currencies'
+
+ select2 'English (US)', from: 'Default locale'
+
click_button 'Create'
expect(page).to have_current_path spree.admin_stores_path
+ expect(page).to have_content('successfully created!')
row_count = page.all(:css, 'table tr').size
expect(row_count).to eq 3
expect(Spree::Store.count).to eq 2
+
+ store = Spree::Store.last
+
+ expect(store.default_currency).to eq 'EUR'
+ expect(store.supported_currencies_list.map(&:iso_code)).to contain_exactly('EUR', 'GBP')
+ expect(store.default_locale).to eq 'en'
end
end
@@ -95,7 +119,7 @@ describe 'Stores admin', type: :feature, js: true do
click_icon :edit
end
page.fill_in 'store_name', with: updated_name
- select2 new_currency, from: 'Currency'
+ select2 new_currency, from: 'Default currency'
click_button 'Update'
expect(page).to have_current_path spree.admin_stores_path
diff --git a/core/spec/lib/spree/core/controller_helpers/locale_spec.rb b/core/spec/lib/spree/core/controller_helpers/locale_spec.rb
index c3a1f5236f..db89c30c2e 100644
--- a/core/spec/lib/spree/core/controller_helpers/locale_spec.rb
+++ b/core/spec/lib/spree/core/controller_helpers/locale_spec.rb
@@ -17,12 +17,17 @@ describe Spree::Core::ControllerHelpers::Locale, type: :controller do
controller(FakesController) {}
describe '#current_locale' do
- context 'store with local set' do
- let!(:store) { create :store, default: true, default_locale: 'fr' }
+ context 'store with locale set' do
+ let!(:store) { create :store, default: true, default_locale: 'fr', supported_locales: 'fr,de' }
it 'returns current store default locale' do
expect(controller.current_locale.to_s).to eq('fr')
end
+
+ it 'return supported locale when passed as param' do
+ controller.params = { locale: 'de' }
+ expect(controller.current_locale.to_s).to eq('de')
+ end
end
context 'config_locale present' do