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

Add Transaction Merchant management (#686)

* Add basid crud for merchant management

* Tweak UI and add localization

* Fix lint

* Add filtering by merchant

* Add tests

* Add stimulus controller to update avatar in merchant form

* Add line between merchant rows

* Change default merchant color

* Cleanup
This commit is contained in:
Jakub Kottnauer 2024-04-29 21:17:28 +02:00 committed by GitHub
parent 7f491f5064
commit 9549182462
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
27 changed files with 363 additions and 18 deletions

View file

@ -32,6 +32,6 @@ class Transactions::CategoriesController < ApplicationController
end end
def category_params def category_params
params.require(:transaction_category).permit(:name, :name, :color) params.require(:transaction_category).permit(:name, :color)
end end
end end

View file

@ -1,4 +1,45 @@
class Transactions::MerchantsController < ApplicationController class Transactions::MerchantsController < ApplicationController
before_action :set_merchant, only: %i[ edit update destroy ]
def index def index
@merchants = Current.family.transaction_merchants
end
def new
@merchant = Transaction::Merchant.new
end
def create
if Current.family.transaction_merchants.create(merchant_params)
redirect_to transactions_merchants_path, notice: t(".success")
else
render transactions_merchants_path, status: :unprocessable_entity, notice: t(".error")
end
end
def edit
end
def update
if @merchant.update(merchant_params)
redirect_to transactions_merchants_path, notice: t(".success")
else
render transactions_merchants_path, status: :unprocessable_entity, notice: t(".error")
end
end
def destroy
@merchant.destroy!
redirect_to transactions_merchants_path, notice: t(".success")
end
private
def set_merchant
@merchant = Current.family.transaction_merchants.find(params[:id])
end
def merchant_params
params.require(:transaction_merchant).permit(:name, :color)
end end
end end

View file

@ -148,6 +148,6 @@ class TransactionsController < ApplicationController
# Only allow a list of trusted parameters through. # Only allow a list of trusted parameters through.
def transaction_params def transaction_params
params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id) params.require(:transaction).permit(:name, :date, :amount, :currency, :notes, :excluded, :category_id, :merchant_id)
end end
end end

View file

@ -22,9 +22,9 @@ module ApplicationHelper
# Wrap view with <%= modal do %> ... <% end %> to have it open in a modal # Wrap view with <%= modal do %> ... <% end %> to have it open in a modal
# Make sure to add data-turbo-frame="modal" to the link/button that opens the modal # Make sure to add data-turbo-frame="modal" to the link/button that opens the modal
def modal(&block) def modal(options = {}, &block)
content = capture &block content = capture &block
render partial: "shared/modal", locals: { content: content } render partial: "shared/modal", locals: { content:, classes: options[:classes] }
end end
def account_groups(period: nil) def account_groups(period: nil)

View file

@ -0,0 +1,32 @@
import {Controller} from "@hotwired/stimulus";
// Connects to data-controller="merchant-avatar"
// Used by the transaction merchant form to show a preview of what the avatar will look like
export default class extends Controller {
static targets = [
"name",
"color",
"avatar"
];
connect() {
this.nameTarget.addEventListener("input", this.handleNameChange);
this.colorTarget.addEventListener("input", this.handleColorChange);
}
disconnect() {
this.nameTarget.removeEventListener("input", this.handleNameChange);
this.colorTarget.removeEventListener("input", this.handleColorChange);
}
handleNameChange = (e) => {
this.avatarTarget.textContent = (e.currentTarget.value?.[0] || "?").toUpperCase();
}
handleColorChange = (e) => {
const color = e.currentTarget.value;
this.avatarTarget.style.backgroundColor = `color-mix(in srgb, ${color} 5%, white)`;
this.avatarTarget.style.borderColor = `color-mix(in srgb, ${color} 10%, white)`;
this.avatarTarget.style.color = color;
}
}

View file

@ -3,6 +3,7 @@ class Family < ApplicationRecord
has_many :accounts, dependent: :destroy has_many :accounts, dependent: :destroy
has_many :transactions, through: :accounts has_many :transactions, through: :accounts
has_many :transaction_categories, dependent: :destroy, class_name: "Transaction::Category" has_many :transaction_categories, dependent: :destroy, class_name: "Transaction::Category"
has_many :transaction_merchants, dependent: :destroy, class_name: "Transaction::Merchant"
def snapshot(period = Period.all) def snapshot(period = Period.all)
query = accounts.active.joins(:balances) query = accounts.active.joins(:balances)

View file

@ -3,6 +3,7 @@ class Transaction < ApplicationRecord
belongs_to :account belongs_to :account
belongs_to :category, optional: true belongs_to :category, optional: true
belongs_to :merchant, optional: true
validates :name, :date, :amount, :account, presence: true validates :name, :date, :amount, :account, presence: true
@ -56,7 +57,7 @@ class Transaction < ApplicationRecord
end end
def self.ransackable_associations(auth_object = nil) def self.ransackable_associations(auth_object = nil)
%w[category account] %w[category merchant account]
end end
def self.build_filter_list(params, family) def self.build_filter_list(params, family)
@ -77,7 +78,11 @@ class Transaction < ApplicationRecord
value.each do |category_id| value.each do |category_id|
filters << { type: "category", value: family.transaction_categories.find(category_id), original: { key: key, value: category_id } } filters << { type: "category", value: family.transaction_categories.find(category_id), original: { key: key, value: category_id } }
end end
when "category_name_or_account_name_or_name_cont" when "merchant_id_in"
value.each do |merchant_id|
filters << { type: "merchant", value: family.transaction_merchants.find(merchant_id), original: { key: key, value: merchant_id } }
end
when "category_name_or_merchant_name_or_account_name_or_name_cont"
filters << { type: "search", value: value, original: { key: key, value: nil } } filters << { type: "search", value: value, original: { key: key, value: nil } }
when "date_gteq" when "date_gteq"
date_filters[:gteq] = value date_filters[:gteq] = value

View file

@ -0,0 +1,18 @@
class Transaction::Merchant < ApplicationRecord
has_many :transactions, dependent: :nullify
belongs_to :family
validates :name, :color, :family, presence: true
scope :alphabetically, -> { order(:name) }
COLORS = %w[#e99537 #4da568 #6471eb #db5a54 #df4e92 #c44fe9 #eb5429 #61c9ea #805dee #6ad28a]
def self.ransackable_attributes(auth_object = nil)
%w[name id]
end
def self.ransackable_associations(auth_object = nil)
%w[]
end
end

View file

@ -1,6 +1,6 @@
<%# locals: (content:) -%> <%# locals: (content:, classes:) -%>
<%= turbo_frame_tag "modal" do %> <%= turbo_frame_tag "modal" do %>
<dialog class="bg-white border border-alpha-black-25 rounded-2xl max-h-[648px] max-w-[580px] w-full shadow-xs h-fit" data-controller="modal" data-action="click->modal#clickOutside"> <dialog class="bg-white border border-alpha-black-25 rounded-2xl max-h-[648px] max-w-[580px] w-full shadow-xs h-fit <%= classes %>" data-controller="modal" data-action="click->modal#clickOutside">
<div class="flex flex-col"> <div class="flex flex-col">
<%= content %> <%= content %>
</div> </div>

View file

@ -11,6 +11,11 @@
<div class="w-2 h-4 text-xs flex items-center justify-center rounded-full" style="background-color: <%= filter[:value].color %>"></div> <div class="w-2 h-4 text-xs flex items-center justify-center rounded-full" style="background-color: <%= filter[:value].color %>"></div>
<p><%= filter[:value].name %></p> <p><%= filter[:value].name %></p>
</div> </div>
<% when "merchant" %>
<div class="flex items-center gap-2">
<div class="w-2 h-4 text-xs flex items-center justify-center rounded-full" style="background-color: <%= filter[:value].color %>"></div>
<p><%= filter[:value].name %></p>
</div>
<% when "search" %> <% when "search" %>
<div class="flex items-center gap-2"> <div class="flex items-center gap-2">
<%= lucide_icon "text", class: "w-5 h-5 text-gray-500" %> <%= lucide_icon "text", class: "w-5 h-5 text-gray-500" %>

View file

@ -0,0 +1,7 @@
<%# locals: (merchant:) %>
<% name = merchant.name || "?" %>
<% background_color = "color-mix(in srgb, #{merchant.color} 5%, white)" %>
<% border_color = "color-mix(in srgb, #{merchant.color} 10%, white)" %>
<span data-merchant-avatar-target="avatar" class="w-8 h-8 flex items-center justify-center rounded-full" style="background-color: <%= background_color %>; border-color: <%= border_color %>; color: <%= merchant.color %>">
<%= name[0].upcase %>
</span>

View file

@ -0,0 +1,27 @@
<% is_editing = @merchant.id.present? %>
<div data-controller="merchant-avatar">
<%= form_with model: @merchant, url: is_editing ? transactions_merchant_path(@merchant) : transactions_merchants_path, method: is_editing ? :patch : :post, scope: :transaction_merchant, data: { turbo: false } do |f| %>
<section class="space-y-4">
<div class="w-fit m-auto">
<%= render partial: "transactions/merchants/avatar", locals: { merchant: } %>
</div>
<div data-controller="select" data-select-active-class="bg-gray-200" data-select-selected-value="<%= @merchant&.color || Transaction::Merchant::COLORS[0] %>">
<%= f.hidden_field :color, data: { select_target: "input", merchant_avatar_target: "color" } %>
<ul data-select-target="list" class="flex gap-2 items-center">
<% Transaction::Merchant::COLORS.each do |color| %>
<li tabindex="0" data-select-target="option" data-action="click->select#selectOption" data-value="<%= color %>" class="flex shrink-0 justify-center items-center w-6 h-6 cursor-pointer hover:bg-gray-200 rounded-full">
<div style="background-color: <%= color %>" class="shrink-0 w-4 h-4 rounded-full"></div>
</li>
<% end %>
</ul>
</div>
<div class="relative flex items-center border border-gray-200 rounded-lg">
<%= f.text_field :name, placeholder: t(".name_placeholder"), class: "text-sm font-normal placeholder:text-gray-500 h-10 relative pl-3 w-full border-none rounded-lg", required: true, data: { merchant_avatar_target: "name" } %>
</div>
</section>
<section>
<%= f.submit(is_editing ? t(".submit_edit") : t(".submit_create")) %>
</section>
<% end %>
</div>

View file

@ -0,0 +1,41 @@
<%# locals: (merchants:) %>
<% merchants.each.with_index do |merchant, index| %>
<div class="flex justify-between items-center p-4 bg-white">
<div class="flex w-full items-center gap-2.5">
<%= render partial: "transactions/merchants/avatar", locals: { merchant: } %>
<p class="text-gray-900 text-sm truncate">
<%= merchant.name %>
</p>
</div>
<div class="relative cursor-pointer" data-controller="menu">
<button data-menu-target="button" class="flex hover:bg-gray-100 p-2 rounded">
<%= lucide_icon("more-horizontal", class: "w-5 h-5 text-gray-500") %>
</button>
<div data-menu-target="content" class="absolute z-10 top-10 right-0 border border-alpha-black-25 bg-white rounded-lg shadow-xs w-48 hidden">
<div class="border-t border-b border-alpha-black-100 p-1">
<%= button_to edit_transactions_merchant_path(merchant),
method: :get,
class: "flex w-full gap-1 items-center text-sm hover:bg-gray-50 rounded-lg px-3 py-2",
data: { turbo_frame: "modal" } do %>
<%= lucide_icon("pencil-line", class: "w-5 h-5 mr-2") %> <%= t(".edit") %>
<% end %>
<%= button_to transactions_merchant_path(merchant),
method: :delete,
class: "flex w-full gap-1 items-center text-sm text-red-600 hover:text-red-800 hover:bg-gray-50 rounded-lg px-3 py-2",
data: {
turbo_confirm: {
title: t(".confirm_title"),
body: t(".confirm_body"),
accept: t(".confirm_accept")
}
} do %>
<%= lucide_icon("trash-2", class: "w-5 h-5 mr-1") %> <%= t(".delete") %>
<% end %>
</div>
</div>
</div>
</div>
<% unless index == merchants.size - 1 %>
<div class="h-px bg-alpha-black-50 ml-14 mr-6"></div>
<% end %>
<% end %>

View file

@ -0,0 +1,10 @@
<%= modal classes: "max-w-fit" do %>
<article class="mx-auto w-full p-4 space-y-4">
<header class="flex justify-between">
<h2 class="font-medium text-xl"><%= t(".title") %></h2>
<%= lucide_icon "x", class: "w-5 h-5 text-gray-500", data: { action: "click->modal#close" } %>
</header>
<%= render "form", merchant: @merchant %>
</article>
<% end %>

View file

@ -2,11 +2,34 @@
<%= render "settings/nav" %> <%= render "settings/nav" %>
<% end %> <% end %>
<div class="space-y-4"> <div class="space-y-4">
<h1 class="text-gray-900 text-xl font-medium mb-4">Merchants</h1> <div class="flex items-center justify-between">
<h1 class="text-xl font-medium text-gray-900"><%= t(".title") %></h1>
<%= link_to new_transactions_merchant_path, class: "flex text-white text-sm font-medium items-center gap-1 bg-gray-900 rounded-lg p-2", data: { turbo_frame: "modal" } do %>
<%= lucide_icon("plus", class: "w-5 h-5") %>
<span><%= t(".new_short") %></span>
<% end %>
</div>
<div class="bg-white shadow-xs border border-alpha-black-25 rounded-xl p-4"> <div class="bg-white shadow-xs border border-alpha-black-25 rounded-xl p-4">
<div class="flex justify-center items-center py-20"> <% if @merchants.empty? %>
<p class="text-gray-500">Manage transaction merchants coming soon...</p> <div class="flex justify-center items-center py-20">
</div> <div class="text-center flex flex-col items-center max-w-[300px]">
<p class="text-gray-900 mb-1 font-medium text-sm"><%= t(".empty") %></p>
<%= link_to new_transactions_merchant_path, class: "w-fit flex text-white text-sm font-medium items-center gap-1 bg-gray-900 rounded-lg p-2", data: { turbo_frame: "modal" } do %>
<%= lucide_icon("plus", class: "w-5 h-5") %>
<span><%= t(".new_long") %></span>
<% end %>
</div>
</div>
<% else %>
<div class="bg-gray-25 p-1 rounded-xl">
<div class="flex items-center px-4 py-2 text-xs font-medium text-gray-500">
<p><%= t(".title") %></p>
<span class="text-gray-400 mx-2">&middot;</span>
<p><%= @merchants.count %></p>
</div>
<%= render partial: "transactions/merchants/list", locals: { merchants: @merchants } %>
</div>
<% end %>
</div> </div>
<div class="flex justify-between gap-4"> <div class="flex justify-between gap-4">
<%= previous_setting("Categories", transactions_categories_path) %> <%= previous_setting("Categories", transactions_categories_path) %>

View file

@ -0,0 +1,10 @@
<%= modal classes: "max-w-fit" do %>
<article class="mx-auto w-full p-4 space-y-4">
<header class="flex justify-between">
<h2 class="font-medium text-xl"><%= t(".title") %></h2>
<%= lucide_icon "x", class: "w-5 h-5 text-gray-500", data: { action: "click->modal#close" } %>
</header>
<%= render "form", merchant: @merchant %>
</article>
<% end %>

View file

@ -1,4 +1,15 @@
<%# locals: (form:) %> <%# locals: (form:) %>
<div class="py-12 flex items-center justify-center"> <div data-controller="list-filter">
<p class="text-gray-500 text-sm">Filter by merchant coming soon...</p> <div class="relative">
<input type="search" autocomplete="off" placeholder="Filter merchants" data-list-filter-target="input" data-action="input->list-filter#filter" class="block w-full border border-gray-200 rounded-md py-2 pl-10 pr-3 focus:border-indigo-500 focus:ring-indigo-500 sm:text-sm">
<%= lucide_icon("search", class: "w-5 h-5 text-gray-500 absolute inset-y-0 left-2 top-1/2 transform -translate-y-1/2") %>
</div>
<div class="my-2" id="list" data-list-filter-target="list">
<% Current.family.transaction_merchants.each do |merchant| %>
<div class="filterable-item flex items-center gap-2 p-2" data-filter-name="<%= merchant.name %>">
<%= form.check_box :merchant_id_in, { multiple: true, class: "rounded-sm border-gray-300 text-indigo-600 shadow-xs focus:border-indigo-300 focus:ring focus:ring-indigo-200 focus:ring-opacity-50" }, merchant.id, nil %>
<%= form.label :merchant_id_in, merchant.name, value: merchant.id, class: "text-sm text-gray-900" %>
</div>
<% end %>
</div>
</div> </div>

View file

@ -1,7 +1,7 @@
<%# locals: (form:) %> <%# locals: (form:) %>
<div class="relative flex items-center bg-white border border-gray-200 rounded-lg"> <div class="relative flex items-center bg-white border border-gray-200 rounded-lg">
<%= form.search_field :category_name_or_account_name_or_name_cont, <%= form.search_field :category_name_or_merchant_name_or_account_name_or_name_cont,
placeholder: "Search transaction by name, category or amount", placeholder: "Search transaction by name, merchant, category or amount",
class: "placeholder:text-sm placeholder:text-gray-500 relative pl-10 w-full border-none rounded-lg", class: "placeholder:text-sm placeholder:text-gray-500 relative pl-10 w-full border-none rounded-lg",
"data-auto-submit-form-target": "auto" %> "data-auto-submit-form-target": "auto" %>
<%= lucide_icon("search", class: "w-5 h-5 text-gray-500 ml-2 absolute inset-0 transform top-1/2 -translate-y-1/2") %> <%= lucide_icon("search", class: "w-5 h-5 text-gray-500 ml-2 absolute inset-0 transform top-1/2 -translate-y-1/2") %>

View file

@ -27,5 +27,34 @@ en:
income: Income income: Income
submit: Add transaction submit: Add transaction
transfer: Transfer transfer: Transfer
merchants:
create:
error: Error creating merchant
success: New merchant created successfully
destroy:
success: Merchant deleted successfully
edit:
title: Edit merchant
form:
name_placeholder: Merchant name
submit_create: Add merchant
submit_edit: Update
index:
empty: No merchants yet
new_long: New merchant
new_short: New
title: Merchants
list:
confirm_accept: Delete merchant
confirm_body: Are you sure you want to delete this merchant? Removing this
merchant will unlink all associated transactions and may effect your reporting.
confirm_title: Delete merchant?
delete: Delete merchant
edit: Edit merchant
new:
title: New merchant
update:
error: Error updating merchant
success: Merchant updated successfully
update: update:
success: Transaction updated successfully success: Transaction updated successfully

View file

@ -25,7 +25,7 @@ Rails.application.routes.draw do
# TODO: These are *placeholders* # TODO: These are *placeholders*
# Uncomment `only` and add the necessary actions as they are implemented. # Uncomment `only` and add the necessary actions as they are implemented.
resources :rules, only: [ :index ] resources :rules, only: [ :index ]
resources :merchants, only: [ :index ] resources :merchants, only: %i[index new create edit update destroy]
end end
resources :transactions do resources :transactions do

View file

@ -0,0 +1,13 @@
class AddTransactionMerchants < ActiveRecord::Migration[7.2]
def change
create_table :transaction_merchants, id: :uuid do |t|
t.string "name", null: false
t.string "color", default: "#e99537", null: false
t.references :family, null: false, foreign_key: true, type: :uuid
t.timestamps
end
add_reference :transactions, :merchant, foreign_key: { to_table: :transaction_merchants }, type: :uuid
end
end

15
db/schema.rb generated
View file

@ -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_04_25_000110) do ActiveRecord::Schema[7.2].define(version: 2024_04_26_191312) 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"
@ -219,6 +219,15 @@ ActiveRecord::Schema[7.2].define(version: 2024_04_25_000110) do
t.index ["family_id"], name: "index_transaction_categories_on_family_id" t.index ["family_id"], name: "index_transaction_categories_on_family_id"
end end
create_table "transaction_merchants", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name", null: false
t.string "color", default: "#e99537", null: false
t.uuid "family_id", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["family_id"], name: "index_transaction_merchants_on_family_id"
end
create_table "transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "transactions", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.string "name" t.string "name"
t.date "date", null: false t.date "date", null: false
@ -230,8 +239,10 @@ ActiveRecord::Schema[7.2].define(version: 2024_04_25_000110) do
t.uuid "category_id" t.uuid "category_id"
t.boolean "excluded", default: false t.boolean "excluded", default: false
t.text "notes" t.text "notes"
t.uuid "merchant_id"
t.index ["account_id"], name: "index_transactions_on_account_id" t.index ["account_id"], name: "index_transactions_on_account_id"
t.index ["category_id"], name: "index_transactions_on_category_id" t.index ["category_id"], name: "index_transactions_on_category_id"
t.index ["merchant_id"], name: "index_transactions_on_merchant_id"
end end
create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "users", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
@ -264,8 +275,10 @@ ActiveRecord::Schema[7.2].define(version: 2024_04_25_000110) do
add_foreign_key "account_balances", "accounts", on_delete: :cascade add_foreign_key "account_balances", "accounts", on_delete: :cascade
add_foreign_key "accounts", "families" add_foreign_key "accounts", "families"
add_foreign_key "transaction_categories", "families" add_foreign_key "transaction_categories", "families"
add_foreign_key "transaction_merchants", "families"
add_foreign_key "transactions", "accounts", on_delete: :cascade add_foreign_key "transactions", "accounts", on_delete: :cascade
add_foreign_key "transactions", "transaction_categories", column: "category_id", on_delete: :nullify add_foreign_key "transactions", "transaction_categories", column: "category_id", on_delete: :nullify
add_foreign_key "transactions", "transaction_merchants", column: "merchant_id"
add_foreign_key "users", "families" add_foreign_key "users", "families"
add_foreign_key "valuations", "accounts", on_delete: :cascade add_foreign_key "valuations", "accounts", on_delete: :cascade
end end

View file

@ -0,0 +1,39 @@
require "test_helper"
class Transactions::MerchantsControllerTest < ActionDispatch::IntegrationTest
setup do
sign_in @user = users(:family_admin)
@merchant = transaction_merchants(:netflix)
end
test "index" do
get transactions_merchants_path
assert_response :success
end
test "new" do
get new_transactions_merchant_path
assert_response :success
end
test "should create merchant" do
assert_difference("Transaction::Merchant.count") do
post transactions_merchants_url, params: { transaction_merchant: { name: "new merchant", color: "#000000" } }
end
assert_redirected_to transactions_merchants_path
end
test "should update merchant" do
patch transactions_merchant_url(@merchant), params: { transaction_merchant: { name: "new name", color: "#000000" } }
assert_redirected_to transactions_merchants_path
end
test "should destroy merchant" do
assert_difference("Transaction::Merchant.count", -1) do
delete transactions_merchant_url(@merchant)
end
assert_redirected_to transactions_merchants_path
end
end

View file

@ -16,6 +16,8 @@ class ValuationsControllerTest < ActionDispatch::IntegrationTest
assert_difference("Valuation.count") do assert_difference("Valuation.count") do
post account_valuations_url(@account), params: { valuation: { value: 1, date: Date.current, type: "Appraisal" } } post account_valuations_url(@account), params: { valuation: { value: 1, date: Date.current, type: "Appraisal" } }
end end
assert_redirected_to account_path(@valuation.account)
end end
test "create should sync account with correct start date" do test "create should sync account with correct start date" do

View file

@ -0,0 +1,9 @@
netflix:
name: Netflix
color: "#fd7f6f"
family: dylan_family
amazon:
name: Amazon
color: "#fd7f6f"
family: dylan_family

View file

@ -21,6 +21,7 @@ checking_three:
amount: 20 amount: 20
account: checking account: checking
currency: USD currency: USD
merchant: amazon
checking_four: checking_four:
name: Paycheck name: Paycheck
@ -36,6 +37,7 @@ checking_five:
amount: 15 amount: 15
account: checking account: checking
currency: USD currency: USD
merchant: netflix
# Savings account that has these transactions and valuation overrides # Savings account that has these transactions and valuation overrides
savings_one: savings_one:
@ -92,6 +94,7 @@ credit_card_three:
amount: 20 amount: 20
account: credit_card account: credit_card
currency: USD currency: USD
merchant: amazon
credit_card_four: credit_card_four:
name: CC Payment name: CC Payment

View file

@ -51,6 +51,12 @@ class FamilyTest < ActiveSupport::TestCase
end end
end end
test "should destroy dependent merchants" do
assert_difference("Transaction::Merchant.count", -@family.transaction_merchants.count) do
@family.destroy
end
end
test "should calculate total assets" do test "should calculate total assets" do
expected = @expected_snapshots.last["assets"].to_d expected = @expected_snapshots.last["assets"].to_d
assert_equal Money.new(expected), @family.assets assert_equal Money.new(expected), @family.assets