The personal finance app for everyone
feat: add crypto account type to demo data (#555)
Juan B. Rodriguez49d1fe0e115b
diff --git a/app/models/account/crypto.rb b/app/models/account/crypto.rbnew file mode 100644index 00000000..8aae9a6d--- /dev/null+++ b/app/models/account/crypto.rb@@ -0,0 +1,3 @@+class Account::Crypto < ApplicationRecord+ include Accountable+enddiff --git a/app/models/concerns/accountable.rb b/app/models/concerns/accountable.rbindex befc16fb..49120637 100644--- a/app/models/concerns/accountable.rb+++ b/app/models/concerns/accountable.rb@@ -1,7 +1,7 @@module Accountableextend ActiveSupport::Concern- ASSET_TYPES = %w[ Account::Depository Account::Investment Account::OtherAsset Account::Property Account::Vehicle ]+ ASSET_TYPES = %w[ Account::Depository Account::Investment Account::Crypto Account::OtherAsset Account::Property Account::Vehicle ]LIABILITY_TYPES = %w[ Account::Credit Account::Loan Account::OtherLiability ]TYPES = ASSET_TYPES + LIABILITY_TYPESdiff --git a/db/migrate/20240319154732_create_account_cryptos.rb b/db/migrate/20240319154732_create_account_cryptos.rbnew file mode 100644index 00000000..9dd2d2b3--- /dev/null+++ b/db/migrate/20240319154732_create_account_cryptos.rb@@ -0,0 +1,7 @@+class CreateAccountCryptos < ActiveRecord::Migration[7.2]+ def change+ create_table :account_cryptos, id: :uuid do |t|+ t.timestamps+ end+ end+enddiff --git a/db/schema.rb b/db/schema.rbindex 4595cc8a..5493b43a 100644--- a/db/schema.rb+++ b/db/schema.rb@@ -10,7 +10,7 @@## It's strongly recommended that you check this file into your version control system.-ActiveRecord::Schema[7.2].define(version: 2024_03_09_180636) do+ActiveRecord::Schema[7.2].define(version: 2024_03_19_154732) do# These are extensions that must be enabled in order to support this databaseenable_extension "pgcrypto"enable_extension "plpgsql"@@ -35,6 +35,11 @@ ActiveRecord::Schema[7.2].define(version: 2024_03_09_180636) dot.datetime "updated_at", null: falseend+ create_table "account_cryptos", 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: falset.datetime "updated_at", null: falsediff --git a/lib/tasks/demo_data.rake b/lib/tasks/demo_data.rakeindex aef3fad0..aff65594 100644--- a/lib/tasks/demo_data.rake+++ b/lib/tasks/demo_data.rake@@ -219,6 +219,24 @@ namespace :demo_data dobrokerage.sync+ crypto = Account.find_or_create_by(name: "Bitcoin Account") do |a|+ a.family = family+ a.accountable = Account::Crypto.new+ a.currency = "BTC"+ a.balance = 0.1+ end++ crypto_valuations = [+ { date: 1.year.ago.to_date, value: 0.05, currency: "BTC" },+ { date: 200.days.ago.to_date, value: 0.06, currency: "BTC" },+ { date: 100.days.ago.to_date, value: 0.08, currency: "BTC" },+ { date: 20.days.ago.to_date, value: 0.1, currency: "BTC" }+ ]++ crypto.valuations.upsert_all(crypto_valuations, unique_by: :index_valuations_on_account_id_and_date)++ crypto.sync+mortgage = Account.find_or_create_by(name: "Demo Mortgage") do |a|a.family = familya.accountable = Account::Loan.newdiff --git a/test/fixtures/account/cryptos.yml b/test/fixtures/account/cryptos.ymlnew file mode 100644index 00000000..1f0df1da--- /dev/null+++ b/test/fixtures/account/cryptos.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/crypto_test.rb b/test/models/account/crypto_test.rbnew file mode 100644index 00000000..82745f32--- /dev/null+++ b/test/models/account/crypto_test.rb@@ -0,0 +1,7 @@+require "test_helper"++class Account::CryptoTest < ActiveSupport::TestCase+ # test "the truth" do+ # assert true+ # end+enddiff --git a/test/models/time_series_test.rb b/test/models/time_series_test.rbindex 4b611666..df0b6d40 100644--- a/test/models/time_series_test.rb+++ b/test/models/time_series_test.rb@@ -39,12 +39,12 @@ class TimeSeriesTest < ActiveSupport::TestCaseexpected_values = {values: [{- date: "2024-03-17",+ date: 1.day.ago.to_date,value: { amount: "100.0", currency: "USD" },trend: { type: "normal", direction: "flat", value: { amount: "0.0", currency: "USD" }, percent: 0.0 }},{- date: "2024-03-18",+ date: Date.current,value: { amount: "200.0", currency: "USD" },trend: { type: "normal", direction: "up", value: { amount: "100.0", currency: "USD" }, percent: 100.0 }}