mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-08-05 13:35:21 +02:00
Account namespace updates: part 5 (valuations) (#901)
* Move Valuation to Account namespace * Move account history to controller * Clean up valuation controller and views * Translations and cleanup * Remove unused scopes and methods * Pass brakeman
This commit is contained in:
parent
0bc0d87768
commit
12380dc8ad
45 changed files with 478 additions and 346 deletions
49
test/models/account/transfer_test.rb
Normal file
49
test/models/account/transfer_test.rb
Normal file
|
@ -0,0 +1,49 @@
|
|||
require "test_helper"
|
||||
|
||||
class Account::TransferTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
# Transfers can be posted on different dates
|
||||
@outflow = accounts(:checking).transactions.create! date: 1.day.ago.to_date, name: "Transfer to Savings", amount: 100, marked_as_transfer: true
|
||||
@inflow = accounts(:savings).transactions.create! date: Date.current, name: "Transfer from Savings", amount: -100, marked_as_transfer: true
|
||||
end
|
||||
|
||||
test "transfer valid if it has inflow and outflow from different accounts for the same amount" do
|
||||
transfer = Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
|
||||
assert transfer.valid?
|
||||
end
|
||||
|
||||
test "transfer must have 2 transactions" do
|
||||
invalid_transfer_1 = Account::Transfer.new transactions: [ @outflow ]
|
||||
invalid_transfer_2 = Account::Transfer.new transactions: [ @inflow, @outflow, transactions(:savings_four) ]
|
||||
|
||||
assert invalid_transfer_1.invalid?
|
||||
assert invalid_transfer_2.invalid?
|
||||
end
|
||||
|
||||
test "transfer cannot have 2 transactions from the same account" do
|
||||
account = accounts(:checking)
|
||||
inflow = account.transactions.create! date: Date.current, name: "Inflow", amount: -100
|
||||
outflow = account.transactions.create! date: Date.current, name: "Outflow", amount: 100
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Account::Transfer.create! transactions: [ inflow, outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
test "all transfer transactions must be marked as transfers" do
|
||||
@inflow.update! marked_as_transfer: false
|
||||
|
||||
assert_raise ActiveRecord::RecordInvalid do
|
||||
Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
|
||||
test "transfer transactions must net to zero" do
|
||||
@outflow.update! amount: 105
|
||||
|
||||
assert_raises ActiveRecord::RecordInvalid do
|
||||
Account::Transfer.create! transactions: [ @inflow, @outflow ]
|
||||
end
|
||||
end
|
||||
end
|
39
test/models/account/valuation_test.rb
Normal file
39
test/models/account/valuation_test.rb
Normal file
|
@ -0,0 +1,39 @@
|
|||
require "test_helper"
|
||||
|
||||
class Account::ValuationTest < ActiveSupport::TestCase
|
||||
setup do
|
||||
@valuation = account_valuations :savings_one
|
||||
@family = families :dylan_family
|
||||
end
|
||||
|
||||
test "one valuation per day" do
|
||||
assert_equal 12.days.ago.to_date, account_valuations(:savings_one).date
|
||||
invalid_valuation = Account::Valuation.new date: 12.days.ago.to_date, value: 20000
|
||||
assert invalid_valuation.invalid?
|
||||
end
|
||||
|
||||
test "triggers sync with correct start date when valuation is set to prior date" do
|
||||
prior_date = @valuation.date - 1
|
||||
@valuation.update! date: prior_date
|
||||
|
||||
@valuation.account.expects(:sync_later).with(prior_date)
|
||||
@valuation.sync_account_later
|
||||
end
|
||||
|
||||
test "triggers sync with correct start date when valuation is set to future date" do
|
||||
prior_date = @valuation.date
|
||||
@valuation.update! date: @valuation.date + 1
|
||||
|
||||
@valuation.account.expects(:sync_later).with(prior_date)
|
||||
@valuation.sync_account_later
|
||||
end
|
||||
|
||||
test "triggers sync with correct start date when valuation deleted" do
|
||||
prior_valuation = account_valuations :savings_two # 25 days ago
|
||||
current_valuation = account_valuations :savings_one # 12 days ago
|
||||
current_valuation.destroy!
|
||||
|
||||
current_valuation.account.expects(:sync_later).with(prior_valuation.date)
|
||||
current_valuation.sync_account_later
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue