diff options
author | George Claghorn <george@basecamp.com> | 2018-07-11 22:09:23 -0400 |
---|---|---|
committer | George Claghorn <george@basecamp.com> | 2018-07-11 22:09:23 -0400 |
commit | 16f435f9313daa9e00dad25e2bcf95e30ad736ed (patch) | |
tree | 8ecb3ed5d27daf09a3ef533ff36667ba4565e21b | |
parent | a1735a0dde6f6efa4cda6347da71a056740da1d3 (diff) | |
download | rails-16f435f9313daa9e00dad25e2bcf95e30ad736ed.tar.gz rails-16f435f9313daa9e00dad25e2bcf95e30ad736ed.tar.bz2 rails-16f435f9313daa9e00dad25e2bcf95e30ad736ed.zip |
Discard ActiveStorage::PurgeJobs for missing blobs
-rw-r--r-- | activestorage/app/jobs/active_storage/purge_job.rb | 2 | ||||
-rw-r--r-- | activestorage/test/jobs/purge_job_test.rb | 27 |
2 files changed, 29 insertions, 0 deletions
diff --git a/activestorage/app/jobs/active_storage/purge_job.rb b/activestorage/app/jobs/active_storage/purge_job.rb index 95ae7d0c30..fa15e0451d 100644 --- a/activestorage/app/jobs/active_storage/purge_job.rb +++ b/activestorage/app/jobs/active_storage/purge_job.rb @@ -2,6 +2,8 @@ # Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later. class ActiveStorage::PurgeJob < ActiveStorage::BaseJob + discard_on ActiveRecord::RecordNotFound + def perform(blob) blob.purge end diff --git a/activestorage/test/jobs/purge_job_test.rb b/activestorage/test/jobs/purge_job_test.rb new file mode 100644 index 0000000000..251022a96f --- /dev/null +++ b/activestorage/test/jobs/purge_job_test.rb @@ -0,0 +1,27 @@ +# frozen_string_literal: true + +require "test_helper" +require "database/setup" + +class ActiveStorage::PurgeJobTest < ActiveJob::TestCase + setup { @blob = create_blob } + + test "purges" do + assert_difference -> { ActiveStorage::Blob.count }, -1 do + ActiveStorage::PurgeJob.perform_now @blob + end + + assert_not ActiveStorage::Blob.exists?(@blob.id) + assert_not ActiveStorage::Blob.service.exist?(@blob.key) + end + + test "ignores missing blob" do + @blob.purge + + perform_enqueued_jobs do + assert_nothing_raised do + ActiveStorage::PurgeJob.perform_later @blob + end + end + end +end |