mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-02 21:57:17 +00:00
Merge pull request #13058 from mkllnk/currency-config
Remove unused app config options
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
module Spree
|
||||
module BaseHelper
|
||||
def available_countries
|
||||
checkout_zone = Zone.find_by(name: Spree::Config[:checkout_zone])
|
||||
checkout_zone = Zone.find_by(name: ENV.fetch("CHECKOUT_ZONE", nil))
|
||||
|
||||
countries = if checkout_zone && checkout_zone.kind == 'country'
|
||||
checkout_zone.countries
|
||||
|
||||
@@ -33,9 +33,6 @@ module Spree
|
||||
preference :allow_backorder_shipping, :boolean, default: false
|
||||
preference :allow_checkout_on_gateway_error, :boolean, default: false
|
||||
preference :allow_guest_checkout, :boolean, default: true
|
||||
# Replace with the name of a zone if you would like to limit the countries
|
||||
preference :checkout_zone, :string, default: nil
|
||||
preference :currency, :string, default: "USD"
|
||||
preference :currency_decimal_mark, :string, default: "."
|
||||
preference :currency_symbol_position, :string, default: "before"
|
||||
preference :currency_thousands_separator, :string, default: ","
|
||||
|
||||
@@ -81,23 +81,6 @@ module Openfoodnetwork
|
||||
]
|
||||
end
|
||||
|
||||
# Settings dependent on locale
|
||||
#
|
||||
# We need to set this config before the promo environment gets loaded and
|
||||
# after the spree environment gets loaded...
|
||||
# This is because Spree uses `Spree::Config` while evaluating classes :scream:
|
||||
#
|
||||
# https://github.com/spree/spree/blob/2-0-stable/core/app/models/spree/calculator/per_item.rb#L6
|
||||
#
|
||||
# TODO: move back to spree initializer once we upgrade to a more recent version
|
||||
# of Spree
|
||||
initializer 'ofn.spree_locale_settings', before: 'spree.promo.environment' do |app|
|
||||
Rails.application.reloader.to_prepare do
|
||||
Spree::Config['checkout_zone'] = ENV['CHECKOUT_ZONE']
|
||||
Spree::Config['currency'] = ENV['CURRENCY']
|
||||
end
|
||||
end
|
||||
|
||||
initializer "load_spree_calculators" do |app|
|
||||
# Register Spree calculators
|
||||
Rails.application.reloader.to_prepare do
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class DeleteCheckoutZoneAndCurrencyPreferences < ActiveRecord::Migration[7.0]
|
||||
def up
|
||||
execute <<~SQL
|
||||
DELETE FROM spree_preferences
|
||||
WHERE key IN (
|
||||
'/spree/app_configuration/checkout_zone',
|
||||
'/spree/app_configuration/currency'
|
||||
)
|
||||
SQL
|
||||
end
|
||||
end
|
||||
@@ -235,15 +235,11 @@ RSpec.configure do |config|
|
||||
end
|
||||
|
||||
default_country_id = DefaultCountry.id
|
||||
checkout_zone = Spree::Config[:checkout_zone]
|
||||
currency = Spree::Config[:currency]
|
||||
# Ensure we start with consistent config settings
|
||||
config.before(:each) do
|
||||
reset_spree_preferences do |spree_config|
|
||||
# These are all settings that differ from Spree's defaults
|
||||
spree_config.default_country_id = default_country_id
|
||||
spree_config.checkout_zone = checkout_zone
|
||||
spree_config.currency = currency
|
||||
spree_config.shipping_instructions = true
|
||||
end
|
||||
CurrentConfig.clear_all
|
||||
|
||||
@@ -10,11 +10,12 @@ RSpec.describe Spree::BaseHelper do
|
||||
|
||||
before do
|
||||
3.times { create(:country) }
|
||||
allow(ENV).to receive(:fetch).and_call_original
|
||||
end
|
||||
|
||||
context "with no checkout zone defined" do
|
||||
before do
|
||||
Spree::Config[:checkout_zone] = nil
|
||||
allow(ENV).to receive(:fetch).and_return(nil)
|
||||
end
|
||||
|
||||
it "return complete list of countries" do
|
||||
@@ -27,7 +28,7 @@ RSpec.describe Spree::BaseHelper do
|
||||
before do
|
||||
@country_zone = create(:zone, name: "CountryZone")
|
||||
@country_zone.members.create(zoneable: country)
|
||||
Spree::Config[:checkout_zone] = @country_zone.name
|
||||
allow(ENV).to receive(:fetch).and_return(@country_zone.name)
|
||||
end
|
||||
|
||||
it "return only the countries defined by the checkout zone" do
|
||||
@@ -40,7 +41,7 @@ RSpec.describe Spree::BaseHelper do
|
||||
state_zone = create(:zone, name: "StateZone")
|
||||
state = create(:state, country:)
|
||||
state_zone.members.create(zoneable: state)
|
||||
Spree::Config[:checkout_zone] = state_zone.name
|
||||
allow(ENV).to receive(:fetch).and_return(state_zone.name)
|
||||
end
|
||||
|
||||
it "return complete list of countries" do
|
||||
|
||||
@@ -7,7 +7,6 @@ RSpec.describe Spree::Money do
|
||||
|
||||
before do
|
||||
configure_spree_preferences do |config|
|
||||
config.currency = "USD"
|
||||
config.currency_symbol_position = :before
|
||||
config.display_currency = false
|
||||
end
|
||||
@@ -97,7 +96,6 @@ RSpec.describe Spree::Money do
|
||||
context "EUR" do
|
||||
before do
|
||||
configure_spree_preferences do |config|
|
||||
config.currency = "EUR"
|
||||
config.currency_symbol_position = :after
|
||||
config.display_currency = false
|
||||
end
|
||||
|
||||
@@ -133,7 +133,7 @@ module Spree
|
||||
before { Spree::Config[:display_currency] = true }
|
||||
|
||||
it "shows the currency" do
|
||||
expect(adjustment.display_amount.to_s).to eq "$10.55 #{Spree::Config[:currency]}"
|
||||
expect(adjustment.display_amount.to_s).to eq "$10.55 AUD"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -167,7 +167,7 @@ module Spree
|
||||
|
||||
context '#currency' do
|
||||
it 'returns the globally configured currency' do
|
||||
expect(adjustment.currency).to eq Spree::Config[:currency]
|
||||
expect(adjustment.currency).to eq "AUD"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -516,7 +516,7 @@ RSpec.describe Spree::Order do
|
||||
before { order.currency = nil }
|
||||
|
||||
it "returns the globally configured currency" do
|
||||
expect(order.currency).to eq Spree::Config[:currency]
|
||||
expect(order.currency).to eq "AUD"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -292,7 +292,7 @@ RSpec.describe Spree::Variant do
|
||||
context "#currency" do
|
||||
it "returns the globally configured currency" do
|
||||
variant.save!
|
||||
expect(variant.currency).to eq Spree::Config[:currency]
|
||||
expect(variant.currency).to eq "AUD"
|
||||
end
|
||||
end
|
||||
|
||||
@@ -309,7 +309,7 @@ RSpec.describe Spree::Variant do
|
||||
|
||||
it "populates cost currency with the default value on save" do
|
||||
variant.save!
|
||||
expect(variant.cost_currency).to eq Spree::Config[:currency]
|
||||
expect(variant.cost_currency).to eq "AUD"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -737,7 +737,7 @@ RSpec.describe '
|
||||
sku,
|
||||
description,
|
||||
quantity,
|
||||
amount.to_s, '', opts[:account_code], tax_type, '', '', '', '', Spree::Config.currency,
|
||||
amount.to_s, '', opts[:account_code], tax_type, '', '', '', '', "AUD",
|
||||
'', 'N']
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user