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

Bulk transaction deletion (#845)

* Clean up transaction show view, add delete button

* Clean up tailwind global styles, add switch

* Bulk deletion controller and tests

* Normalize translations

* Add bulk deletion button and form
This commit is contained in:
Zach Gollwitzer 2024-06-07 16:56:30 -04:00 committed by GitHub
parent 115f792198
commit d3f9be15f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 225 additions and 95 deletions

View file

@ -97,13 +97,16 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
test "incomes are negative" do
assert_difference("Transaction.count") do
post transactions_url, params: { transaction: {
nature: "income",
account_id: @transaction.account_id,
amount: @transaction.amount,
currency: @transaction.currency,
date: @transaction.date,
name: @transaction.name } }
post transactions_url, params: {
transaction: {
nature: "income",
account_id: @transaction.account_id,
amount: @transaction.amount,
currency: @transaction.currency,
date: @transaction.date,
name: @transaction.name
}
}
end
assert_redirected_to transactions_url
@ -122,7 +125,8 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
amount: @transaction.amount,
currency: @transaction.currency,
date: @transaction.date,
name: @transaction.name
name: @transaction.name,
tag_ids: [ Tag.first.id, Tag.second.id ]
}
}
@ -138,4 +142,40 @@ class TransactionsControllerTest < ActionDispatch::IntegrationTest
assert_redirected_to transactions_url
assert_enqueued_with(job: AccountSyncJob)
end
test "can destroy many transactions at once" do
delete_count = 10
assert_difference("Transaction.count", -delete_count) do
post bulk_delete_transactions_url, params: { bulk_delete: { transaction_ids: @recent_transactions.first(delete_count).pluck(:id) } }
end
assert_redirected_to transactions_url
assert_equal "10 transactions deleted", flash[:notice]
end
test "can update many transactions at once" do
transactions = @user.family.transactions.ordered.limit(20)
transactions.each do |transaction|
transaction.update! excluded: false, currency: "USD", category_id: Transaction::Category.first.id
end
post bulk_update_transactions_url, params: {
bulk_update: {
transaction_ids: transactions.map(&:id),
excluded: true,
currency: "CAD",
category_id: Transaction::Category.second.id
}
}
assert_redirected_to transactions_url
assert_equal "#{transactions.count} transactions updated", flash[:notice]
transactions.reload.each do |transaction|
assert transaction.excluded
assert_equal "CAD", transaction.currency
assert_equal Transaction::Category.second, transaction.category
end
end
end