diff --git a/app/furniture/tobias/beneficiary.rb b/app/furniture/tobias/beneficiary.rb index 7477ba219..422e4a7fd 100644 --- a/app/furniture/tobias/beneficiary.rb +++ b/app/furniture/tobias/beneficiary.rb @@ -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 diff --git a/app/furniture/tobias/payment.rb b/app/furniture/tobias/payment.rb index ddd1f0778..394c759c0 100644 --- a/app/furniture/tobias/payment.rb +++ b/app/furniture/tobias/payment.rb @@ -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 diff --git a/spec/tobias/beneficiary_spec.rb b/spec/tobias/beneficiary_spec.rb new file mode 100644 index 000000000..1bb9a325a --- /dev/null +++ b/spec/tobias/beneficiary_spec.rb @@ -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