2021-10-29 10:58:05 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::PullUserProfileHotlinkedImages do
|
2023-11-09 17:47:59 -05:00
|
|
|
fab!(:user)
|
2021-10-29 10:58:05 -04:00
|
|
|
|
|
|
|
let(:image_url) { "http://wiki.mozilla.org/images/2/2e/Longcat1.png" }
|
|
|
|
let(:png) do
|
|
|
|
Base64.decode64(
|
|
|
|
"R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw==",
|
|
|
|
)
|
2023-01-09 06:18:21 -05:00
|
|
|
end
|
2021-10-29 10:58:05 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
stub_request(:get, image_url).to_return(body: png, headers: { "Content-Type" => "image/png" })
|
|
|
|
SiteSetting.download_remote_images_to_local = true
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "#execute" do
|
|
|
|
before { stub_image_size }
|
|
|
|
|
|
|
|
it "replaces images" do
|
|
|
|
user.user_profile.update!(bio_raw: "![](#{image_url})")
|
|
|
|
expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.to change {
|
|
|
|
Upload.count
|
|
|
|
}.by(1)
|
|
|
|
expect(user.user_profile.reload.bio_cooked).to include(Upload.last.url)
|
|
|
|
end
|
2022-05-24 06:52:13 -04:00
|
|
|
|
|
|
|
it "handles nil bio" do
|
2022-07-19 10:03:03 -04:00
|
|
|
expect { Jobs::PullUserProfileHotlinkedImages.new.execute(user_id: user.id) }.not_to change {
|
|
|
|
Upload.count
|
|
|
|
}
|
2022-05-24 06:52:13 -04:00
|
|
|
expect(user.user_profile.reload.bio_cooked).to eq(nil)
|
|
|
|
end
|
2021-10-29 10:58:05 -04:00
|
|
|
end
|
|
|
|
end
|