A platform for community discussion. Free, open, simple.
DEV: Refactor specs for `Jobs::PullHotlinkedImages`.
Guo Xiang Tan3b4432f2586a
diff --git a/spec/jobs/pull_hotlinked_images_spec.rb b/spec/jobs/pull_hotlinked_images_spec.rbindex f87bc9ba93b..962699ff63d 100644--- a/spec/jobs/pull_hotlinked_images_spec.rb+++ b/spec/jobs/pull_hotlinked_images_spec.rb@@ -15,14 +15,29 @@ describe Jobs::PullHotlinkedImages dostub_request(:get, image_url).to_return(body: png, headers: { "Content-Type" => "image/png" })stub_request(:get, broken_image_url).to_return(status: 404)stub_request(:get, large_image_url).to_return(body: large_png, headers: { "Content-Type" => "image/png" })++ stub_request(+ :get,+ "#{Discourse.base_url}/uploads/default/original/1X/f59ea56fe8ebe42048491d43a19d9f34c5d0f8dc.gif"+ )++ stub_request(+ :get,+ "#{Discourse.base_url}/uploads/default/original/1X/c530c06cf89c410c0355d7852644a73fc3ec8c04.png"+ )+SiteSetting.crawl_images = trueSiteSetting.download_remote_images_to_local = trueSiteSetting.max_image_size_kb = 2SiteSetting.download_remote_images_threshold = 0end- describe "#nochange" do- it 'does saves nothing if there are no large images to pull' do+ describe '#execute' do+ before do+ Jobs.run_immediately!+ end++ it 'does nothing if there are no large images to pull' dopost = Fabricate(:post, raw: 'bob bob')orig = post.updated_at@@ -30,13 +45,6 @@ describe Jobs::PullHotlinkedImages doJobs::PullHotlinkedImages.new.execute(post_id: post.id)expect(orig).to be_within(1.second).of(post.reload.updated_at)end- end-- describe '#execute' do- before do- Jobs.run_immediately!- FastImage.expects(:size).returns([100, 100]).at_least_once- endit 'replaces images' dopost = Fabricate(:post, raw: "<img src='#{image_url}'>")