From c2e58b6b85977af40cedc4f093f20c38d6451bec Mon Sep 17 00:00:00 2001 From: Robin Ward Date: Thu, 13 Feb 2020 14:00:30 -0500 Subject: [PATCH] FIX: Don't remove the topic image if posts don't have them --- lib/cooked_post_processor.rb | 2 +- spec/components/cooked_post_processor_spec.rb | 17 +++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/cooked_post_processor.rb b/lib/cooked_post_processor.rb index b5f044e6658..9846c9e0bb2 100644 --- a/lib/cooked_post_processor.rb +++ b/lib/cooked_post_processor.rb @@ -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 diff --git a/spec/components/cooked_post_processor_spec.rb b/spec/components/cooked_post_processor_spec.rb index f5ba4d386a4..5406d146df5 100644 --- a/spec/components/cooked_post_processor_spec.rb +++ b/spec/components/cooked_post_processor_spec.rb @@ -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