diff options
author | George Claghorn <george@basecamp.com> | 2018-03-05 17:01:31 -0500 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-03-05 17:01:31 -0500 |
commit | 9cc88043e70f927a3c8b151c862f6b3cb8b8a6f7 (patch) | |
tree | d3ccb0a4997b78dfc2151fe72d09f85980c41bd3 /activestorage/test | |
parent | 8228d12a43927a22d0ac9bd351d18f473d6a49ae (diff) | |
download | rails-9cc88043e70f927a3c8b151c862f6b3cb8b8a6f7.tar.gz rails-9cc88043e70f927a3c8b151c862f6b3cb8b8a6f7.tar.bz2 rails-9cc88043e70f927a3c8b151c862f6b3cb8b8a6f7.zip |
Fix purging dependent blobs when attachments aren't loaded
Diffstat (limited to 'activestorage/test')
-rw-r--r-- | activestorage/test/models/attachments_test.rb | 18 | ||||
-rw-r--r-- | activestorage/test/test_helper.rb | 2 |
2 files changed, 18 insertions, 2 deletions
diff --git a/activestorage/test/models/attachments_test.rb b/activestorage/test/models/attachments_test.rb index a5fcad1bab..36e76f2845 100644 --- a/activestorage/test/models/attachments_test.rb +++ b/activestorage/test/models/attachments_test.rb @@ -217,13 +217,20 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase avatar_key = @user.avatar.key perform_enqueued_jobs do - @user.destroy + @user.reload.destroy assert_nil ActiveStorage::Blob.find_by(key: avatar_key) assert_not ActiveStorage::Blob.service.exist?(avatar_key) end end + test "delete attachment for independent blob when record is destroyed" do + @user.cover_photo.attach create_blob(filename: "funky.jpg") + + @user.destroy + assert_not ActiveStorage::Attachment.exists?(record: @user, name: "cover_photo") + end + test "find with attached blob" do records = %w[alice bob].map do |name| User.create!(name: name).tap do |user| @@ -395,7 +402,7 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase highlight_keys = @user.highlights.collect(&:key) perform_enqueued_jobs do - @user.destroy + @user.reload.destroy assert_nil ActiveStorage::Blob.find_by(key: highlight_keys.first) assert_not ActiveStorage::Blob.service.exist?(highlight_keys.first) @@ -404,4 +411,11 @@ class ActiveStorage::AttachmentsTest < ActiveSupport::TestCase assert_not ActiveStorage::Blob.service.exist?(highlight_keys.second) end end + + test "delete attachments for independent blobs when the record is destroyed" do + @user.vlogs.attach create_blob(filename: "funky.mp4"), create_blob(filename: "wonky.mp4") + + @user.destroy + assert_not ActiveStorage::Attachment.exists?(record: @user, name: "vlogs") + end end diff --git a/activestorage/test/test_helper.rb b/activestorage/test/test_helper.rb index 9b5cd41335..2a8e153303 100644 --- a/activestorage/test/test_helper.rb +++ b/activestorage/test/test_helper.rb @@ -66,5 +66,7 @@ ActiveRecord::Base.send :include, GlobalID::Identification class User < ActiveRecord::Base has_one_attached :avatar has_one_attached :cover_photo, dependent: false + has_many_attached :highlights + has_many_attached :vlogs, dependent: false end |