From 6686e519d44d5d51e196617cba8ff96a12478520 Mon Sep 17 00:00:00 2001 From: Zee Spencer <50284+zspencer@users.noreply.github.com> Date: Mon, 29 Jan 2024 15:34:50 -0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=A7=B9=20`Payout#destroy`=20destroys=20`#?= =?UTF-8?q?payments`?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While it may be better us to void a `Payout`, making sure we clean up any `Payout#payments` upon `Payout#destroy` should reduce the likelihood of data being in a sad place. --- app/furniture/tobias/payment.rb | 2 ++ app/furniture/tobias/payout.rb | 2 +- spec/tobias/payout_spec.rb | 6 +++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/app/furniture/tobias/payment.rb b/app/furniture/tobias/payment.rb index ef91a299b..34f5d7e2e 100644 --- a/app/furniture/tobias/payment.rb +++ b/app/furniture/tobias/payment.rb @@ -2,6 +2,8 @@ class Tobias class Payment < ApplicationRecord self.table_name = "tobias_payments" + belongs_to :payout + monetize :amount_cents end end diff --git a/app/furniture/tobias/payout.rb b/app/furniture/tobias/payout.rb index 1d37b0e28..d783afc94 100644 --- a/app/furniture/tobias/payout.rb +++ b/app/furniture/tobias/payout.rb @@ -4,7 +4,7 @@ class Payout < ApplicationRecord belongs_to :trust has_many :beneficiaries, through: :trust - has_many :payments + has_many :payments, inverse_of: :payout, dependent: :destroy monetize :amount_cents diff --git a/spec/tobias/payout_spec.rb b/spec/tobias/payout_spec.rb index 53556bfe7..0a9194d73 100644 --- a/spec/tobias/payout_spec.rb +++ b/spec/tobias/payout_spec.rb @@ -2,7 +2,11 @@ require_relative "factories/payout_factory" require_relative "factories/beneficiary_factory" -RSpec.describe Tobias::Payout do +RSpec.describe Tobias::Payout, type: :model do + describe "#payments" do + it { is_expected.to have_many(:payments).inverse_of(:payout).dependent(:destroy) } + end + describe "#issue" do it "issues a Payment to each Beneficiary for their share of the #amount" do payout = create(:tobias_payout, amount_cents: 150_00)