@@ -294,18 +294,20 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
294
294
295
295
test "updating an existing record with attachments when appending on assign" do
296
296
append_on_assign do
297
- @user . highlights . attach create_blob ( filename : "funky.jpg" ) , create_blob ( filename : "town.jpg" )
297
+ assert_deprecated do
298
+ @user . highlights . attach create_blob ( filename : "funky.jpg" ) , create_blob ( filename : "town.jpg" )
298
299
299
- assert_difference -> { @user . reload . highlights . count } , +2 do
300
- @user . update! highlights : [ create_blob ( filename : "whenever.jpg" ) , create_blob ( filename : "wherever.jpg" ) ]
301
- end
300
+ assert_difference -> { @user . reload . highlights . count } , +2 do
301
+ @user . update! highlights : [ create_blob ( filename : "whenever.jpg" ) , create_blob ( filename : "wherever.jpg" ) ]
302
+ end
302
303
303
- assert_no_difference -> { @user . reload . highlights . count } do
304
- @user . update! highlights : [ ]
305
- end
304
+ assert_no_difference -> { @user . reload . highlights . count } do
305
+ @user . update! highlights : [ ]
306
+ end
306
307
307
- assert_no_difference -> { @user . reload . highlights . count } do
308
- @user . update! highlights : nil
308
+ assert_no_difference -> { @user . reload . highlights . count } do
309
+ @user . update! highlights : nil
310
+ end
309
311
end
310
312
end
311
313
end
@@ -760,20 +762,22 @@ def highlights
760
762
761
763
test "successfully attaches new blobs and destroys attachments marked for destruction via nested attributes" do
762
764
append_on_assign do
763
- town_blob = create_blob ( filename : "town.jpg" )
764
- @user . highlights . attach ( town_blob )
765
- @user . reload
766
-
767
- racecar_blob = fixture_file_upload ( "racecar.jpg" )
768
- attachment_id = town_blob . attachments . find_by! ( record : @user ) . id
769
- @user . update (
770
- highlights : [ racecar_blob ] ,
771
- highlights_attachments_attributes : [ { id : attachment_id , _destroy : true } ]
772
- )
773
-
774
- assert @user . reload . highlights . attached?
775
- assert_equal 1 , @user . highlights . count
776
- assert_equal "racecar.jpg" , @user . highlights . blobs . first . filename . to_s
765
+ assert_deprecated do
766
+ town_blob = create_blob ( filename : "town.jpg" )
767
+ @user . highlights . attach ( town_blob )
768
+ @user . reload
769
+
770
+ racecar_blob = fixture_file_upload ( "racecar.jpg" )
771
+ attachment_id = town_blob . attachments . find_by! ( record : @user ) . id
772
+ @user . update (
773
+ highlights : [ racecar_blob ] ,
774
+ highlights_attachments_attributes : [ { id : attachment_id , _destroy : true } ]
775
+ )
776
+
777
+ assert @user . reload . highlights . attached?
778
+ assert_equal 1 , @user . highlights . count
779
+ assert_equal "racecar.jpg" , @user . highlights . blobs . first . filename . to_s
780
+ end
777
781
end
778
782
end
779
783
0 commit comments