FIX: Avoid pulling hotlinked images of post that have been deleted. (#11913)

This commit is contained in:
Alan Guo Xiang Tan 2021-02-03 13:45:07 +08:00 committed by GitHub
parent 3744e49190
commit 0cc178d58b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 0 deletions

View File

@ -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

View File

@ -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: "<img src='#{image_url}'>")
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