The personal finance app for everyone (by everyone)
Ruby
fix(tags): return 404 for missing or cross-family tag deletion (#2703)
pro3958150e6598461e
diff --git a/app/controllers/tag/deletions_controller.rb b/app/controllers/tag/deletions_controller.rbindex 5ec31a3d5a..c4b8d889bb 100644--- a/app/controllers/tag/deletions_controller.rb+++ b/app/controllers/tag/deletions_controller.rb@@ -13,10 +13,12 @@ class Tag::DeletionsController < ApplicationControllerprivatedef set_tag- @tag = Current.family.tags.find_by(id: params[:tag_id])+ @tag = Current.family.tags.find(params[:tag_id])enddef set_replacement_tag- @replacement_tag = Current.family.tags.find_by(id: params[:replacement_tag_id])+ if params[:replacement_tag_id].present?+ @replacement_tag = Current.family.tags.find(params[:replacement_tag_id])+ endendenddiff --git a/test/controllers/tag/deletions_controller_test.rb b/test/controllers/tag/deletions_controller_test.rbindex d51af30f94..2cf3da3072 100644--- a/test/controllers/tag/deletions_controller_test.rb+++ b/test/controllers/tag/deletions_controller_test.rb@@ -32,4 +32,22 @@ class Tag::DeletionsControllerTest < ActionDispatch::IntegrationTestpost tag_deletions_url(@tag)endend++ test "create with invalid or cross-family tag_id returns not found" do+ other_family_tag = families(:empty).tags.create!(name: "Other family tag")++ assert_no_difference -> { Tag.count } do+ post tag_deletions_url(tag_id: other_family_tag.id)+ end++ assert_response :not_found+ end++ test "create with invalid replacement_tag_id returns not found" do+ assert_no_difference -> { Tag.count } do+ post tag_deletions_url(@tag), params: { replacement_tag_id: "missing" }+ end++ assert_response :not_found+ endend