Skip to content

Commit

Permalink
Merge pull request #6021 from Matt-Yorkley/concerns
Browse files Browse the repository at this point in the history
Move concern to concerns directory
  • Loading branch information
sauloperez committed Sep 15, 2020
2 parents 27ffe9e + 276fea6 commit 7006b0a
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 22 deletions.
19 changes: 19 additions & 0 deletions app/models/concerns/payment_method_distributors.rb
@@ -0,0 +1,19 @@
# frozen_string_literal: true

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
16 changes: 0 additions & 16 deletions app/models/spree/concerns/payment_method_distributors.rb

This file was deleted.

4 changes: 1 addition & 3 deletions 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

Expand Down
4 changes: 1 addition & 3 deletions 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
Expand Down

0 comments on commit 7006b0a

Please sign in to comment.