1
0
Fork 0
mirror of https://github.com/maybe-finance/maybe.git synced 2025-07-22 22:59:39 +02:00

Allow for optional start date on account creation (#866)

This commit is contained in:
Zach Gollwitzer 2024-06-13 09:16:00 -04:00 committed by GitHub
parent c5704ffd45
commit 8c1a7af37f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 83 additions and 33 deletions

View file

@ -27,20 +27,35 @@ class AccountsControllerTest < ActionDispatch::IntegrationTest
assert_equal "Account updated", flash[:notice]
end
test "should create account" do
assert_difference -> { Account.count }, +1 do
post accounts_path, params: { account: { accountable_type: "Account::Credit" } }
test "should create an account" do
assert_difference [ "Account.count", "Valuation.count" ], 1 do
post accounts_path, params: {
account: {
accountable_type: "Account::Depository",
balance: 200,
subtype: "checking"
}
}
assert_equal "New account created successfully", flash[:notice]
assert_redirected_to account_url(Account.order(:created_at).last)
end
end
test "should create a valuation together with account" do
balance = 700
start_date = 3.days.ago.to_date
post accounts_path, params: { account: { accountable_type: "Account::Credit", balance:, start_date: } }
test "can add optional start date and balance to an account on create" do
assert_difference -> { Account.count } => 1, -> { Valuation.count } => 2 do
post accounts_path, params: {
account: {
accountable_type: "Account::Depository",
balance: 200,
subtype: "checking",
start_balance: 100,
start_date: 10.days.ago
}
}
new_valuation = Valuation.order(:created_at).last
assert new_valuation.value == balance
assert new_valuation.date == start_date
assert_equal "New account created successfully", flash[:notice]
assert_redirected_to account_url(Account.order(:created_at).last)
end
end
end