mirror of
https://github.com/we-promise/sure.git
synced 2026-04-07 14:31:25 +00:00
Rework Account to use delegated types
This commit is contained in:
@@ -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
|
||||
|
||||
3
app/models/account/credit.rb
Normal file
3
app/models/account/credit.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Credit < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/depository.rb
Normal file
3
app/models/account/depository.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Depository < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/investment.rb
Normal file
3
app/models/account/investment.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Investment < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/loan.rb
Normal file
3
app/models/account/loan.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Loan < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/other_asset.rb
Normal file
3
app/models/account/other_asset.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::OtherAsset < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/other_liability.rb
Normal file
3
app/models/account/other_liability.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::OtherLiability < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/property.rb
Normal file
3
app/models/account/property.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Property < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
3
app/models/account/vehicle.rb
Normal file
3
app/models/account/vehicle.rb
Normal file
@@ -0,0 +1,3 @@
|
||||
class Account::Vehicle < ApplicationRecord
|
||||
include Accountable
|
||||
end
|
||||
7
app/models/concerns/accountable.rb
Normal file
7
app/models/concerns/accountable.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
module Accountable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_one :account, as: :accountable, touch: true
|
||||
end
|
||||
end
|
||||
7
db/migrate/20240202191425_create_account_loans.rb
Normal file
7
db/migrate/20240202191425_create_account_loans.rb
Normal 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
|
||||
6
db/migrate/20240202191746_add_accountable_to_account.rb
Normal file
6
db/migrate/20240202191746_add_accountable_to_account.rb
Normal 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
|
||||
7
db/migrate/20240202192214_create_account_depositories.rb
Normal file
7
db/migrate/20240202192214_create_account_depositories.rb
Normal 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
|
||||
7
db/migrate/20240202192231_create_account_credits.rb
Normal file
7
db/migrate/20240202192231_create_account_credits.rb
Normal 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
|
||||
7
db/migrate/20240202192238_create_account_investments.rb
Normal file
7
db/migrate/20240202192238_create_account_investments.rb
Normal 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
|
||||
7
db/migrate/20240202192312_create_account_properties.rb
Normal file
7
db/migrate/20240202192312_create_account_properties.rb
Normal 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
|
||||
7
db/migrate/20240202192319_create_account_vehicles.rb
Normal file
7
db/migrate/20240202192319_create_account_vehicles.rb
Normal 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
|
||||
7
db/migrate/20240202192327_create_account_other_assets.rb
Normal file
7
db/migrate/20240202192327_create_account_other_assets.rb
Normal 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
|
||||
@@ -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
43
db/schema.rb
generated
@@ -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
11
test/fixtures/account/credits.yml
vendored
Normal 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
11
test/fixtures/account/depositories.yml
vendored
Normal 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
11
test/fixtures/account/investments.yml
vendored
Normal 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
11
test/fixtures/account/loans.yml
vendored
Normal 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
11
test/fixtures/account/other_assets.yml
vendored
Normal 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_liabilities.yml
vendored
Normal file
11
test/fixtures/account/other_liabilities.yml
vendored
Normal 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
11
test/fixtures/account/properties.yml
vendored
Normal 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
11
test/fixtures/account/vehicles.yml
vendored
Normal 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
|
||||
7
test/models/account/credit_test.rb
Normal file
7
test/models/account/credit_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::CreditTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/depository_test.rb
Normal file
7
test/models/account/depository_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::DepositoryTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/investment_test.rb
Normal file
7
test/models/account/investment_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::InvestmentTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/loan_test.rb
Normal file
7
test/models/account/loan_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::LoanTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/other_asset_test.rb
Normal file
7
test/models/account/other_asset_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::OtherAssetTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/other_liability_test.rb
Normal file
7
test/models/account/other_liability_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::OtherLiabilityTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/property_test.rb
Normal file
7
test/models/account/property_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::PropertyTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
7
test/models/account/vehicle_test.rb
Normal file
7
test/models/account/vehicle_test.rb
Normal file
@@ -0,0 +1,7 @@
|
||||
require "test_helper"
|
||||
|
||||
class Account::VehicleTest < ActiveSupport::TestCase
|
||||
# test "the truth" do
|
||||
# assert true
|
||||
# end
|
||||
end
|
||||
Reference in New Issue
Block a user