mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-19 13:19:39 +02:00
Prepare fixture data for account sync tests (#493)
* Rename account balance field for clarity `original_balance` and `original_currency` may infer that these values are "original" to the account. In reality, they represent the "current" balance and currency on the account. * Prepare fixture data for account sync testing * Update to new field * Fix conflicts * Remove local schema change
This commit is contained in:
parent
d3b326d273
commit
7d48c01833
37 changed files with 230 additions and 265 deletions
|
@ -3,7 +3,7 @@ class AccountsController < ApplicationController
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@account = Account.new(
|
@account = Account.new(
|
||||||
original_balance: nil,
|
balance: nil,
|
||||||
accountable: Accountable.from_type(params[:type])&.new
|
accountable: Accountable.from_type(params[:type])&.new
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
@ -41,6 +41,6 @@ class AccountsController < ApplicationController
|
||||||
private
|
private
|
||||||
|
|
||||||
def account_params
|
def account_params
|
||||||
params.require(:account).permit(:name, :accountable_type, :original_balance, :original_currency, :subtype)
|
params.require(:account).permit(:name, :accountable_type, :balance, :currency, :subtype)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,11 +6,11 @@ class ConvertCurrencyJob < ApplicationJob
|
||||||
|
|
||||||
# Convert all account balances to new currency
|
# Convert all account balances to new currency
|
||||||
family.accounts.each do |account|
|
family.accounts.each do |account|
|
||||||
if account.original_currency == family.currency
|
if account.currency == family.currency
|
||||||
account.converted_balance = account.original_balance
|
account.converted_balance = account.balance
|
||||||
account.converted_currency = account.original_currency
|
account.converted_currency = account.currency
|
||||||
else
|
else
|
||||||
account.converted_balance = ExchangeRate.convert(account.original_currency, family.currency, account.original_balance)
|
account.converted_balance = ExchangeRate.convert(account.currency, family.currency, account.balance)
|
||||||
account.converted_currency = family.currency
|
account.converted_currency = family.currency
|
||||||
end
|
end
|
||||||
account.save!
|
account.save!
|
||||||
|
|
|
@ -37,11 +37,11 @@ class Account < ApplicationRecord
|
||||||
end
|
end
|
||||||
|
|
||||||
def check_currency
|
def check_currency
|
||||||
if self.original_currency == self.family.currency
|
if self.currency == self.family.currency
|
||||||
self.converted_balance = self.original_balance
|
self.converted_balance = self.balance
|
||||||
self.converted_currency = self.original_currency
|
self.converted_currency = self.currency
|
||||||
else
|
else
|
||||||
self.converted_balance = ExchangeRate.convert(self.original_currency, self.family.currency, self.original_balance)
|
self.converted_balance = ExchangeRate.convert(self.currency, self.family.currency, self.balance)
|
||||||
self.converted_currency = self.family.currency
|
self.converted_currency = self.family.currency
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
<h1 class="text-3xl font-semibold font-display"><%= t('.title')%></h1>
|
<h1 class="text-3xl font-semibold font-display"><%= t('.title')%></h1>
|
||||||
|
|
||||||
<%= modal do %>
|
<%= modal do %>
|
||||||
<div class="flex flex-col min-h-[530px]" data-controller="list-keyboard-navigation">
|
<div class="flex flex-col min-h-[530px]" data-controller="list-keyboard-navigation">
|
||||||
<% if @account.accountable.blank? %>
|
<% if @account.accountable.blank? %>
|
||||||
|
@ -9,7 +8,6 @@
|
||||||
<div class="flex flex-col p-2 text-sm grow">
|
<div class="flex flex-col p-2 text-sm grow">
|
||||||
<button hidden data-controller="hotkey" data-hotkey="k,K,ArrowUp,ArrowLeft" data-action="list-keyboard-navigation#focusPrevious">Previous</button>
|
<button hidden data-controller="hotkey" data-hotkey="k,K,ArrowUp,ArrowLeft" data-action="list-keyboard-navigation#focusPrevious">Previous</button>
|
||||||
<button hidden data-controller="hotkey" data-hotkey="j,J,ArrowDown,ArrowRight" data-action="list-keyboard-navigation#focusNext">Next</button>
|
<button hidden data-controller="hotkey" data-hotkey="j,J,ArrowDown,ArrowRight" data-action="list-keyboard-navigation#focusNext">Next</button>
|
||||||
|
|
||||||
<%= render "account_type", type: Account::Depository.new, bg_color: "bg-blue-50", text_color: "text-blue-500", icon: "landmark" %>
|
<%= render "account_type", type: Account::Depository.new, bg_color: "bg-blue-50", text_color: "text-blue-500", icon: "landmark" %>
|
||||||
<%= render "account_type", type: Account::Investment.new, bg_color: "bg-green-50", text_color: "text-green-500", icon: "line-chart" %>
|
<%= render "account_type", type: Account::Investment.new, bg_color: "bg-green-50", text_color: "text-green-500", icon: "line-chart" %>
|
||||||
<%= render "account_type", type: Account::Property.new, bg_color: "bg-pink-50", text_color: "text-pink-500", icon: "home" %>
|
<%= render "account_type", type: Account::Property.new, bg_color: "bg-pink-50", text_color: "text-pink-500", icon: "home" %>
|
||||||
|
@ -42,7 +40,6 @@
|
||||||
<div class="flex flex-col p-2 text-sm grow">
|
<div class="flex flex-col p-2 text-sm grow">
|
||||||
<button hidden data-controller="hotkey" data-hotkey="k,K,ArrowUp,ArrowLeft" data-action="list-keyboard-navigation#focusPrevious">Previous</button>
|
<button hidden data-controller="hotkey" data-hotkey="k,K,ArrowUp,ArrowLeft" data-action="list-keyboard-navigation#focusPrevious">Previous</button>
|
||||||
<button hidden data-controller="hotkey" data-hotkey="j,J,ArrowDown,ArrowRight" data-action="list-keyboard-navigation#focusNext">Next</button>
|
<button hidden data-controller="hotkey" data-hotkey="j,J,ArrowDown,ArrowRight" data-action="list-keyboard-navigation#focusNext">Next</button>
|
||||||
|
|
||||||
<%= render "entry_method", type: @account.accountable, text: 'Enter account balance manually', icon: "keyboard" %>
|
<%= render "entry_method", type: @account.accountable, text: 'Enter account balance manually', icon: "keyboard" %>
|
||||||
<%= render "entry_method", type: @account.accountable, text: 'Securely link bank account with data provider (coming soon)', icon: "link-2", disabled: true %>
|
<%= render "entry_method", type: @account.accountable, text: 'Securely link bank account with data provider (coming soon)', icon: "link-2", disabled: true %>
|
||||||
<%= render "entry_method", type: @account.accountable, text: 'Upload spreadsheet (coming soon)', icon: "sheet", disabled: true %>
|
<%= render "entry_method", type: @account.accountable, text: 'Upload spreadsheet (coming soon)', icon: "sheet", disabled: true %>
|
||||||
|
@ -67,22 +64,17 @@
|
||||||
<% end %>
|
<% end %>
|
||||||
<span>Add <%= @account.accountable.model_name.human.downcase %></span>
|
<span>Add <%= @account.accountable.model_name.human.downcase %></span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "m-5 mt-1 flex flex-col justify-between grow", data: { turbo: false } } do |f| %>
|
<%= form_with model: @account, url: accounts_path, scope: :account, html: { class: "m-5 mt-1 flex flex-col justify-between grow", data: { turbo: false } } do |f| %>
|
||||||
<div class="space-y-4 grow">
|
<div class="space-y-4 grow">
|
||||||
<%= f.hidden_field :accountable_type %>
|
<%= f.hidden_field :accountable_type %>
|
||||||
|
|
||||||
<%= f.text_field :name, placeholder: t('accounts.new.name.placeholder'), required: 'required', label: t('accounts.new.name.label'), autofocus: true %>
|
<%= f.text_field :name, placeholder: t('accounts.new.name.placeholder'), required: 'required', label: t('accounts.new.name.label'), autofocus: true %>
|
||||||
|
|
||||||
<%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
|
<%= render "accounts/#{permitted_accountable_partial(@account.accountable_type)}", f: f %>
|
||||||
|
|
||||||
<%= form_field_tag do %>
|
<%= form_field_tag do %>
|
||||||
<%= f.label :original_balance, class: "form-field__label" %>
|
<%= f.label :balance, class: "form-field__label" %>
|
||||||
<%= f.number_field :original_balance, step: :any, placeholder: number_to_currency(0), in: 0.00..100000000.00, required: 'required', class: 'form-field__input max-w-[80%]' %>
|
<%= f.number_field :balance, step: :any, placeholder: number_to_currency(0), in: 0.00..100000000.00, required: 'required', class: 'form-field__input max-w-[80%]' %>
|
||||||
<%= currency_dropdown(f: f, options: Currency.all.order(:iso_code).pluck(:iso_code)) if Currency.count > 1 %>
|
<%= currency_dropdown(f: f, options: Currency.all.order(:iso_code).pluck(:iso_code)) if Currency.count > 1 %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<%= f.submit "Add #{@account.accountable.model_name.human.downcase}" %>
|
<%= f.submit "Add #{@account.accountable.model_name.human.downcase}" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="flex items-center gap-3">
|
<div class="flex items-center gap-3">
|
||||||
<div class="relative cursor-not-allowed">
|
<div class="relative cursor-not-allowed">
|
||||||
<div class="flex items-center gap-2 px-3 py-2">
|
<div class="flex items-center gap-2 px-3 py-2">
|
||||||
<span class="text-gray-900"><%= @account.original_currency %> <%= @account.original_currency.unit %></span>
|
<span class="text-gray-900"><%= @account.currency %> <%= @account.currency.unit %></span>
|
||||||
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
|
<%= lucide_icon("chevron-down", class: "w-5 h-5 text-gray-500") %>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -29,10 +29,10 @@
|
||||||
<p class="text-sm text-gray-500">Total Value</p>
|
<p class="text-sm text-gray-500">Total Value</p>
|
||||||
<%# TODO: Will need a better way to split a formatted monetary value into these 3 parts %>
|
<%# TODO: Will need a better way to split a formatted monetary value into these 3 parts %>
|
||||||
<p class="text-gray-900">
|
<p class="text-gray-900">
|
||||||
<span class="text-gray-500"><%= @account.original_currency.unit %></span>
|
<span class="text-gray-500"><%= @account.currency.unit %></span>
|
||||||
<span class="text-xl font-medium"><%= format_currency(@account.original_balance, precision: 0, unit: '') %></span>
|
<span class="text-xl font-medium"><%= format_currency(@account.balance, precision: 0, unit: '') %></span>
|
||||||
<%- if @account.original_currency.precision.positive? -%>
|
<%- if @account.currency.precision.positive? -%>
|
||||||
<span class="text-gray-500"><%= @account.original_currency.separator %><%= @account.original_balance.cents(precision: @account.original_currency.precision) %></span>
|
<span class="text-gray-500"><%= @account.currency.separator %><%= @account.balance.cents(precision: @account.currency.precision) %></span>
|
||||||
<% end %>
|
<% end %>
|
||||||
</p>
|
</p>
|
||||||
<% if @balance_series.nil? %>
|
<% if @balance_series.nil? %>
|
||||||
|
|
|
@ -1,14 +1,14 @@
|
||||||
<div data-controller="currency-dropdown" class="absolute right-1 bottom-[10px] flex items-end">
|
<div data-controller="currency-dropdown" class="absolute right-1 bottom-[10px] flex items-end">
|
||||||
<button type="button" class="flex items-center justify-between w-20 px-2 py-1 text-sm rounded-lg hover:bg-gray-100 focus:bg-gray-100" data-action="click->currency-dropdown#toggleMenu">
|
<button type="button" class="flex items-center justify-between w-20 px-2 py-1 text-sm rounded-lg hover:bg-gray-100 focus:bg-gray-100" data-action="click->currency-dropdown#toggleMenu">
|
||||||
<div data-currency-dropdown-target="label"><%= f.object.original_currency %></div>
|
<div data-currency-dropdown-target="label"><%= f.object.currency %></div>
|
||||||
<%# Example of how account currency value is updated %>
|
<%# Example of how account currency value is updated %>
|
||||||
<%= f.hidden_field :original_currency, data: {currency_dropdown_target: "input"} %>
|
<%= f.hidden_field :currency, data: {currency_dropdown_target: "input"} %>
|
||||||
<%= lucide_icon("chevron-down", class: "text-gray-500 w-5 h-5" ) %>
|
<%= lucide_icon("chevron-down", class: "text-gray-500 w-5 h-5" ) %>
|
||||||
</button>
|
</button>
|
||||||
<ul data-currency-dropdown-target="menu" class="hidden fixed p-1 bg-white rounded-[10px] min-w-[112px] z-50 translate-y-2 border border-alpha-black-100 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.1)]">
|
<ul data-currency-dropdown-target="menu" class="hidden fixed p-1 bg-white rounded-[10px] min-w-[112px] z-50 translate-y-2 border border-alpha-black-100 shadow-[inset_0_-1px_0_0_rgba(0,0,0,0.1)]">
|
||||||
<% options.each do |option| %>
|
<% options.each do |option| %>
|
||||||
<li data-action="click->currency-dropdown#selectOption" data-currency-dropdown-target="option" data-value="<%= option %>" class="flex justify-between items-center p-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer rounded-lg <%= "bg-gray-100" if option === f.object.original_currency %>"><%= option %>
|
<li data-action="click->currency-dropdown#selectOption" data-currency-dropdown-target="option" data-value="<%= option %>" class="flex justify-between items-center p-2 text-sm text-gray-700 hover:bg-gray-100 cursor-pointer rounded-lg <%= "bg-gray-100" if option === f.object.currency %>"><%= option %>
|
||||||
<%= inline_svg_tag('icn-check.svg', class: "text-gray-500 fill-current #{'hidden'if option != f.object.original_currency}") %>
|
<%= inline_svg_tag('icn-check.svg', class: "text-gray-500 fill-current #{'hidden'if option != f.object.currency}") %>
|
||||||
</li>
|
</li>
|
||||||
<% end %>
|
<% end %>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
|
@ -3,11 +3,11 @@ en:
|
||||||
activerecord:
|
activerecord:
|
||||||
attributes:
|
attributes:
|
||||||
account:
|
account:
|
||||||
|
balance: Balance
|
||||||
|
currency: Currency
|
||||||
family: Family
|
family: Family
|
||||||
family_id: Family
|
family_id: Family
|
||||||
name: Name
|
name: Name
|
||||||
original_balance: Balance
|
|
||||||
original_currency: Currency
|
|
||||||
subtype: Subtype
|
subtype: Subtype
|
||||||
models:
|
models:
|
||||||
account: Account
|
account: Account
|
||||||
|
|
6
db/migrate/20240227142457_rename_account_balance.rb
Normal file
6
db/migrate/20240227142457_rename_account_balance.rb
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
class RenameAccountBalance < ActiveRecord::Migration[7.2]
|
||||||
|
def change
|
||||||
|
rename_column :accounts, :original_balance, :balance
|
||||||
|
rename_column :accounts, :original_currency, :currency
|
||||||
|
end
|
||||||
|
end
|
6
db/schema.rb
generated
6
db/schema.rb
generated
|
@ -10,7 +10,7 @@
|
||||||
#
|
#
|
||||||
# It's strongly recommended that you check this file into your version control system.
|
# It's strongly recommended that you check this file into your version control system.
|
||||||
|
|
||||||
ActiveRecord::Schema[7.2].define(version: 2024_02_23_162105) do
|
ActiveRecord::Schema[7.2].define(version: 2024_02_27_142457) do
|
||||||
# These are extensions that must be enabled in order to support this database
|
# These are extensions that must be enabled in order to support this database
|
||||||
enable_extension "pgcrypto"
|
enable_extension "pgcrypto"
|
||||||
enable_extension "plpgsql"
|
enable_extension "plpgsql"
|
||||||
|
@ -74,8 +74,8 @@ ActiveRecord::Schema[7.2].define(version: 2024_02_23_162105) do
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at", null: false
|
||||||
t.string "accountable_type"
|
t.string "accountable_type"
|
||||||
t.uuid "accountable_id"
|
t.uuid "accountable_id"
|
||||||
t.decimal "original_balance", precision: 19, scale: 4, default: "0.0"
|
t.decimal "balance", precision: 19, scale: 4, default: "0.0"
|
||||||
t.string "original_currency", default: "USD"
|
t.string "currency", default: "USD"
|
||||||
t.decimal "converted_balance", precision: 19, scale: 4, default: "0.0"
|
t.decimal "converted_balance", precision: 19, scale: 4, default: "0.0"
|
||||||
t.string "converted_currency", default: "USD"
|
t.string "converted_currency", default: "USD"
|
||||||
t.string "status", default: "OK"
|
t.string "status", default: "OK"
|
||||||
|
|
|
@ -28,7 +28,7 @@ Currency.find_or_create_by(iso_code: "USD", name: "United States Dollar")
|
||||||
|
|
||||||
current_balance = 350000
|
current_balance = 350000
|
||||||
|
|
||||||
account = Account.create_or_find_by(name: "Seed Property Account", accountable: Account::Property.new, family: family, original_balance: current_balance, original_currency: "USD")
|
account = Account.create_or_find_by(name: "Seed Property Account", accountable: Account::Property.new, family: family, balance: current_balance, currency: "USD")
|
||||||
puts "Account created: #{account.name}"
|
puts "Account created: #{account.name}"
|
||||||
|
|
||||||
# Represent user-defined "Valuations" at various dates
|
# Represent user-defined "Valuations" at various dates
|
||||||
|
|
|
@ -2,8 +2,8 @@ require "test_helper"
|
||||||
|
|
||||||
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
class AccountsControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
sign_in @user = users(:bob)
|
sign_in @user = users(:family_admin)
|
||||||
@account = accounts(:dylan_checking)
|
@account = accounts(:generic)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new" do
|
test "new" do
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "test_helper"
|
||||||
|
|
||||||
class PagesControllerTest < ActionDispatch::IntegrationTest
|
class PagesControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
sign_in users(:bob)
|
sign_in users(:family_admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "dashboard" do
|
test "dashboard" do
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "test_helper"
|
||||||
|
|
||||||
class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
class PasswordResetsControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
@user = users(:bob)
|
@user = users(:family_admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new" do
|
test "new" do
|
||||||
|
|
|
@ -2,8 +2,8 @@ require "test_helper"
|
||||||
|
|
||||||
class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
class TransactionsControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
sign_in @user = users(:bob)
|
sign_in @user = users(:family_admin)
|
||||||
@transaction = transactions(:one)
|
@transaction = transactions(:checking_one)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should get index" do
|
test "should get index" do
|
||||||
|
|
|
@ -2,8 +2,8 @@ require "test_helper"
|
||||||
|
|
||||||
class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
class ValuationsControllerTest < ActionDispatch::IntegrationTest
|
||||||
setup do
|
setup do
|
||||||
sign_in @user = users(:bob)
|
sign_in @user = users(:family_admin)
|
||||||
@account = accounts(:dylan_checking)
|
@account = accounts(:generic)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new" do
|
test "new" do
|
||||||
|
|
10
test/fixtures/account/credits.yml
vendored
10
test/fixtures/account/credits.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
12
test/fixtures/account/depositories.yml
vendored
12
test/fixtures/account/depositories.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
checking: {}
|
||||||
|
|
||||||
# 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
|
|
||||||
|
|
10
test/fixtures/account/investments.yml
vendored
10
test/fixtures/account/investments.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
10
test/fixtures/account/loans.yml
vendored
10
test/fixtures/account/loans.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
10
test/fixtures/account/other_assets.yml
vendored
10
test/fixtures/account/other_assets.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
10
test/fixtures/account/other_liabilities.yml
vendored
10
test/fixtures/account/other_liabilities.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
10
test/fixtures/account/properties.yml
vendored
10
test/fixtures/account/properties.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
10
test/fixtures/account/vehicles.yml
vendored
10
test/fixtures/account/vehicles.yml
vendored
|
@ -1,11 +1 @@
|
||||||
# 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: {}
|
one: {}
|
||||||
# column: value
|
|
||||||
#
|
|
||||||
two: {}
|
|
||||||
# column: value
|
|
||||||
|
|
20
test/fixtures/account_balances.yml
vendored
20
test/fixtures/account_balances.yml
vendored
|
@ -1,13 +1,13 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
one:
|
# one:
|
||||||
account: dylan_checking
|
# account: generic
|
||||||
date: 2024-02-12
|
# date: 2024-02-12
|
||||||
balance: 9.99
|
# balance: 9.99
|
||||||
currency: MyString
|
# currency: MyString
|
||||||
|
|
||||||
two:
|
# two:
|
||||||
account: richards_savings
|
# account: generic
|
||||||
date: 2024-02-12
|
# date: 2024-02-13
|
||||||
balance: 9.99
|
# balance: 9.99
|
||||||
currency: MyString
|
# currency: MyString
|
||||||
|
|
29
test/fixtures/accounts.yml
vendored
29
test/fixtures/accounts.yml
vendored
|
@ -1,14 +1,23 @@
|
||||||
dylan_checking:
|
# No transactions, no valuations, just a generic account
|
||||||
|
generic:
|
||||||
family: dylan_family
|
family: dylan_family
|
||||||
name: Bob's Checking
|
name: No history, generic account
|
||||||
original_balance: 1200
|
balance: 1200
|
||||||
|
|
||||||
dylan_roth:
|
# Account with only valuations
|
||||||
|
collectible:
|
||||||
family: dylan_family
|
family: dylan_family
|
||||||
name: Bob's Roth IRA
|
name: Collectible Account
|
||||||
original_balance: 1200
|
balance: 500
|
||||||
|
|
||||||
richards_savings:
|
# Account with only transactions
|
||||||
family: richards_family
|
checking:
|
||||||
name: Keef's HYSA
|
family: dylan_family
|
||||||
original_balance: 1500
|
name: Checking Account
|
||||||
|
balance: 5000
|
||||||
|
|
||||||
|
# Account with both transactions and valuations
|
||||||
|
savings_with_valuation_overrides:
|
||||||
|
family: dylan_family
|
||||||
|
name: Savings account with valuation overrides
|
||||||
|
balance: 20000
|
||||||
|
|
20
test/fixtures/exchange_rates.yml
vendored
20
test/fixtures/exchange_rates.yml
vendored
|
@ -1,13 +1,13 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
||||||
|
|
||||||
one:
|
# one:
|
||||||
base_currency: one
|
# base_currency: one
|
||||||
converted_currency: one
|
# converted_currency: one
|
||||||
rate: 9.99
|
# rate: 9.99
|
||||||
date: 2024-02-09
|
# date: 2024-02-09
|
||||||
|
|
||||||
two:
|
# two:
|
||||||
base_currency: two
|
# base_currency: two
|
||||||
converted_currency: two
|
# converted_currency: two
|
||||||
rate: 9.99
|
# rate: 9.99
|
||||||
date: 2024-02-09
|
# date: 2024-02-09
|
||||||
|
|
5
test/fixtures/families.yml
vendored
5
test/fixtures/families.yml
vendored
|
@ -1,7 +1,2 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
|
||||||
|
|
||||||
dylan_family:
|
dylan_family:
|
||||||
name: The Dylan Family
|
name: The Dylan Family
|
||||||
|
|
||||||
richards_family:
|
|
||||||
name: The Richards Family
|
|
||||||
|
|
66
test/fixtures/transactions.yml
vendored
66
test/fixtures/transactions.yml
vendored
|
@ -1,15 +1,55 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# Checking account transactions
|
||||||
|
checking_one:
|
||||||
|
name: Starbucks
|
||||||
|
date: <%= 5.days.ago.to_date %>
|
||||||
|
amount: 10
|
||||||
|
account: checking
|
||||||
|
|
||||||
one:
|
checking_two:
|
||||||
name: MyString
|
name: Chipotle
|
||||||
date: 2024-02-23
|
date: <%= 12.days.ago.to_date %>
|
||||||
amount: 9.99
|
amount: 30
|
||||||
currency: MyString
|
account: checking
|
||||||
account: dylan_checking
|
|
||||||
|
|
||||||
two:
|
checking_three:
|
||||||
name: MyString
|
name: Amazon
|
||||||
date: 2024-02-20
|
date: <%= 15.days.ago.to_date %>
|
||||||
amount: 9.99
|
amount: 20
|
||||||
currency: MyString
|
account: checking
|
||||||
account: dylan_checking
|
|
||||||
|
checking_four:
|
||||||
|
name: Paycheck
|
||||||
|
date: <%= 22.days.ago.to_date %>
|
||||||
|
amount: -1075
|
||||||
|
account: checking
|
||||||
|
|
||||||
|
checking_five:
|
||||||
|
name: Netflix
|
||||||
|
date: <%= 30.days.ago.to_date %>
|
||||||
|
amount: 15
|
||||||
|
account: checking
|
||||||
|
|
||||||
|
# Savings account that has these transactions and valuation overrides
|
||||||
|
savings_one:
|
||||||
|
name: Interest Received
|
||||||
|
date: <%= 5.days.ago.to_date %>
|
||||||
|
amount: -200
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
||||||
|
savings_two:
|
||||||
|
name: Check Deposit
|
||||||
|
date: <%= 12.days.ago.to_date %>
|
||||||
|
amount: -50
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
||||||
|
savings_three:
|
||||||
|
name: Withdrawal
|
||||||
|
date: <%= 18.days.ago.to_date %>
|
||||||
|
amount: 2000
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
||||||
|
savings_four:
|
||||||
|
name: Check Deposit
|
||||||
|
date: <%= 30.days.ago.to_date %>
|
||||||
|
amount: -500
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
11
test/fixtures/users.yml
vendored
11
test/fixtures/users.yml
vendored
|
@ -1,20 +1,13 @@
|
||||||
bob:
|
family_admin:
|
||||||
family: dylan_family
|
family: dylan_family
|
||||||
first_name: Bob
|
first_name: Bob
|
||||||
last_name: Dylan
|
last_name: Dylan
|
||||||
email: bob@bobdylan.com
|
email: bob@bobdylan.com
|
||||||
password_digest: <%= BCrypt::Password.create('password') %>
|
password_digest: <%= BCrypt::Password.create('password') %>
|
||||||
|
|
||||||
jakob:
|
family_member:
|
||||||
family: dylan_family
|
family: dylan_family
|
||||||
first_name: Jakob
|
first_name: Jakob
|
||||||
last_name: Dylan
|
last_name: Dylan
|
||||||
email: jakobdylan@yahoo.com
|
email: jakobdylan@yahoo.com
|
||||||
password_digest: <%= BCrypt::Password.create('password') %>
|
password_digest: <%= BCrypt::Password.create('password') %>
|
||||||
|
|
||||||
keith:
|
|
||||||
family: richards_family
|
|
||||||
first_name: Keith
|
|
||||||
last_name: Richards
|
|
||||||
email: keith@rollingstones.com
|
|
||||||
password_digest: <%= BCrypt::Password.create('password') %>
|
|
||||||
|
|
33
test/fixtures/valuations.yml
vendored
33
test/fixtures/valuations.yml
vendored
|
@ -1,11 +1,26 @@
|
||||||
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
|
# For collectible account that only has valuations (no transactions)
|
||||||
|
collectible_one:
|
||||||
|
value: 550
|
||||||
|
date: <%= 4.days.ago.to_date %>
|
||||||
|
account: collectible
|
||||||
|
|
||||||
one:
|
collectible_two:
|
||||||
value: 9.99
|
value: 700
|
||||||
date: 2024-02-15
|
date: <%= 12.days.ago.to_date %>
|
||||||
account: dylan_checking
|
account: collectible
|
||||||
|
|
||||||
two:
|
collectible_three:
|
||||||
value: 9.99
|
value: 400
|
||||||
date: 2024-02-15
|
date: <%= 30.days.ago.to_date %>
|
||||||
account: richards_savings
|
account: collectible
|
||||||
|
|
||||||
|
# For checking account that has valuations and transactions
|
||||||
|
savings_one:
|
||||||
|
value: 20500
|
||||||
|
date: <%= 3.days.ago.to_date %>
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
||||||
|
savings_two:
|
||||||
|
value: 19500
|
||||||
|
date: <%= 12.days.ago.to_date %>
|
||||||
|
account: savings_with_valuation_overrides
|
||||||
|
|
|
@ -2,8 +2,9 @@ require "test_helper"
|
||||||
|
|
||||||
class AccountTest < ActiveSupport::TestCase
|
class AccountTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
depository = Account::Depository.create!
|
depository = account_depositories(:checking)
|
||||||
@account = Account.create!(family: families(:dylan_family), name: "Explicit Checking", original_balance: 1200, accountable: depository)
|
@account = accounts(:checking)
|
||||||
|
@account.accountable = depository
|
||||||
end
|
end
|
||||||
|
|
||||||
test "new account should be valid" do
|
test "new account should be valid" do
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "test_helper"
|
||||||
|
|
||||||
class CurrentTest < ActiveSupport::TestCase
|
class CurrentTest < ActiveSupport::TestCase
|
||||||
test "family returns user family" do
|
test "family returns user family" do
|
||||||
user = users(:bob)
|
user = users(:family_admin)
|
||||||
Current.user = user
|
Current.user = user
|
||||||
assert_equal user.family, Current.family
|
assert_equal user.family, Current.family
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,12 +6,12 @@ class FamilyTest < ActiveSupport::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should have many users" do
|
test "should have many users" do
|
||||||
assert_equal 2, @dylan_family.users.size
|
assert @dylan_family.users.size > 0
|
||||||
assert @dylan_family.users.include?(users(:bob))
|
assert @dylan_family.users.include?(users(:family_admin))
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should have many accounts" do
|
test "should have many accounts" do
|
||||||
assert_equal 2, @dylan_family.accounts.size
|
assert @dylan_family.accounts.size > 0
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should destroy dependent users" do
|
test "should destroy dependent users" do
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class TransactionTest < ActiveSupport::TestCase
|
class TransactionTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "test_helper"
|
||||||
|
|
||||||
class UserTest < ActiveSupport::TestCase
|
class UserTest < ActiveSupport::TestCase
|
||||||
def setup
|
def setup
|
||||||
@user = users(:bob)
|
@user = users(:family_admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should be valid" do
|
test "should be valid" do
|
||||||
|
|
|
@ -1,7 +1,4 @@
|
||||||
require "test_helper"
|
require "test_helper"
|
||||||
|
|
||||||
class ValuationTest < ActiveSupport::TestCase
|
class ValuationTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
end
|
||||||
|
|
|
@ -2,7 +2,7 @@ require "application_system_test_case"
|
||||||
|
|
||||||
class AccountsTest < ApplicationSystemTestCase
|
class AccountsTest < ApplicationSystemTestCase
|
||||||
setup do
|
setup do
|
||||||
sign_in @user = users(:bob)
|
sign_in @user = users(:family_admin)
|
||||||
end
|
end
|
||||||
|
|
||||||
test "should create account" do
|
test "should create account" do
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue