FIX: Remove onebox src from `Jobs::PullHotlinkedImages`.

The test that was added is incorrect because the post was not cooked.
This commit is contained in:
Guo Xiang Tan 2019-06-14 09:21:25 +08:00
parent 457be89445
commit c9db897777
2 changed files with 2 additions and 18 deletions

View File

@ -71,6 +71,7 @@ module Jobs
filename = File.basename(URI.parse(src).path)
filename << File.extname(hotlinked.path) unless filename["."]
upload = UploadCreator.new(hotlinked, filename, origin: src).create_for(post.user_id)
if upload.persisted?
downloaded_urls[src] = upload.url
downloaded_images[remove_scheme(src)] = upload.id
@ -148,7 +149,7 @@ module Jobs
def extract_images_from(html)
doc = Nokogiri::HTML::fragment(html)
doc.css("img[src], a.lightbox[href], a.onebox[href]") -
doc.css("img[src], a.lightbox[href]") -
doc.css("img.avatar") -
doc.css(".lightbox img[src]")
end

View File

@ -98,23 +98,6 @@ describe Jobs::PullHotlinkedImages do
expect(post.uploads).to contain_exactly(upload)
end
it 'replaces direct links' do
post = Fabricate(:post, raw: <<~MD)
#{image_url}
#{image_url}
MD
expect { Jobs::PullHotlinkedImages.new.execute(post_id: post.id) }
.to change { Upload.count }.by(1)
post.reload
expect(post.raw).to eq(<<~MD.chomp)
![](#{Upload.last.short_url})
![](#{Upload.last.short_url})
MD
end
it 'replaces markdown image' do
post = Fabricate(:post, raw: <<~MD)
[![some test](#{image_url})](https://somelink.com)