2019-04-30 08:27:42 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2015-10-11 17:41:23 +08:00
|
|
|
require 'rails_helper'
|
2014-12-16 05:10:27 +08:00
|
|
|
|
|
|
|
describe Jobs::UpdateGravatar do
|
2020-09-03 10:12:24 +08:00
|
|
|
fab!(:user) { Fabricate(:user) }
|
|
|
|
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=="))
|
|
|
|
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
|
|
|
|
|
|
|
|
expect { user.refresh_avatar }
|
|
|
|
.to change { Jobs::UpdateGravatar.jobs.count }.by(0)
|
|
|
|
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
|