FIX: Onebox images are not downloaded locally without css class

This commit is contained in:
Vinoth Kannan 2018-08-01 02:51:02 +05:30
parent 4b166cccc1
commit 6aee22b88f
2 changed files with 19 additions and 1 deletions

View File

@ -193,7 +193,7 @@ class CookedPostProcessor
end
def oneboxed_images
@doc.css(".onebox-body img, .onebox img")
@doc.css(".onebox-body img, .onebox img, img.onebox")
end
def limit_size!(img)

View File

@ -513,6 +513,24 @@ describe CookedPostProcessor do
expect(cpp).to be_dirty
expect(cpp.html).to match_html "<div>GANGNAM STYLE</div>"
end
it "replaces downloaded onebox image" do
url = 'https://image.com/my-avatar'
image_url = 'https://image.com/avatar.png'
Oneboxer.stubs(:onebox).with(url, anything).returns("<img class='onebox' src='#{image_url}' />")
post = Fabricate(:post, raw: url)
upload = Fabricate(:upload, url: "https://test.s3.amazonaws.com/something.png")
post.custom_fields[Post::DOWNLOADED_IMAGES] = { "//image.com/avatar.png": upload.id }
post.save_custom_fields
cpp = CookedPostProcessor.new(post, invalidate_oneboxes: true)
cpp.post_process_oneboxes
expect(cpp.doc.to_s).to eq("<p><img class=\"onebox\" src=\"#{upload.url}\" width=\"\" height=\"\"></p>")
end
end
context ".post_process_oneboxes removes nofollow if add_rel_nofollow_to_user_content is disabled" do