From c45dcad975637f63b8b58dbc92f25a069101d646 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 14 Sep 2020 13:23:21 +0100 Subject: [PATCH 1/2] Move concern to concerns directory --- .../concerns/payment_method_distributors.rb | 14 ++++++++++++++ .../concerns/payment_method_distributors.rb | 16 ---------------- app/models/spree/gateway.rb | 4 +--- app/models/spree/payment_method.rb | 4 +--- 4 files changed, 16 insertions(+), 22 deletions(-) create mode 100644 app/models/concerns/payment_method_distributors.rb delete mode 100644 app/models/spree/concerns/payment_method_distributors.rb diff --git a/app/models/concerns/payment_method_distributors.rb b/app/models/concerns/payment_method_distributors.rb new file mode 100644 index 0000000000..3796066e0e --- /dev/null +++ b/app/models/concerns/payment_method_distributors.rb @@ -0,0 +1,14 @@ +require 'active_support/concern' + +# This concern is used to duplicate the associations distributors and distributor_ids +# across payment method and gateway +# this fixes the inheritance problem https://github.com/openfoodfoundation/openfoodnetwork/issues/2781 +module PaymentMethodDistributors + extend ActiveSupport::Concern + + def self.included(base) + base.class_eval do + has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', class_name: 'Enterprise', foreign_key: 'payment_method_id', association_foreign_key: 'distributor_id' + end + end +end diff --git a/app/models/spree/concerns/payment_method_distributors.rb b/app/models/spree/concerns/payment_method_distributors.rb deleted file mode 100644 index ce25c5d9b9..0000000000 --- a/app/models/spree/concerns/payment_method_distributors.rb +++ /dev/null @@ -1,16 +0,0 @@ -require 'active_support/concern' - -# This concern is used to duplicate the associations distributors and distributor_ids -# across payment method and gateway -# this fixes the inheritance problem https://github.com/openfoodfoundation/openfoodnetwork/issues/2781 -module Spree - module PaymentMethodDistributors - extend ActiveSupport::Concern - - def self.included(base) - base.class_eval do - has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', class_name: 'Enterprise', foreign_key: 'payment_method_id', association_foreign_key: 'distributor_id' - end - end - end -end diff --git a/app/models/spree/gateway.rb b/app/models/spree/gateway.rb index 216f0cfe6b..99d57826fb 100644 --- a/app/models/spree/gateway.rb +++ b/app/models/spree/gateway.rb @@ -1,10 +1,8 @@ # frozen_string_literal: true -require 'spree/concerns/payment_method_distributors' - module Spree class Gateway < PaymentMethod - include Spree::PaymentMethodDistributors + include PaymentMethodDistributors delegate_belongs_to :provider, :authorize, :purchase, :capture, :void, :credit diff --git a/app/models/spree/payment_method.rb b/app/models/spree/payment_method.rb index 39df36486d..9c41fbefa2 100644 --- a/app/models/spree/payment_method.rb +++ b/app/models/spree/payment_method.rb @@ -1,11 +1,9 @@ # frozen_string_literal: true -require 'spree/concerns/payment_method_distributors' - module Spree class PaymentMethod < ActiveRecord::Base include Spree::Core::CalculatedAdjustments - include Spree::PaymentMethodDistributors + include PaymentMethodDistributors acts_as_taggable acts_as_paranoid From 276fea69423e99312522781afc4265deb79792a3 Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Mon, 14 Sep 2020 15:14:16 +0100 Subject: [PATCH 2/2] Fix rubocop offenses --- app/models/concerns/payment_method_distributors.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/models/concerns/payment_method_distributors.rb b/app/models/concerns/payment_method_distributors.rb index 3796066e0e..d9ac7ccb68 100644 --- a/app/models/concerns/payment_method_distributors.rb +++ b/app/models/concerns/payment_method_distributors.rb @@ -1,3 +1,5 @@ +# frozen_string_literal: true + require 'active_support/concern' # This concern is used to duplicate the associations distributors and distributor_ids @@ -8,7 +10,10 @@ module PaymentMethodDistributors def self.included(base) base.class_eval do - has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', class_name: 'Enterprise', foreign_key: 'payment_method_id', association_foreign_key: 'distributor_id' + has_and_belongs_to_many :distributors, join_table: 'distributors_payment_methods', + class_name: 'Enterprise', + foreign_key: 'payment_method_id', + association_foreign_key: 'distributor_id' end end end