The personal finance app for everyone
Rework Account to use delegated types
Rob Zolkos71939d6fb597
diff --git a/app/models/account.rb b/app/models/account.rbindex 0c34c0b3..e5cecf44 100644--- a/app/models/account.rb+++ b/app/models/account.rb@@ -3,5 +3,7 @@ class Account < ApplicationRecordbelongs_to :family+ delegated_type :accountable, types: %w[ Credit Depository Investment Loan OtherAsset OtherLiability Property Vehicle]+scope :depository, -> { where(type: "Depository") }enddiff --git a/app/models/account/credit.rb b/app/models/account/credit.rbnew file mode 100644index 00000000..06e91afc--- /dev/null+++ b/app/models/account/credit.rb@@ -0,0 +1,3 @@+class Account::Credit < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/depository.rb b/app/models/account/depository.rbnew file mode 100644index 00000000..b7d4cb30--- /dev/null+++ b/app/models/account/depository.rb@@ -0,0 +1,3 @@+class Account::Depository < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/investment.rb b/app/models/account/investment.rbnew file mode 100644index 00000000..57bdfcf8--- /dev/null+++ b/app/models/account/investment.rb@@ -0,0 +1,3 @@+class Account::Investment < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/loan.rb b/app/models/account/loan.rbnew file mode 100644index 00000000..71c72d92--- /dev/null+++ b/app/models/account/loan.rb@@ -0,0 +1,3 @@+class Account::Loan < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/other_asset.rb b/app/models/account/other_asset.rbnew file mode 100644index 00000000..b4f638da--- /dev/null+++ b/app/models/account/other_asset.rb@@ -0,0 +1,3 @@+class Account::OtherAsset < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/other_liability.rb b/app/models/account/other_liability.rbnew file mode 100644index 00000000..2467c08d--- /dev/null+++ b/app/models/account/other_liability.rb@@ -0,0 +1,3 @@+class Account::OtherLiability < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/property.rb b/app/models/account/property.rbnew file mode 100644index 00000000..0088dfcd--- /dev/null+++ b/app/models/account/property.rb@@ -0,0 +1,3 @@+class Account::Property < ApplicationRecord+ include Accountable+enddiff --git a/app/models/account/vehicle.rb b/app/models/account/vehicle.rbnew file mode 100644index 00000000..fd640f2a--- /dev/null+++ b/app/models/account/vehicle.rb@@ -0,0 +1,3 @@+class Account::Vehicle < ApplicationRecord+ include Accountable+enddiff --git a/app/models/concerns/accountable.rb b/app/models/concerns/accountable.rbnew file mode 100644index 00000000..11ec8f24--- /dev/null+++ b/app/models/concerns/accountable.rb@@ -0,0 +1,7 @@+module Accountable+ extend ActiveSupport::Concern++ included do+ has_one :account, as: :accountable, touch: true+ end+enddiff --git a/db/migrate/20240202191425_create_account_loans.rb b/db/migrate/20240202191425_create_account_loans.rbnew file mode 100644index 00000000..6f2cc760--- /dev/null+++ b/db/migrate/20240202191425_create_account_loans.rb@@ -0,0 +1,7 @@+class CreateAccountLoans < ActiveRecord::Migration[7.2]+ def change+ create_table :account_loans, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202191746_add_accountable_to_account.rb b/db/migrate/20240202191746_add_accountable_to_account.rbnew file mode 100644index 00000000..985aeb79--- /dev/null+++ b/db/migrate/20240202191746_add_accountable_to_account.rb@@ -0,0 +1,6 @@+class AddAccountableToAccount < ActiveRecord::Migration[7.2]+ def change+ add_column :accounts, :accountable_type, :string+ add_column :accounts, :accountable_id, :uuid+ end+enddiff --git a/db/migrate/20240202192214_create_account_depositories.rb b/db/migrate/20240202192214_create_account_depositories.rbnew file mode 100644index 00000000..2d8548cb--- /dev/null+++ b/db/migrate/20240202192214_create_account_depositories.rb@@ -0,0 +1,7 @@+class CreateAccountDepositories < ActiveRecord::Migration[7.2]+ def change+ create_table :account_depositories, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192231_create_account_credits.rb b/db/migrate/20240202192231_create_account_credits.rbnew file mode 100644index 00000000..221d4d8a--- /dev/null+++ b/db/migrate/20240202192231_create_account_credits.rb@@ -0,0 +1,7 @@+class CreateAccountCredits < ActiveRecord::Migration[7.2]+ def change+ create_table :account_credits, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192238_create_account_investments.rb b/db/migrate/20240202192238_create_account_investments.rbnew file mode 100644index 00000000..a616ee58--- /dev/null+++ b/db/migrate/20240202192238_create_account_investments.rb@@ -0,0 +1,7 @@+class CreateAccountInvestments < ActiveRecord::Migration[7.2]+ def change+ create_table :account_investments, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192312_create_account_properties.rb b/db/migrate/20240202192312_create_account_properties.rbnew file mode 100644index 00000000..1d44b4c7--- /dev/null+++ b/db/migrate/20240202192312_create_account_properties.rb@@ -0,0 +1,7 @@+class CreateAccountProperties < ActiveRecord::Migration[7.2]+ def change+ create_table :account_properties, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192319_create_account_vehicles.rb b/db/migrate/20240202192319_create_account_vehicles.rbnew file mode 100644index 00000000..712ac6d6--- /dev/null+++ b/db/migrate/20240202192319_create_account_vehicles.rb@@ -0,0 +1,7 @@+class CreateAccountVehicles < ActiveRecord::Migration[7.2]+ def change+ create_table :account_vehicles, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192327_create_account_other_assets.rb b/db/migrate/20240202192327_create_account_other_assets.rbnew file mode 100644index 00000000..e37ddcf6--- /dev/null+++ b/db/migrate/20240202192327_create_account_other_assets.rb@@ -0,0 +1,7 @@+class CreateAccountOtherAssets < ActiveRecord::Migration[7.2]+ def change+ create_table :account_other_assets, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/migrate/20240202192333_create_account_other_liabilities.rb b/db/migrate/20240202192333_create_account_other_liabilities.rbnew file mode 100644index 00000000..dd37e4c5--- /dev/null+++ b/db/migrate/20240202192333_create_account_other_liabilities.rb@@ -0,0 +1,7 @@+class CreateAccountOtherLiabilities < ActiveRecord::Migration[7.2]+ def change+ create_table :account_other_liabilities, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 1a132587..7cdbc9bf 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -15,6 +15,46 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_02_230325) doenable_extension "pgcrypto"enable_extension "plpgsql"+ create_table "account_credits", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_depositories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_investments", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_loans", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_other_assets", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_other_liabilities", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_properties", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end++ create_table "account_vehicles", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|+ t.datetime "created_at", null: false+ t.datetime "updated_at", null: false+ end+create_table "accounts", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|t.string "type"t.string "subtype"@@ -24,6 +64,9 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_02_230325) dot.string "currency", default: "USD"t.datetime "created_at", null: falset.datetime "updated_at", null: false+ t.string "accountable_type"+ t.uuid "accountable_id"+ t.index ["accountable_type"], name: "index_accounts_on_accountable_type"t.index ["family_id"], name: "index_accounts_on_family_id"t.index ["type"], name: "index_accounts_on_type"enddiff --git a/test/fixtures/account/credits.yml b/test/fixtures/account/credits.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/credits.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/depositories.yml b/test/fixtures/account/depositories.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/depositories.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/investments.yml b/test/fixtures/account/investments.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/investments.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/loans.yml b/test/fixtures/account/loans.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/loans.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/other_assets.yml b/test/fixtures/account/other_assets.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/other_assets.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/other_liabilities.yml b/test/fixtures/account/other_liabilities.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/other_liabilities.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/properties.yml b/test/fixtures/account/properties.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/properties.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/fixtures/account/vehicles.yml b/test/fixtures/account/vehicles.ymlnew file mode 100644index 00000000..d7a33292--- /dev/null+++ b/test/fixtures/account/vehicles.yml@@ -0,0 +1,11 @@+# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html++# This model initially had no columns defined. If you add columns to the+# model remove the "{}" from the fixture names and add the columns immediately+# below each fixture, per the syntax in the comments below+#+one: {}+# column: value+#+two: {}+# column: valuediff --git a/test/models/account/credit_test.rb b/test/models/account/credit_test.rbnew file mode 100644index 00000000..1c8fd636--- /dev/null+++ b/test/models/account/credit_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::CreditTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/depository_test.rb b/test/models/account/depository_test.rbnew file mode 100644index 00000000..d93cf1cd--- /dev/null+++ b/test/models/account/depository_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::DepositoryTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/investment_test.rb b/test/models/account/investment_test.rbnew file mode 100644index 00000000..1ed2b6ba--- /dev/null+++ b/test/models/account/investment_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::InvestmentTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/loan_test.rb b/test/models/account/loan_test.rbnew file mode 100644index 00000000..e793470a--- /dev/null+++ b/test/models/account/loan_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::LoanTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/other_asset_test.rb b/test/models/account/other_asset_test.rbnew file mode 100644index 00000000..d65911f5--- /dev/null+++ b/test/models/account/other_asset_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::OtherAssetTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/other_liability_test.rb b/test/models/account/other_liability_test.rbnew file mode 100644index 00000000..4c682491--- /dev/null+++ b/test/models/account/other_liability_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::OtherLiabilityTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/property_test.rb b/test/models/account/property_test.rbnew file mode 100644index 00000000..34f6fb71--- /dev/null+++ b/test/models/account/property_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::PropertyTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/account/vehicle_test.rb b/test/models/account/vehicle_test.rbnew file mode 100644index 00000000..011d99f5--- /dev/null+++ b/test/models/account/vehicle_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::VehicleTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+end