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.

Merge `Currency` and `Currencies` helper into one

Damian Legawiec6a48ca17ab08
diff --git a/admin/app/helpers/spree/admin/currencies_helper.rb b/admin/app/helpers/spree/admin/currencies_helper.rb
deleted file mode 100644
index 6ab4006342..0000000000
--- a/admin/app/helpers/spree/admin/currencies_helper.rb
+++ /dev/null
@@ -1,17 +0,0 @@
-module Spree
- module Admin
- module CurrenciesHelper
- def preferred_currencies
- @preferred_currencies ||= current_store.supported_currencies_list
- end
-
- def currency_money(currency = current_currency)
- ::Money::Currency.find(currency)
- end
-
- def currency_symbol(currency = current_currency)
- currency_money(currency).symbol
- end
- end
- end
-end
diff --git a/admin/spec/helpers/spree/admin/currencies_helper_spec.rb b/admin/spec/helpers/spree/admin/currencies_helper_spec.rb
deleted file mode 100644
index 3a127790ef..0000000000
--- a/admin/spec/helpers/spree/admin/currencies_helper_spec.rb
+++ /dev/null
@@ -1,39 +0,0 @@
-require 'spec_helper'
-
-RSpec.describe Spree::Admin::CurrenciesHelper, type: :helper do
- let(:store) { Spree::Store.default }
-
- before do
- allow(store).to receive(:supported_currencies).and_return('USD,EUR,GBP')
- allow(helper).to receive(:current_store).and_return(store)
- allow(helper).to receive(:current_currency).and_return('USD')
- end
-
- describe '#preferred_currencies' do
- it 'returns array of supported currencies from current store as `Money::Currency`' do
- expect(helper.preferred_currencies).to eq([Money::Currency.find('USD'), Money::Currency.find('EUR'), Money::Currency.find('GBP')])
- end
- end
-
- describe '#currency_money' do
- it 'returns Money::Currency instance for given currency' do
- expect(helper.currency_money('EUR')).to be_a(Money::Currency)
- expect(helper.currency_money('EUR').iso_code).to eq('EUR')
- end
-
- it 'uses current_currency when no argument is provided' do
- expect(helper.currency_money.iso_code).to eq('USD')
- end
- end
-
- describe '#currency_symbol' do
- it 'returns symbol for given currency' do
- expect(helper.currency_symbol('USD')).to eq('$')
- expect(helper.currency_symbol('EUR')).to eq('€')
- end
-
- it 'uses current_currency when no argument is provided' do
- expect(helper.currency_symbol).to eq('$')
- end
- end
-end
diff --git a/core/app/helpers/spree/currency_helper.rb b/core/app/helpers/spree/currency_helper.rb
index 2e354683ef..11365cc7ae 100644
--- a/core/app/helpers/spree/currency_helper.rb
+++ b/core/app/helpers/spree/currency_helper.rb
@@ -30,5 +30,13 @@ module Spree
[label, currency]
end
+
+ def preferred_currencies
+ @preferred_currencies ||= current_store.supported_currencies_list
+ end
+
+ def currency_money(currency = current_currency)
+ ::Money::Currency.find(currency)
+ end
end
end
diff --git a/core/spec/helpers/currency_helper_spec.rb b/core/spec/helpers/currency_helper_spec.rb
index 559391d16b..8fefafcbcd 100644
--- a/core/spec/helpers/currency_helper_spec.rb
+++ b/core/spec/helpers/currency_helper_spec.rb
@@ -3,6 +3,11 @@ require 'spec_helper'
describe Spree::CurrencyHelper, type: :helper do
let(:current_store) { create(:store, default_currency: 'EUR', supported_currencies: 'EUR,PLN,GBP') }
+ before do
+ allow(helper).to receive(:current_store).and_return(current_store)
+ allow(helper).to receive(:current_currency).and_return('USD')
+ end
+
describe '#supported_currency_options' do
it { expect(supported_currency_options).to contain_exactly(['zł PLN', 'PLN'], ['£ GBP', 'GBP'], ['€ EUR', 'EUR']) }
end
@@ -26,4 +31,21 @@ describe Spree::CurrencyHelper, type: :helper do
describe '#currency_presentation' do
it { expect(currency_presentation('EUR')).to eq(['€ EUR', 'EUR']) }
end
+
+ describe '#currency_money' do
+ it 'returns Money::Currency instance for given currency' do
+ expect(helper.currency_money('EUR')).to be_a(Money::Currency)
+ expect(helper.currency_money('EUR').iso_code).to eq('EUR')
+ end
+
+ it 'uses current_currency when no argument is provided' do
+ expect(helper.currency_money.iso_code).to eq('USD')
+ end
+ end
+
+ describe '#preferred_currencies' do
+ it 'returns array of supported currencies from current store as `Money::Currency`' do
+ expect(helper.preferred_currencies).to contain_exactly(Money::Currency.find('EUR'), Money::Currency.find('PLN'), Money::Currency.find('GBP'))
+ end
+ end
end