mirror of
https://github.com/maybe-finance/maybe.git
synced 2025-07-24 07:39:39 +02:00
Add scope to filter transactions from active accounts (#1810)
* Add scope to filter transactions from active accounts * Add test for transfer match candidates with active accounts * Refactor active account filtering for transactions and entries
This commit is contained in:
parent
cf014bc24f
commit
4aba9d1c0b
5 changed files with 69 additions and 1 deletions
|
@ -81,4 +81,27 @@ class Account::EntryTest < ActiveSupport::TestCase
|
|||
assert_equal 200, totals.expense_total
|
||||
assert_equal "USD", totals.currency
|
||||
end
|
||||
|
||||
test "active scope only returns entries from active, non-scheduled-for-deletion accounts" do
|
||||
# Create transactions for all account types
|
||||
active_transaction = create_transaction(account: accounts(:depository), name: "Active transaction")
|
||||
inactive_transaction = create_transaction(account: accounts(:credit_card), name: "Inactive transaction")
|
||||
deletion_transaction = create_transaction(account: accounts(:investment), name: "Scheduled for deletion transaction")
|
||||
|
||||
# Update account statuses
|
||||
accounts(:credit_card).update!(is_active: false)
|
||||
accounts(:investment).update!(scheduled_for_deletion: true)
|
||||
|
||||
# Test the scope
|
||||
active_entries = Account::Entry.active
|
||||
|
||||
# Should include entry from active account
|
||||
assert_includes active_entries, active_transaction
|
||||
|
||||
# Should not include entry from inactive account
|
||||
assert_not_includes active_entries, inactive_transaction
|
||||
|
||||
# Should not include entry from account scheduled for deletion
|
||||
assert_not_includes active_entries, deletion_transaction
|
||||
end
|
||||
end
|
||||
|
|
|
@ -99,4 +99,43 @@ class AccountTest < ActiveSupport::TestCase
|
|||
@account.auto_match_transfers!
|
||||
end
|
||||
end
|
||||
|
||||
test "transfer_match_candidates only matches between active accounts" do
|
||||
active_account = accounts(:depository)
|
||||
another_active_account = accounts(:credit_card)
|
||||
inactive_account = accounts(:investment)
|
||||
inactive_account.update!(is_active: false)
|
||||
|
||||
# Create matching transactions
|
||||
active_inflow = active_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: -100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
active_outflow = another_active_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: 100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
inactive_outflow = inactive_account.entries.create!(
|
||||
date: Date.current,
|
||||
amount: 100,
|
||||
currency: "USD",
|
||||
name: "Test transfer",
|
||||
entryable: Account::Transaction.new
|
||||
)
|
||||
|
||||
# Should find matches between active accounts
|
||||
candidates = active_account.transfer_match_candidates
|
||||
assert_includes candidates.map(&:outflow_transaction_id), active_outflow.entryable_id
|
||||
|
||||
# Should not match with inactive account
|
||||
assert_not_includes candidates.map(&:outflow_transaction_id), inactive_outflow.entryable_id
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue