Skip to content

Commit

Permalink
🥗🧹 Tobias: Beneficiary has defined associations
Browse files Browse the repository at this point in the history
  • Loading branch information
zspencer committed Feb 12, 2024
1 parent 845e0b0 commit cbe27e2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
5 changes: 3 additions & 2 deletions app/furniture/tobias/beneficiary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@ class Tobias
class Beneficiary < ApplicationRecord
self.table_name = "tobias_beneficiaries"

belongs_to :trust
belongs_to :trust, inverse_of: :beneficiaries

has_many :payments
has_many :payments, inverse_of: :beneficiary
has_many :payouts, through: :payments
end
end
1 change: 1 addition & 0 deletions app/furniture/tobias/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ class Payment < ApplicationRecord
self.table_name = "tobias_payments"

belongs_to :payout, inverse_of: :payments
belongs_to :beneficiary, inverse_of: :payments

monetize :amount_cents
end
Expand Down
15 changes: 15 additions & 0 deletions spec/tobias/beneficiary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
require "rails_helper"

RSpec.describe Tobias::Beneficiary, type: :model do
describe "#trust" do
it { is_expected.to belong_to(:trust).inverse_of(:beneficiaries) }
end

describe "#payments" do
it { is_expected.to have_many(:payments).inverse_of(:beneficiary) }
end

describe "#payouts" do
it { is_expected.to have_many(:payouts).through(:payments) }
end
end

0 comments on commit cbe27e2

Please sign in to comment.