Fix image width for feed location (#19321)

* Fix image width for feed location

* Fix typo
This commit is contained in:
Ben Halpern 2023-04-12 15:06:19 -04:00 committed by GitHub
parent 6e7957f1c0
commit 3b22dada38
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 1 deletions

View file

@ -142,6 +142,6 @@ class DisplayAd < ApplicationRecord
end
def prefix_width
placement_area.to_s == "post_comments" ? POST_WIDTH : SIDEBAR_WIDTH
placement_area.include?("sidebar") ? SIDEBAR_WIDTH : POST_WIDTH
end
end

View file

@ -117,6 +117,24 @@ RSpec.describe DisplayAd do
# Images::Optimizer.call(source, width: width)
end
it "uses sidebar width for sidebar location" do
image_url = "https://dummyimage.com/100x100"
allow(FastImage).to receive(:size)
allow(Images::Optimizer).to receive(:call).and_return(image_url)
image_md = "![Image description](#{image_url})<p style='margin-top:100px'>Hello <em>hey</em> Hey hey</p>"
create(:display_ad, body_markdown: image_md, placement_area: "post_sidebar")
expect(Images::Optimizer).to have_received(:call).with(image_url, width: DisplayAd::SIDEBAR_WIDTH)
end
it "uses post width for feed location" do
image_url = "https://dummyimage.com/100x100"
allow(FastImage).to receive(:size)
allow(Images::Optimizer).to receive(:call).and_return(image_url)
image_md = "![Image description](#{image_url})<p style='margin-top:100px'>Hello <em>hey</em> Hey hey</p>"
create(:display_ad, body_markdown: image_md, placement_area: "feed_second")
expect(Images::Optimizer).to have_received(:call).with(image_url, width: DisplayAd::POST_WIDTH)
end
it "keeps the same processed_html if markdown was not changed" do
display_ad = create(:display_ad)
html = display_ad.processed_html