2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-28 10:27:38 +08:00
|
|
|
RSpec.describe Jobs::UpdateGravatar do
|
2023-11-10 06:47:59 +08:00
|
|
|
fab!(:user)
|
2020-09-03 10:12:24 +08:00
|
|
|
let(:temp) { Tempfile.new("test") }
|
|
|
|
fab!(:upload) { Fabricate(:upload, user: user) }
|
|
|
|
let(:avatar) { user.create_user_avatar! }
|
2014-12-16 05:10:27 +08:00
|
|
|
|
|
|
|
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
2020-09-03 10:12:24 +08:00
|
|
|
temp.binmode
|
|
|
|
# tiny valid png
|
|
|
|
temp.write(
|
|
|
|
Base64.decode64(
|
|
|
|
"iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg==",
|
2023-01-09 19:18:21 +08:00
|
|
|
),
|
2020-09-03 10:12:24 +08:00
|
|
|
)
|
|
|
|
temp.rewind
|
|
|
|
FileHelper.expects(:download).returns(temp)
|
|
|
|
|
|
|
|
Jobs.run_immediately!
|
|
|
|
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
|
|
|
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
2014-12-16 05:10:27 +08:00
|
|
|
|
|
|
|
SiteSetting.automatically_download_gravatars = true
|
|
|
|
|
|
|
|
user.refresh_avatar
|
|
|
|
user.reload
|
|
|
|
|
2020-09-03 10:12:24 +08:00
|
|
|
expect(user.uploaded_avatar_id).to_not eq(nil)
|
2014-12-31 22:55:03 +08:00
|
|
|
expect(user.uploaded_avatar_id).to eq(user.user_avatar.gravatar_upload_id)
|
2020-09-03 10:12:24 +08:00
|
|
|
|
|
|
|
temp.unlink
|
2014-12-16 05:10:27 +08:00
|
|
|
end
|
|
|
|
|
2020-09-03 10:12:24 +08:00
|
|
|
it "does not enqueue a job when user is missing their email" do
|
|
|
|
user.primary_email.destroy
|
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
|
|
|
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
|
|
|
|
|
|
|
SiteSetting.automatically_download_gravatars = true
|
|
|
|
|
2022-07-19 22:03:03 +08:00
|
|
|
expect { user.refresh_avatar }.not_to change { Jobs::UpdateGravatar.jobs.count }
|
2020-09-03 10:12:24 +08:00
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
|
|
|
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
|
|
|
end
|
2014-12-16 05:10:27 +08:00
|
|
|
end
|