2019-04-29 20:27:42 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2022-07-27 22:27:38 -04:00
|
|
|
RSpec.describe Jobs::UpdateGravatar do
|
2020-09-02 22:12:24 -04:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
let(:temp) { Tempfile.new('test') }
|
|
|
|
fab!(:upload) { Fabricate(:upload, user: user) }
|
|
|
|
let(:avatar) { user.create_user_avatar! }
|
2014-12-15 16:10:27 -05:00
|
|
|
|
|
|
|
it "picks gravatar if system avatar is picked and gravatar was just downloaded" do
|
2020-09-02 22:12:24 -04:00
|
|
|
temp.binmode
|
|
|
|
# tiny valid png
|
|
|
|
temp.write(Base64.decode64("iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAACklEQVR4nGMAAQAABQABDQottAAAAABJRU5ErkJggg=="))
|
|
|
|
temp.rewind
|
|
|
|
FileHelper.expects(:download).returns(temp)
|
|
|
|
|
|
|
|
Jobs.run_immediately!
|
|
|
|
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
|
|
|
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
2014-12-15 16:10:27 -05:00
|
|
|
|
|
|
|
SiteSetting.automatically_download_gravatars = true
|
|
|
|
|
|
|
|
user.refresh_avatar
|
|
|
|
user.reload
|
|
|
|
|
2020-09-02 22:12:24 -04:00
|
|
|
expect(user.uploaded_avatar_id).to_not eq(nil)
|
2014-12-31 09:55:03 -05:00
|
|
|
expect(user.uploaded_avatar_id).to eq(user.user_avatar.gravatar_upload_id)
|
2020-09-02 22:12:24 -04:00
|
|
|
|
|
|
|
temp.unlink
|
2014-12-15 16:10:27 -05:00
|
|
|
end
|
|
|
|
|
2020-09-02 22:12:24 -04: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
|
|
|
|
|
|
|
|
expect { user.refresh_avatar }
|
2022-07-19 10:03:03 -04:00
|
|
|
.not_to change { Jobs::UpdateGravatar.jobs.count }
|
2020-09-02 22:12:24 -04:00
|
|
|
user.reload
|
|
|
|
|
|
|
|
expect(user.uploaded_avatar_id).to eq(nil)
|
|
|
|
expect(user.user_avatar.gravatar_upload_id).to eq(nil)
|
|
|
|
end
|
2014-12-15 16:10:27 -05:00
|
|
|
end
|