diff --git a/lib/topic_view.rb b/lib/topic_view.rb index 1c2ed0e7b0..b242d03503 100644 --- a/lib/topic_view.rb +++ b/lib/topic_view.rb @@ -301,8 +301,8 @@ class TopicView end def image_url - url = desired_post&.image_url if @post_number > 1 - url || @topic.image_url + return @topic.image_url if @post_number == 1 + desired_post&.image_url end def filter_posts(opts = {}) diff --git a/spec/lib/topic_view_spec.rb b/spec/lib/topic_view_spec.rb index 927518bd00..7282eca535 100644 --- a/spec/lib/topic_view_spec.rb +++ b/spec/lib/topic_view_spec.rb @@ -895,9 +895,9 @@ RSpec.describe TopicView do post1.update_column(:image_upload_id, op_upload.id) end - it "uses the topic image as a fallback when posts have no image" do + it "uses the topic image for op and posts image when they have one" do expect(topic_view_for_post(1).image_url).to end_with(op_upload.url) - expect(topic_view_for_post(2).image_url).to end_with(op_upload.url) + expect(topic_view_for_post(2).image_url).to eq(nil) expect(topic_view_for_post(3).image_url).to end_with(post3_upload.url) end end