FIX: Don't remove the topic image if posts don't have them

This commit is contained in:
Robin Ward 2020-02-13 14:00:30 -05:00
parent 4b46db6ea8
commit c2e58b6b85
2 changed files with 18 additions and 1 deletions

View File

@ -492,7 +492,7 @@ class CookedPostProcessor
img = extract_images_for_post.first
if img.blank?
@post.update_column(:image_url, nil) if @post.image_url
@post.topic.update_column(:image_url, nil) if @post.topic.image_url
@post.topic.update_column(:image_url, nil) if @post.topic.image_url && @post.is_first_post?
return
end

View File

@ -789,6 +789,23 @@ describe CookedPostProcessor do
expect(post.topic.image_url).not_to be_present
expect(post.image_url).not_to be_present
end
it "won't remove the original image if another post doesn't have an image" do
FastImage.stubs(:size)
topic = post.topic
cpp.post_process
topic.reload
expect(topic.image_url).to be_present
expect(post.image_url).to be_present
post = Fabricate(:post, topic: topic, raw: "this post doesn't have an image")
CookedPostProcessor.new(post).post_process
topic.reload
expect(post.topic.image_url).to be_present
expect(post.image_url).to be_blank
end
end
context "post image" do