discourse/spec/models/user_avatar_spec.rb
Sam 5b3cd3fac9 FEATURE: Import facebook avatars when logging in via facebook
FIX: warning about popup dimensions when using facebook login

Rules are:

- On account creation we always import
- If you already have an avatar uploaded, nothing is changed
- If you have no avatar uploaded, we upload from facebook on login
- If you have no avatar uploaded, we select facebook unless gravatar already selected

This also fixes SSO issues where on account creation accounts had missing avatar uploads
2016-09-19 15:10:23 +10:00

50 lines
1.4 KiB
Ruby

require 'rails_helper'
describe UserAvatar do
let(:avatar){
user = Fabricate(:user)
user.create_user_avatar!
}
it 'can update gravatars' do
temp = Tempfile.new('test')
temp.binmode
# tiny valid png
temp.write(Base64.decode64("R0lGODlhAQABALMAAAAAAIAAAACAAICAAAAAgIAAgACAgMDAwICAgP8AAAD/AP//AAAA//8A/wD//wBiZCH5BAEAAA8ALAAAAAABAAEAAAQC8EUAOw=="))
temp.rewind
FileHelper.expects(:download).returns(temp)
avatar.update_gravatar!
temp.unlink
expect(avatar.gravatar_upload).not_to eq(nil)
end
context '#import_url_for_user' do
it 'creates user_avatar record if missing' do
user = Fabricate(:user)
user.user_avatar.destroy
user.reload
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
UserAvatar.import_url_for_user("logo.png", user)
user.reload
expect(user.uploaded_avatar_id).not_to eq(nil)
expect(user.user_avatar.custom_upload_id).to eq(user.uploaded_avatar_id)
end
it 'can leave gravatar alone' do
user = Fabricate(:user, uploaded_avatar_id: 1)
user.user_avatar.update_columns(gravatar_upload_id: 1)
FileHelper.stubs(:download).returns(file_from_fixtures("logo.png"))
UserAvatar.import_url_for_user("logo.png", user, override_gravatar: false)
user.reload
expect(user.uploaded_avatar_id).to eq(1)
expect(user.user_avatar.custom_upload_id).not_to eq(nil)
end
end
end