diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index 5a6ab648a59..83c9705d839 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -15,6 +15,7 @@ module Jobs post = Post.find_by(id: @post_id) return if post.blank? + return if post.topic.blank? raw = post.raw.dup start_raw = raw.dup diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rb index adb7a56d7eb..64ed3f3b7b1 100644 --- a/spec/jobs/pull_hotlinked_images_spec.rb +++ b/spec/jobs/pull_hotlinked_images_spec.rb @@ -42,6 +42,15 @@ describe Jobs::PullHotlinkedImages do Jobs.run_immediately! end + it 'does nothing if topic has been deleted' do + post = Fabricate(:post, raw: "") + post.topic.destroy! + + expect do + Jobs::PullHotlinkedImages.new.execute(post_id: post.id) + end.to change { Upload.count }.by(0) + end + it 'does nothing if there are no large images to pull' do post = Fabricate(:post, raw: 'bob bob') orig = post.updated_at