From 8aefa92730dc360ee52bd897e82a1d0406731ce8 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 29 Jan 2024 16:03:59 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A5=97=F0=9F=A7=B9=20`Tobias`:=20`Benefic?= =?UTF-8?q?iary`=20has=20defined=20associations?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/furniture/tobias/beneficiary.rb | 5 +++-- app/furniture/tobias/payment.rb | 1 + spec/tobias/beneficiary_spec.rb | 15 +++++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) create mode 100644 spec/tobias/beneficiary_spec.rb 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