@@ -222,6 +222,28 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
222222 assert_equal [ tag . title ] , @response . parsed_body [ "tags" ]
223223 end
224224
225+ test "create as JSON with nonexistent tag_ids returns not found" do
226+ assert_no_difference -> { Card . count } do
227+ post board_cards_path ( boards ( :writebook ) ) ,
228+ params : { card : { title : "Tagged card" , tag_ids : [ "does-not-exist" ] } } ,
229+ as : :json
230+ end
231+
232+ assert_response :not_found
233+ end
234+
235+ test "create as JSON with foreign-account tag_ids returns not found" do
236+ foreign_tag = accounts ( :initech ) . tags . create! ( title : "foreign" )
237+
238+ assert_no_difference -> { Card . count } do
239+ post board_cards_path ( boards ( :writebook ) ) ,
240+ params : { card : { title : "Tagged card" , tag_ids : [ foreign_tag . id ] } } ,
241+ as : :json
242+ end
243+
244+ assert_response :not_found
245+ end
246+
225247 test "create as JSON with custom created_at" do
226248 custom_time = Time . utc ( 2024 , 1 , 15 , 10 , 30 , 0 )
227249
@@ -319,6 +341,16 @@ class CardsControllerTest < ActionDispatch::IntegrationTest
319341 assert_equal [ tag . title ] , @response . parsed_body [ "tags" ]
320342 end
321343
344+ test "update as JSON with foreign-account tag_ids returns not found" do
345+ card = cards ( :logo )
346+ foreign_tag = accounts ( :initech ) . tags . create! ( title : "foreign" )
347+
348+ put card_path ( card , format : :json ) , params : { card : { tag_ids : [ foreign_tag . id ] } }
349+
350+ assert_response :not_found
351+ assert_equal [ tags ( :web ) ] , card . reload . tags
352+ end
353+
322354 test "update as JSON with description and tag_ids busts the card cache key" do
323355 card = cards ( :logo )
324356 original_cache_key = card . cache_key_with_version
0 commit comments