From 84c3b39e158f1ca824a61412c820020d7f66222b Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sat, 17 Jul 2021 16:38:42 -0700 Subject: [PATCH 1/4] use zeitwerk for autoloading --- app/models/spree/preferences/preferable.rb | 2 -- config/application.rb | 2 ++ 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/models/spree/preferences/preferable.rb b/app/models/spree/preferences/preferable.rb index dd8fc41120..b55b763ada 100644 --- a/app/models/spree/preferences/preferable.rb +++ b/app/models/spree/preferences/preferable.rb @@ -11,8 +11,6 @@ # and copy all the definitions allowing the subclass to add # additional defintions without affecting the base -require 'spree/preferences/store' - module Spree module Preferences module Preferable diff --git a/config/application.rb b/config/application.rb index c4f609a4a4..853a9cae9b 100644 --- a/config/application.rb +++ b/config/application.rb @@ -213,5 +213,7 @@ module Openfoodnetwork config.action_controller.include_all_helpers = false config.generators.template_engine = :haml + + config.autoloader = :zeitwerk end end From bb8dc3f3bcc52f7ac4869ac161f77856382f3ff9 Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Fri, 23 Jul 2021 17:01:22 -0700 Subject: [PATCH 2/4] add inflector for StripeSCA --- config/initializers/inflections.rb | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/config/initializers/inflections.rb b/config/initializers/inflections.rb index 9e8b0131f8..e630d3121e 100644 --- a/config/initializers/inflections.rb +++ b/config/initializers/inflections.rb @@ -8,3 +8,8 @@ # inflect.irregular 'person', 'people' # inflect.uncountable %w( fish sheep ) # end +Rails.autoloaders.each do |autoloader| + autoloader.inflector.inflect( + "stripe_sca" => "StripeSCA" + ) +end From afa3de80401a9c3cd80149e2bd7f154b1f1681af Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sat, 24 Jul 2021 08:24:39 -0700 Subject: [PATCH 3/4] load calculator classes on app reload --- config/application.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/config/application.rb b/config/application.rb index 853a9cae9b..97176f97fb 100644 --- a/config/application.rb +++ b/config/application.rb @@ -97,6 +97,17 @@ module Openfoodnetwork end # Register Spree calculators + Rails.application.reloader.to_prepare do + Openfoodnetwork::Application.config.spree.calculators.shipping_methods = [ + Calculator::FlatPercentItemTotal, + Calculator::FlatRate, + Calculator::FlexiRate, + Calculator::PerItem, + Calculator::PriceSack, + Calculator::Weight + ] + end + initializer 'spree.register.calculators' do |app| app.config.spree.calculators.shipping_methods = [ Calculator::FlatPercentItemTotal, From f2ec806d9c024013696142bf7042e8019e759eae Mon Sep 17 00:00:00 2001 From: Andy Brett Date: Sat, 24 Jul 2021 11:54:46 -0700 Subject: [PATCH 4/4] move all calculators to reload block --- config/application.rb | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/config/application.rb b/config/application.rb index 97176f97fb..8689fe592c 100644 --- a/config/application.rb +++ b/config/application.rb @@ -98,17 +98,7 @@ module Openfoodnetwork # Register Spree calculators Rails.application.reloader.to_prepare do - Openfoodnetwork::Application.config.spree.calculators.shipping_methods = [ - Calculator::FlatPercentItemTotal, - Calculator::FlatRate, - Calculator::FlexiRate, - Calculator::PerItem, - Calculator::PriceSack, - Calculator::Weight - ] - end - - initializer 'spree.register.calculators' do |app| + app = Openfoodnetwork::Application app.config.spree.calculators.shipping_methods = [ Calculator::FlatPercentItemTotal, Calculator::FlatRate, @@ -119,7 +109,7 @@ module Openfoodnetwork ] app.config.spree.calculators.add_class('enterprise_fees') - config.spree.calculators.enterprise_fees = [ + app.config.spree.calculators.enterprise_fees = [ Calculator::FlatPercentPerItem, Calculator::FlatRate, Calculator::FlexiRate, @@ -129,7 +119,7 @@ module Openfoodnetwork ] app.config.spree.calculators.add_class('payment_methods') - config.spree.calculators.payment_methods = [ + app.config.spree.calculators.payment_methods = [ Calculator::FlatPercentItemTotal, Calculator::FlatRate, Calculator::FlexiRate, @@ -138,7 +128,7 @@ module Openfoodnetwork ] app.config.spree.calculators.add_class('tax_rates') - config.spree.calculators.tax_rates = [ + app.config.spree.calculators.tax_rates = [ Calculator::DefaultTax ] end