@@ -456,6 +456,28 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
456
456
end
457
457
end
458
458
459
+ test "purging from the attachments relation" do
460
+ [ create_blob ( filename : "funky.jpg" ) , create_blob ( filename : "town.jpg" ) ] . tap do |blobs |
461
+ @user . highlights . attach blobs
462
+ assert @user . highlights . attached?
463
+
464
+ message = <<-MSG . squish
465
+ Calling `purge` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
466
+ To migrate to Rails 7.1's behavior call `purge` from `highlights` instead: `highlights.purge`.
467
+ MSG
468
+ assert_deprecated ( message ) do
469
+ assert_changes -> { @user . updated_at } do
470
+ @user . highlights_attachments . purge
471
+ end
472
+ end
473
+ assert_not @user . highlights . attached?
474
+ assert_not ActiveStorage ::Blob . exists? ( blobs . first . id )
475
+ assert_not ActiveStorage ::Blob . exists? ( blobs . second . id )
476
+ assert_not ActiveStorage ::Blob . service . exist? ( blobs . first . key )
477
+ assert_not ActiveStorage ::Blob . service . exist? ( blobs . second . key )
478
+ end
479
+ end
480
+
459
481
test "purging attachment with shared blobs" do
460
482
[
461
483
create_blob ( filename : "funky.jpg" ) ,
@@ -529,6 +551,31 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase
529
551
end
530
552
end
531
553
554
+ test "purging later from the attachments relation" do
555
+ [ create_blob ( filename : "funky.jpg" ) , create_blob ( filename : "town.jpg" ) ] . tap do |blobs |
556
+ @user . highlights . attach blobs
557
+ assert @user . highlights . attached?
558
+
559
+ message = <<-MSG . squish
560
+ Calling `purge_later` from `highlights_attachments` is deprecated and will be removed in Rails 7.1.
561
+ To migrate to Rails 7.1's behavior call `purge_later` from `highlights` instead: `highlights.purge_later`.
562
+ MSG
563
+ assert_deprecated ( message ) do
564
+ perform_enqueued_jobs do
565
+ assert_changes -> { @user . updated_at } do
566
+ @user . highlights_attachments . purge_later
567
+ end
568
+ end
569
+ end
570
+
571
+ assert_not @user . highlights . attached?
572
+ assert_not ActiveStorage ::Blob . exists? ( blobs . first . id )
573
+ assert_not ActiveStorage ::Blob . exists? ( blobs . second . id )
574
+ assert_not ActiveStorage ::Blob . service . exist? ( blobs . first . key )
575
+ assert_not ActiveStorage ::Blob . service . exist? ( blobs . second . key )
576
+ end
577
+ end
578
+
532
579
test "purging attachment later with shared blobs" do
533
580
[
534
581
create_blob ( filename : "funky.jpg" ) ,
0 commit comments