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.

Added missing LocaleHelper specs

Damian Legawiecdb274968a147
diff --git a/core/app/helpers/spree/locale_helper.rb b/core/app/helpers/spree/locale_helper.rb
index 5e8c589e31..7f3e083470 100644
--- a/core/app/helpers/spree/locale_helper.rb
+++ b/core/app/helpers/spree/locale_helper.rb
@@ -16,9 +16,9 @@ module Spree
def locale_presentation(locale)
if I18n.exists?('spree.i18n.this_file_language', locale: locale)
- [Spree.t('i18n.this_file_language', locale: locale), locale]
+ [Spree.t('i18n.this_file_language', locale: locale), locale.to_s]
else
- locale.to_s == 'en' ? ['English (US)', :en] : [locale, locale]
+ locale.to_s == 'en' ? ['English (US)', 'en'] : [locale, locale.to_s]
end
end
end
diff --git a/core/spec/helpers/locale_helper_spec.rb b/core/spec/helpers/locale_helper_spec.rb
new file mode 100644
index 0000000000..d3d5ad7247
--- /dev/null
+++ b/core/spec/helpers/locale_helper_spec.rb
@@ -0,0 +1,46 @@
+require 'spec_helper'
+
+describe Spree::LocaleHelper, type: :helper do
+ let(:germany) { create(:country, name: 'Germany', iso: 'GR') }
+ let(:eu_store) { create(:store, default_currency: 'EUR', default_locale: 'de', default_country: germany, supported_locales: 'fr,de') }
+ let(:available_locales) { Spree::Store.available_locales }
+ let(:supported_locales_for_all_stores) { [:en, :de, :fr] }
+
+ before do
+ I18n.backend.store_translations(:de,
+ spree: {
+ i18n: {
+ this_file_language: 'Deutsch (DE)'
+ }
+ })
+ I18n.backend.store_translations(:fr,
+ spree: {
+ i18n: {
+ this_file_language: 'Français (FR)'
+ }
+ })
+ end
+
+ describe '#all_locales_options' do
+ it { expect(all_locales_options).to contain_exactly(['English (US)', 'en'], ['Deutsch (DE)', 'de'], ['Français (FR)', 'fr']) }
+ end
+
+ describe '#available_locales_options' do
+ before do
+ create(:store, supported_locales: 'en,de')
+ create(:store, supported_locales: 'en')
+ end
+
+ it { expect(available_locales_options).to contain_exactly(['English (US)', 'en'], ['Deutsch (DE)', 'de']) }
+ end
+
+ describe '#supported_locales_options' do
+ let(:current_store) { eu_store }
+
+ it { expect(supported_locales_options).to contain_exactly(['Deutsch (DE)', 'de'], ['Français (FR)', 'fr']) }
+ end
+
+ describe '#locale_presentation' do
+ it { expect(locale_presentation(:fr)).to eq( ['Français (FR)', 'fr']) }
+ end
+end