1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-19 05:09:38 +02:00

Rework Account to use delegated types

This commit is contained in:
Rob Zolkos 2024-02-02 23:09:35 +00:00
parent 938656de0e
commit 71939d6fb5
36 changed files with 282 additions and 0 deletions

View file

@ -3,5 +3,7 @@ class Account < ApplicationRecord
belongs_to :family
delegated_type :accountable, types: %w[ Credit Depository Investment Loan OtherAsset OtherLiability Property Vehicle]
scope :depository, -> { where(type: "Depository") }
end

View file

@ -0,0 +1,3 @@
class Account::Credit < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::Depository < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::Investment < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::Loan < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::OtherAsset < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::OtherLiability < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::Property < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,3 @@
class Account::Vehicle < ApplicationRecord
include Accountable
end

View file

@ -0,0 +1,7 @@
module Accountable
extend ActiveSupport::Concern
included do
has_one :account, as: :accountable, touch: true
end
end

View file

@ -0,0 +1,7 @@
class CreateAccountLoans < ActiveRecord::Migration[7.2]
def change
create_table :account_loans, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -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
end

View file

@ -0,0 +1,7 @@
class CreateAccountDepositories < ActiveRecord::Migration[7.2]
def change
create_table :account_depositories, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -0,0 +1,7 @@
class CreateAccountCredits < ActiveRecord::Migration[7.2]
def change
create_table :account_credits, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -0,0 +1,7 @@
class CreateAccountInvestments < ActiveRecord::Migration[7.2]
def change
create_table :account_investments, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -0,0 +1,7 @@
class CreateAccountProperties < ActiveRecord::Migration[7.2]
def change
create_table :account_properties, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -0,0 +1,7 @@
class CreateAccountVehicles < ActiveRecord::Migration[7.2]
def change
create_table :account_vehicles, id: :uuid do |t|
t.timestamps
end
end
end

View file

@ -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
end

View file

@ -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
end

43
db/schema.rb generated
View file

@ -15,6 +15,46 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_02_230325) do
enable_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) do
t.string "currency", default: "USD"
t.datetime "created_at", null: false
t.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"
end

11
test/fixtures/account/credits.yml vendored Normal file
View file

@ -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: value

11
test/fixtures/account/depositories.yml vendored Normal file
View file

@ -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: value

11
test/fixtures/account/investments.yml vendored Normal file
View file

@ -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: value

11
test/fixtures/account/loans.yml vendored Normal file
View file

@ -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: value

11
test/fixtures/account/other_assets.yml vendored Normal file
View file

@ -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: value

View file

@ -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: value

11
test/fixtures/account/properties.yml vendored Normal file
View file

@ -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: value

11
test/fixtures/account/vehicles.yml vendored Normal file
View file

@ -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: value

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::CreditTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::DepositoryTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::InvestmentTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::LoanTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::OtherAssetTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::OtherLiabilityTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::PropertyTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View file

@ -0,0 +1,7 @@
require "test_helper"
class Account::VehicleTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end