Skip to content

Commit

Permalink
🧹 Payout#destroy destroys #payments
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
zspencer committed Jan 29, 2024
1 parent 63f8184 commit 6686e51
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
2 changes: 2 additions & 0 deletions app/furniture/tobias/payment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ class Tobias
class Payment < ApplicationRecord
self.table_name = "tobias_payments"

belongs_to :payout

monetize :amount_cents
end
end
2 changes: 1 addition & 1 deletion app/furniture/tobias/payout.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion spec/tobias/payout_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 6686e51

Please sign in to comment.