diff options
author | George Claghorn <george@basecamp.com> | 2018-07-16 08:59:23 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-07-16 08:59:23 -0400 |
commit | 1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2 (patch) | |
tree | 8567738e99145d4d18fe9f25ab2356f8ad1fabfb /activestorage/test/models | |
parent | faa9a29fbbacc95e86c0ab3056a4443aa94e5530 (diff) | |
download | rails-1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2.tar.gz rails-1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2.tar.bz2 rails-1d13de4e39aa8045d1829ebbec5f7a8a192ed4b2.zip |
Test removing attachments via #attach
Diffstat (limited to 'activestorage/test/models')
-rw-r--r-- | activestorage/test/models/attached/many_test.rb | 40 | ||||
-rw-r--r-- | activestorage/test/models/attached/one_test.rb | 31 |
2 files changed, 59 insertions, 12 deletions
diff --git a/activestorage/test/models/attached/many_test.rb b/activestorage/test/models/attached/many_test.rb index fc89dae658..2a45829da8 100644 --- a/activestorage/test/models/attached/many_test.rb +++ b/activestorage/test/models/attached/many_test.rb @@ -195,21 +195,47 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase end end - test "successfully updating an existing record to remove dependent attachments" do + test "removing dependent attachments from an existing record" do [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| @user.highlights.attach blobs - perform_enqueued_jobs do - @user.update! highlights: [] + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.first ] do + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.second ] do + @user.highlights.attach [] + end end assert_not @user.highlights.attached? - assert_not ActiveStorage::Blob.service.exist?(blobs.first.key) - assert_not ActiveStorage::Blob.service.exist?(blobs.second.key) end end - test "successfully updating an existing record to remove independent attachments" do + test "removing independent attachments from an existing record" do + [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| + @user.vlogs.attach blobs + + assert_no_enqueued_jobs only: ActiveStorage::PurgeJob do + @user.vlogs.attach [] + end + + assert_not @user.vlogs.attached? + end + end + + test "updating an existing record to remove dependent attachments" do + [ create_blob(filename: "funky.jpg"), create_blob(filename: "town.jpg") ].tap do |blobs| + @user.highlights.attach blobs + + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.first ] do + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blobs.second ] do + @user.update! highlights: [] + end + end + + assert_not @user.highlights.attached? + end + end + + test "updating an existing record to remove independent attachments" do [ create_blob(filename: "funky.mp4"), create_blob(filename: "town.mp4") ].tap do |blobs| @user.vlogs.attach blobs @@ -218,8 +244,6 @@ class ActiveStorage::ManyAttachedTest < ActiveSupport::TestCase end assert_not @user.vlogs.attached? - assert ActiveStorage::Blob.service.exist?(blobs.first.key) - assert ActiveStorage::Blob.service.exist?(blobs.second.key) end end diff --git a/activestorage/test/models/attached/one_test.rb b/activestorage/test/models/attached/one_test.rb index 33f9122644..01caaf0b55 100644 --- a/activestorage/test/models/attached/one_test.rb +++ b/activestorage/test/models/attached/one_test.rb @@ -195,11 +195,35 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase end end - test "successfully updating an existing record to remove a dependent attachment" do + test "removing a dependent attachment from an existing record" do create_blob(filename: "funky.jpg").tap do |blob| @user.avatar.attach blob - perform_enqueued_jobs do + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blob ] do + @user.avatar.attach nil + end + + assert_not @user.avatar.attached? + end + end + + test "removing an independent attachment from an existing record" do + create_blob(filename: "funky.jpg").tap do |blob| + @user.cover_photo.attach blob + + assert_no_enqueued_jobs only: ActiveStorage::PurgeJob do + @user.cover_photo.attach nil + end + + assert_not @user.cover_photo.attached? + end + end + + test "updating an existing record to remove a dependent attachment" do + create_blob(filename: "funky.jpg").tap do |blob| + @user.avatar.attach blob + + assert_enqueued_with job: ActiveStorage::PurgeJob, args: [ blob ] do @user.update! avatar: nil end @@ -207,7 +231,7 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase end end - test "successfully updating an existing record to remove an independent attachment" do + test "updating an existing record to remove an independent attachment" do create_blob(filename: "funky.jpg").tap do |blob| @user.cover_photo.attach blob @@ -216,7 +240,6 @@ class ActiveStorage::OneAttachedTest < ActiveSupport::TestCase end assert_not @user.cover_photo.attached? - assert ActiveStorage::Blob.service.exist?(blob.key) end end |