From f775d74cfd67d7c6110c293259f6dd60165b8c55 Mon Sep 17 00:00:00 2001 From: Marco Colli Date: Wed, 24 Dec 2014 11:49:35 +0100 Subject: [PATCH 1/2] Add failing test --- spec/controllers/services_controller_spec.rb | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index 1dd5396c6..d7bd50e92 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -8,7 +8,7 @@ describe ServicesController, :type => :controller do let(:omniauth_auth) do { 'provider' => 'facebook', 'uid' => '2', - 'info' => { 'nickname' => 'grimmin' }, + 'info' => { 'nickname' => 'grimmin', 'image' => 'http://graph.facebook.com/2/picture' }, 'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" }} end let(:user) { alice } @@ -46,6 +46,15 @@ describe ServicesController, :type => :controller do expect(user.reload.services.first.class.name).to eq("Services::Facebook") end + context "when the user hasn't got a profile photo on Diaspora" do + before { user.person.profile.update_attribute :image_url, nil } + + it "imports the profile photo from the service" do + expect(Workers::FetchProfilePhoto).to receive(:perform_async) + post :create, :provider => 'facebook' + end + end + context 'when service exists with the same uid' do before { Services::Twitter.create!(uid: omniauth_auth['uid'], user_id: user.id) } From 8dea4b5fd90f66be54a17f6bfd5c2bc3380e0038 Mon Sep 17 00:00:00 2001 From: Marco Colli Date: Wed, 24 Dec 2014 11:52:12 +0100 Subject: [PATCH 2/2] Solve #5341 --- app/controllers/services_controller.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index 8baa56cfd..abfd50782 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -23,9 +23,9 @@ class ServicesController < ApplicationController service = Service.initialize_from_omniauth( omniauth_hash ) if current_user.services << service - current_user.update_profile_with_omniauth( service.info ) - - fetch_photo(service) if no_profile_image? + no_profile_image_before_update = no_profile_image? + current_user.update_profile_with_omniauth(service.info) + fetch_photo(service) if no_profile_image_before_update flash[:notice] = I18n.t 'services.create.success' else