diff --git a/app/furniture/tobias/beneficiary.rb b/app/furniture/tobias/beneficiary.rb index 44f7a35c3..7477ba219 100644 --- a/app/furniture/tobias/beneficiary.rb +++ b/app/furniture/tobias/beneficiary.rb @@ -1,5 +1,5 @@ class Tobias - class Beneficiary < Record + class Beneficiary < ApplicationRecord self.table_name = "tobias_beneficiaries" belongs_to :trust diff --git a/app/furniture/tobias/payment.rb b/app/furniture/tobias/payment.rb index db0b0d18b..ef91a299b 100644 --- a/app/furniture/tobias/payment.rb +++ b/app/furniture/tobias/payment.rb @@ -1,5 +1,5 @@ class Tobias - class Payment < Record + class Payment < ApplicationRecord self.table_name = "tobias_payments" monetize :amount_cents diff --git a/app/furniture/tobias/payout.rb b/app/furniture/tobias/payout.rb index d37aff9fd..1d37b0e28 100644 --- a/app/furniture/tobias/payout.rb +++ b/app/furniture/tobias/payout.rb @@ -6,12 +6,11 @@ class Payout < ApplicationRecord has_many :beneficiaries, through: :trust has_many :payments - monetize :payout_amount_cents + monetize :amount_cents def issue - per_beneficiary_amount = (payout_amount / beneficiaries.count) + per_beneficiary_amount = (amount / beneficiaries.count) beneficiaries.each do |beneficiary| - payments.create_with(amount: per_beneficiary_amount).find_or_create_by(beneficiary_id: beneficiary.id) end end diff --git a/app/furniture/tobias/record.rb b/app/furniture/tobias/record.rb deleted file mode 100644 index 6763703c1..000000000 --- a/app/furniture/tobias/record.rb +++ /dev/null @@ -1,9 +0,0 @@ -class Tobias - class Record < ApplicationRecord - self.abstract_class = true - - def self.model_name - @_model_name ||= ActiveModel::Name.new(self, ::Tobias) - end - end -end diff --git a/app/furniture/tobias/trust.rb b/app/furniture/tobias/trust.rb index 74d13943a..f4cd46e7b 100644 --- a/app/furniture/tobias/trust.rb +++ b/app/furniture/tobias/trust.rb @@ -1,8 +1,7 @@ class Tobias - class Trust < Record + class Trust < ApplicationRecord self.table_name = "tobias_trusts" has_many :beneficiaries - end end diff --git a/db/migrate/20240127063826_create_tobias_payouts.rb b/db/migrate/20240127063826_create_tobias_payouts.rb index 9ae921836..ad6eadffb 100644 --- a/db/migrate/20240127063826_create_tobias_payouts.rb +++ b/db/migrate/20240127063826_create_tobias_payouts.rb @@ -11,7 +11,7 @@ def change end create_table :tobias_payouts, id: :uuid do |t| - t.monetize :payout_amount + t.monetize :amount t.references :trust, type: :uuid, foreign_key: {to_table: :tobias_trusts} t.timestamps end diff --git a/db/schema.rb b/db/schema.rb index 6fd3e0a13..8be628a4b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -314,8 +314,8 @@ end create_table "tobias_payouts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.integer "payout_amount_cents", default: 0, null: false - t.string "payout_amount_currency", default: "USD", null: false + t.integer "amount_cents", default: 0, null: false + t.string "amount_currency", default: "USD", null: false t.uuid "trust_id" t.datetime "created_at", null: false t.datetime "updated_at", null: false diff --git a/spec/tobias/factories/beneficiary_factory.rb b/spec/tobias/factories/beneficiary_factory.rb index b1206ba10..b330f1abb 100644 --- a/spec/tobias/factories/beneficiary_factory.rb +++ b/spec/tobias/factories/beneficiary_factory.rb @@ -1,5 +1,4 @@ FactoryBot.define do factory :tobias_beneficiary, class: "Tobias::Beneficiary" do - end end diff --git a/spec/tobias/factories/trust_factory.rb b/spec/tobias/factories/trust_factory.rb index 4c1892065..7fd94abab 100644 --- a/spec/tobias/factories/trust_factory.rb +++ b/spec/tobias/factories/trust_factory.rb @@ -1,5 +1,4 @@ FactoryBot.define do factory :tobias_trust, class: "Tobias::Trust" do - end end diff --git a/spec/tobias/payout_spec.rb b/spec/tobias/payout_spec.rb index ee3e52181..afcbc3ee1 100644 --- a/spec/tobias/payout_spec.rb +++ b/spec/tobias/payout_spec.rb @@ -4,8 +4,8 @@ RSpec.describe Tobias::Payout do describe "#issue" do - it "issues a Payment to each Beneficiary for their share of the #payout_amount" do - payout = create(:tobias_payout, payout_amount_cents: 150_00) + it "issues a Payment to each Beneficiary for their share of the #amount" do + payout = create(:tobias_payout, amount_cents: 150_00) beneficiaries = create_list(:tobias_beneficiary, 10, trust: payout.trust)