2014-05-22 03:37:02 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
describe UserAvatar do
|
|
|
|
let(:avatar){
|
|
|
|
user = Fabricate(:user)
|
|
|
|
user.create_user_avatar!
|
|
|
|
}
|
|
|
|
|
|
|
|
it 'can generate a system avatar' do
|
|
|
|
avatar.update_system_avatar!
|
|
|
|
avatar.system_upload.should_not be_nil
|
|
|
|
end
|
|
|
|
|
2014-05-27 21:50:49 -04:00
|
|
|
it 'corrects old system avatars on refresh' do
|
|
|
|
upload = Fabricate(:upload)
|
|
|
|
user = Fabricate(:user, uploaded_avatar_id: upload.id)
|
|
|
|
avatar = UserAvatar.create!(user_id: user.id, system_upload_id: upload.id)
|
|
|
|
avatar.update_system_avatar!
|
|
|
|
|
|
|
|
user.reload
|
|
|
|
user.uploaded_avatar_id.should_not == upload.id
|
|
|
|
avatar.system_upload_id.should == user.uploaded_avatar_id
|
|
|
|
end
|
|
|
|
|
2014-05-22 03:37:02 -04:00
|
|
|
it 'can update gravatars' do
|
|
|
|
temp = Tempfile.new('test')
|
2014-05-26 07:17:20 -04:00
|
|
|
temp.binmode
|
|
|
|
# tiny valid png
|
|
|
|
temp.write(Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw=="))
|
|
|
|
temp.rewind
|
2014-05-22 03:37:02 -04:00
|
|
|
FileHelper.expects(:download).returns(temp)
|
|
|
|
avatar.update_gravatar!
|
|
|
|
temp.unlink
|
|
|
|
avatar.gravatar_upload.should_not be_nil
|
|
|
|
end
|
|
|
|
end
|