forked from zinc-collective/convene
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨
Payout#issue
creates Payment
for Trust#beneficiaries
This sketches in the `Payout#issue` method's line-of-action, which is to iterate through the `Payout#trust#beneficiaries` and add a `Payment` to the set of `Payout#payments` for the per-beneficiary amount. That said, there's a few outstanding questions we'll probably want to add some tests to interrogate, especially around: 1. What happens if the method is ran twice with the same data? 2. What about if the set of `Payout#trust#beneficiaries` is changed between calls to `Payout#issue`? 3. What happens when the `Payout#payout_amount` doesn't divide evenly between the `Payout#beneficiaries?
- Loading branch information
Showing
12 changed files
with
139 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
class Tobias | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Tobias | ||
class Beneficiary < Record | ||
self.table_name = "tobias_beneficiaries" | ||
|
||
belongs_to :trust | ||
|
||
has_many :payments | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Tobias | ||
class Payment < Record | ||
self.table_name = "tobias_payments" | ||
|
||
monetize :amount_cents | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
class Tobias | ||
class Payout < ApplicationRecord | ||
self.table_name = "tobias_payouts" | ||
|
||
belongs_to :trust | ||
has_many :beneficiaries, through: :trust | ||
has_many :payments | ||
|
||
monetize :payout_amount_cents | ||
|
||
def issue | ||
per_beneficiary_amount = (payout_amount / beneficiaries.count) | ||
beneficiaries.each do |beneficiary| | ||
|
||
payments.create_with(amount: per_beneficiary_amount).find_or_create_by(beneficiary_id: beneficiary.id) | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
class Tobias | ||
class Record < ApplicationRecord | ||
self.abstract_class = true | ||
|
||
def self.model_name | ||
@_model_name ||= ActiveModel::Name.new(self, ::Tobias) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class Tobias | ||
class Trust < Record | ||
self.table_name = "tobias_trusts" | ||
|
||
has_many :beneficiaries | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
class CreateTobiasPayouts < ActiveRecord::Migration[7.1] | ||
def change | ||
create_table :tobias_trusts, id: :uuid do |t| | ||
t.timestamps | ||
end | ||
|
||
create_table :tobias_beneficiaries, id: :uuid do |t| | ||
t.references :trust, type: :uuid, foreign_key: {to_table: :tobias_trusts} | ||
|
||
t.timestamps | ||
end | ||
|
||
create_table :tobias_payouts, id: :uuid do |t| | ||
t.monetize :payout_amount | ||
t.references :trust, type: :uuid, foreign_key: {to_table: :tobias_trusts} | ||
t.timestamps | ||
end | ||
|
||
create_table :tobias_payments, id: :uuid do |t| | ||
t.references :payout, type: :uuid, foreign_key: {to_table: :tobias_payouts} | ||
t.references :beneficiary, type: :uuid, foreign_key: {to_table: :tobias_beneficiaries} | ||
t.monetize :amount | ||
|
||
t.timestamps | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :tobias_beneficiary, class: "Tobias::Beneficiary" do | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
require_relative "trust_factory" | ||
|
||
FactoryBot.define do | ||
factory :tobias_payout, class: "Tobias::Payout" do | ||
association(:trust, factory: :tobias_trust) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
FactoryBot.define do | ||
factory :tobias_trust, class: "Tobias::Trust" do | ||
|
||
end | ||
end |
6 changes: 4 additions & 2 deletions
6
spec/furniture/tobias/payout_spec.rb → spec/tobias/payout_spec.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters