Permalink
Browse files

Discard ActiveStorage::PurgeJobs for missing blobs

  • Loading branch information...
georgeclaghorn committed Jul 12, 2018
1 parent a1735a0 commit 16f435f9313daa9e00dad25e2bcf95e30ad736ed
Showing with 29 additions and 0 deletions.
  1. +2 −0 activestorage/app/jobs/active_storage/purge_job.rb
  2. +27 −0 activestorage/test/jobs/purge_job_test.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
@@ -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

0 comments on commit 16f435f

Please sign in to comment.