2024-05-02 07:24:31 -06:00
|
|
|
require "test_helper"
|
|
|
|
|
2024-06-20 13:32:44 -04:00
|
|
|
class Category::DeletionsControllerTest < ActionDispatch::IntegrationTest
|
2024-05-02 07:24:31 -06:00
|
|
|
setup do
|
|
|
|
sign_in users(:family_admin)
|
2024-06-20 08:15:09 -04:00
|
|
|
@category = categories(:food_and_drink)
|
2024-05-02 07:24:31 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
test "new" do
|
2024-06-20 08:15:09 -04:00
|
|
|
get new_category_deletion_url(@category)
|
2024-05-02 07:24:31 -06:00
|
|
|
assert_response :success
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create with replacement" do
|
2024-06-20 08:15:09 -04:00
|
|
|
replacement_category = categories(:income)
|
2024-05-02 07:24:31 -06:00
|
|
|
|
|
|
|
assert_not_empty @category.transactions
|
|
|
|
|
2024-06-20 08:15:09 -04:00
|
|
|
assert_difference "Category.count", -1 do
|
2024-05-02 07:24:31 -06:00
|
|
|
assert_difference "replacement_category.transactions.count", @category.transactions.count do
|
2024-06-20 08:15:09 -04:00
|
|
|
post category_deletions_url(@category),
|
2024-05-02 07:24:31 -06:00
|
|
|
params: { replacement_category_id: replacement_category.id }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_redirected_to transactions_url
|
|
|
|
end
|
|
|
|
|
|
|
|
test "create without replacement" do
|
|
|
|
assert_not_empty @category.transactions
|
|
|
|
|
2024-06-20 08:15:09 -04:00
|
|
|
assert_difference "Category.count", -1 do
|
2025-04-14 11:40:34 -04:00
|
|
|
assert_difference "Transaction.where(category: nil).count", @category.transactions.count do
|
2024-06-20 08:15:09 -04:00
|
|
|
post category_deletions_url(@category)
|
2024-05-02 07:24:31 -06:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_redirected_to transactions_url
|
|
|
|
end
|
|
|
|
end
|