From a0b740f52df995f9da8d60df99fcab363e0486e8 Mon Sep 17 00:00:00 2001 From: Rohan Mitchell Date: Fri, 20 May 2016 11:01:54 +1000 Subject: [PATCH] Generalise fix for missing EnterpriseFee::Calculator to any use of calculated_adjustments --- app/models/enterprise_fee.rb | 3 --- config/initializers/spree.rb | 1 + lib/spree/core/calculated_adjustments_decorator.rb | 14 ++++++++++++++ .../enterprise_fee_applicator_spec.rb | 1 + 4 files changed, 16 insertions(+), 3 deletions(-) create mode 100644 lib/spree/core/calculated_adjustments_decorator.rb diff --git a/app/models/enterprise_fee.rb b/app/models/enterprise_fee.rb index 0fc44ac496..ff118cf0aa 100644 --- a/app/models/enterprise_fee.rb +++ b/app/models/enterprise_fee.rb @@ -16,9 +16,6 @@ class EnterpriseFee < ActiveRecord::Base calculated_adjustments - # Class name is mis-inferred outside of Spree namespace - has_one :calculator, as: :calculable, dependent: :destroy, class_name: 'Spree::Calculator' - attr_accessible :enterprise_id, :fee_type, :name, :tax_category_id, :calculator_type, :inherits_tax_category diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index 30182ef63a..f439e779cf 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -8,6 +8,7 @@ require 'spree/product_filters' +require 'spree/core/calculated_adjustments_decorator' require "#{Rails.root}/app/models/spree/payment_method_decorator" require "#{Rails.root}/app/models/spree/gateway_decorator" diff --git a/lib/spree/core/calculated_adjustments_decorator.rb b/lib/spree/core/calculated_adjustments_decorator.rb new file mode 100644 index 0000000000..6a42eb68c5 --- /dev/null +++ b/lib/spree/core/calculated_adjustments_decorator.rb @@ -0,0 +1,14 @@ +module Spree + module Core + module CalculatedAdjustments + module ClassMethods + def calculated_adjustments_with_explicit_class_name + calculated_adjustments_without_explicit_class_name + # Class name is mis-inferred outside of Spree namespace + has_one :calculator, as: :calculable, dependent: :destroy, class_name: 'Spree::Calculator' + end + alias_method_chain :calculated_adjustments, :explicit_class_name + end + end + end +end diff --git a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb index 9ad1d222b3..b1a9074efb 100644 --- a/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb +++ b/spec/lib/open_food_network/enterprise_fee_applicator_spec.rb @@ -1,3 +1,4 @@ +require 'spec_helper' require 'open_food_network/enterprise_fee_applicator' module OpenFoodNetwork