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
This commit is contained in:
Maikel Linke
2019-01-23 17:32:15 +11:00
parent b6ca0ba24f
commit 9044bf60b9
2 changed files with 37 additions and 0 deletions

View File

@@ -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"

View File

@@ -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