2017-01-16 18:50:07 +08:00
|
|
|
require 'rails_helper'
|
|
|
|
require 'jobs/regular/pull_hotlinked_images'
|
|
|
|
|
|
|
|
describe Jobs::PullHotlinkedImages do
|
|
|
|
|
2017-01-28 05:16:57 +08:00
|
|
|
before do
|
|
|
|
png = Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==")
|
2017-04-15 12:11:02 +08:00
|
|
|
stub_request(:get, "http://wiki.mozilla.org/images/2/2e/Longcat1.png").to_return(body: png)
|
2017-05-26 15:19:09 +08:00
|
|
|
stub_request(:head, "http://wiki.mozilla.org/images/2/2e/Longcat1.png")
|
2017-01-28 05:16:57 +08:00
|
|
|
SiteSetting.download_remote_images_to_local = true
|
2017-04-15 12:11:02 +08:00
|
|
|
FastImage.expects(:size).returns([100, 100]).at_least_once
|
2017-01-28 05:16:57 +08:00
|
|
|
end
|
2017-01-16 18:50:07 +08:00
|
|
|
|
|
|
|
it 'replaces image src' do
|
|
|
|
post = Fabricate(:post, raw: "<img src='http://wiki.mozilla.org/images/2/2e/Longcat1.png'>")
|
|
|
|
|
2017-05-12 10:31:31 +08:00
|
|
|
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
|
2017-01-16 18:50:07 +08:00
|
|
|
post.reload
|
|
|
|
|
|
|
|
expect(post.raw).to match(/^<img src='\/uploads/)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'replaces image src without protocol' do
|
|
|
|
post = Fabricate(:post, raw: "<img src='//wiki.mozilla.org/images/2/2e/Longcat1.png'>")
|
|
|
|
|
|
|
|
Jobs::PullHotlinkedImages.new.execute(post_id: post.id)
|
|
|
|
post.reload
|
|
|
|
|
|
|
|
expect(post.raw).to match(/^<img src='\/uploads/)
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|