From dad287331462977d92d12a9bb8f675a3c1481db4 Mon Sep 17 00:00:00 2001 From: Eric Schultz Date: Wed, 10 Feb 2021 17:48:18 -0600 Subject: [PATCH] Move some common elements of TransactionAssignments to a single module --- app/models/campaign_gift_purchase.rb | 13 ++---------- app/models/concerns/model/trx_assignable.rb | 23 +++++++++++++++++++++ app/models/modern_donation.rb | 12 +---------- app/models/ticket_purchase.rb | 12 ++--------- 4 files changed, 28 insertions(+), 32 deletions(-) create mode 100644 app/models/concerns/model/trx_assignable.rb diff --git a/app/models/campaign_gift_purchase.rb b/app/models/campaign_gift_purchase.rb index 293971d2..336b7d74 100644 --- a/app/models/campaign_gift_purchase.rb +++ b/app/models/campaign_gift_purchase.rb @@ -3,23 +3,14 @@ # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE class CampaignGiftPurchase < ApplicationRecord - include Model::Houidable - include Model::Jbuilder - include Model::Eventable + include Model::TrxAssignable setup_houid :cgpur belongs_to :campaign has_many :campaign_gifts, class_name: 'ModernCampaignGift' - add_builder_expansion :nonprofit, :supporter, :campaign - add_builder_expansion :trx, - json_attrib: :transaction - - has_one :transaction_assignment, as: :assignable - has_one :trx, through: :transaction_assignment - has_one :supporter, through: :trx - has_one :nonprofit, through: :supporter + add_builder_expansion :campaign # TODO replace with Discard gem diff --git a/app/models/concerns/model/trx_assignable.rb b/app/models/concerns/model/trx_assignable.rb new file mode 100644 index 00000000..4e4761c6 --- /dev/null +++ b/app/models/concerns/model/trx_assignable.rb @@ -0,0 +1,23 @@ +# frozen_string_literal: true + +# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later +# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE +module Model::TrxAssignable + extend ActiveSupport::Concern + + included do + include Model::Houidable + include Model::Jbuilder + include Model::Eventable + + add_builder_expansion :nonprofit, :supporter + + add_builder_expansion :trx, + json_attrib: :transaction + + has_one :transaction_assignment, as: :assignable + has_one :trx, through: :transaction_assignment + has_one :supporter, through: :trx + has_one :nonprofit, through: :supporter + end +end \ No newline at end of file diff --git a/app/models/modern_donation.rb b/app/models/modern_donation.rb index afc0abf1..2a83aa29 100644 --- a/app/models/modern_donation.rb +++ b/app/models/modern_donation.rb @@ -3,20 +3,10 @@ # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE class ModernDonation < ApplicationRecord - include Model::Houidable - include Model::Jbuilder - include Model::Eventable + include Model::TrxAssignable setup_houid :don # TODO must associate with events and campaigns somehow - add_builder_expansion :nonprofit, :supporter - add_builder_expansion :trx, - json_attrib: :transaction - - has_one :transaction_assignment, as: :assignable - has_one :trx, through: :transaction_assignment - has_one :supporter, through: :trx - has_one :nonprofit, through: :supporter belongs_to :legacy_donation, class_name: 'Donation', foreign_key: :donation_id, inverse_of: :modern_donation delegate :designation, :dedication, to: :legacy_donation diff --git a/app/models/ticket_purchase.rb b/app/models/ticket_purchase.rb index 5a22125f..32466316 100644 --- a/app/models/ticket_purchase.rb +++ b/app/models/ticket_purchase.rb @@ -3,14 +3,10 @@ # License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later # Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE class TicketPurchase < ApplicationRecord - include Model::Houidable - include Model::Jbuilder - include Model::Eventable + include Model::TrxAssignable setup_houid :tktpur - add_builder_expansion :event, :nonprofit, :supporter - add_builder_expansion :trx, - json_attrib: :transaction + add_builder_expansion :event add_builder_expansion :event_discount, to_id: -> (model) { model.event_discount&.id }, @@ -20,10 +16,6 @@ class TicketPurchase < ApplicationRecord belongs_to :event_discount belongs_to :event - has_one :transaction_assignment, as: :assignable - has_one :trx, through: :transaction_assignment - has_one :supporter, through: :trx - has_one :nonprofit, through: :supporter has_many :ticket_to_legacy_tickets