From 9044bf60b95b851ae45ea546ca07bc5fed9ab35c Mon Sep 17 00:00:00 2001 From: Maikel Linke Date: Wed, 23 Jan 2019 17:32:15 +1100 Subject: [PATCH] Workaround Rails inheritance bug in Spree::Gateway Due to a bug in ActiveRecord we need to load the tagging code in Gateway which should have inherited it from its parent PaymentMethod. We have to call it before loading the PaymentMethod decorator because the tagging code won't load twice within the inheritance chain. https://github.com/openfoodfoundation/openfoodnetwork/issues/3121 --- config/initializers/spree.rb | 10 +++++++++ spec/models/spree/gateway_tagging_spec.rb | 27 +++++++++++++++++++++++ 2 files changed, 37 insertions(+) create mode 100644 spec/models/spree/gateway_tagging_spec.rb diff --git a/config/initializers/spree.rb b/config/initializers/spree.rb index a934679676..dca59d96a1 100644 --- a/config/initializers/spree.rb +++ b/config/initializers/spree.rb @@ -8,6 +8,16 @@ require 'spree/product_filters' +# Due to a bug in ActiveRecord we need to load the tagging code in Gateway which +# should have inherited it from its parent PaymentMethod. +# We have to call it before loading the PaymentMethod decorator because the +# tagging code won't load twice within the inheritance chain. +# https://github.com/openfoodfoundation/openfoodnetwork/issues/3121 +Spree::Gateway.class_eval do + acts_as_taggable + attr_accessible :tag_list +end + require "#{Rails.root}/app/models/spree/payment_method_decorator" require "#{Rails.root}/app/models/spree/gateway_decorator" diff --git a/spec/models/spree/gateway_tagging_spec.rb b/spec/models/spree/gateway_tagging_spec.rb new file mode 100644 index 0000000000..defda661bd --- /dev/null +++ b/spec/models/spree/gateway_tagging_spec.rb @@ -0,0 +1,27 @@ +require "spec_helper" + +# An inheritance bug made these specs fail. +# See config/initializers/spree.rb +shared_examples "taggable" do |parameter| + it "uses the given parameter" do + expect(subject.tag_list).to eq [] + end +end + +module Spree + describe PaymentMethod do + it_behaves_like "taggable" + end + + describe Gateway do + it_behaves_like "taggable" + end + + describe Gateway::PayPalExpress do + it_behaves_like "taggable" + end + + describe Gateway::StripeConnect do + it_behaves_like "taggable" + end +end