From 6c45b04a7399bb629bf17319dc3519a061d4d7a0 Mon Sep 17 00:00:00 2001 From: George Claghorn Date: Fri, 20 Jul 2018 11:18:37 -0400 Subject: Discard ActiveStorage::PurgeJobs on ActiveRecord::InvalidForeignKey --- activestorage/app/jobs/active_storage/purge_job.rb | 2 +- activestorage/test/jobs/purge_job_test.rb | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/activestorage/app/jobs/active_storage/purge_job.rb b/activestorage/app/jobs/active_storage/purge_job.rb index fa15e0451d..b021b5f2d0 100644 --- a/activestorage/app/jobs/active_storage/purge_job.rb +++ b/activestorage/app/jobs/active_storage/purge_job.rb @@ -2,7 +2,7 @@ # Provides asynchronous purging of ActiveStorage::Blob records via ActiveStorage::Blob#purge_later. class ActiveStorage::PurgeJob < ActiveStorage::BaseJob - discard_on ActiveRecord::RecordNotFound + discard_on ActiveRecord::RecordNotFound, ActiveRecord::InvalidForeignKey def perform(blob) blob.purge diff --git a/activestorage/test/jobs/purge_job_test.rb b/activestorage/test/jobs/purge_job_test.rb index 251022a96f..ed4100b78d 100644 --- a/activestorage/test/jobs/purge_job_test.rb +++ b/activestorage/test/jobs/purge_job_test.rb @@ -24,4 +24,14 @@ class ActiveStorage::PurgeJobTest < ActiveJob::TestCase end end end + + test "ignores attached blob" do + User.create! name: "DHH", avatar: @blob + + perform_enqueued_jobs do + assert_nothing_raised do + ActiveStorage::PurgeJob.perform_later @blob + end + end + end end -- cgit v1.2.3