diff --git a/app/controllers/services_controller.rb b/app/controllers/services_controller.rb index d7adac787ca683991fc80f8ab46254ee2f5017b8..25df66366a9c7e33a2f5f45d1871595cc0dccd55 100644 --- a/app/controllers/services_controller.rb +++ b/app/controllers/services_controller.rb @@ -1,5 +1,6 @@ # Copyright (c) 2010-2011, Diaspora Inc. This file is -# licensed under the Affero General Public License version 3 or later. See # the COPYRIGHT file. +# licensed under the Affero General Public License version 3 or later. See +# the COPYRIGHT file. class ServicesController < ApplicationController before_filter :authenticate_user! @@ -38,8 +39,8 @@ class ServicesController < ApplicationController if existing_service = Service.where(:type => service.type.to_s, :uid => service.uid).first flash[:error] << I18n.t('services.create.already_authorized', - :diaspora_id => existing_service.user.person.profile.diaspora_handle, - :service_name => provider.camelize ) + :diaspora_id => existing_service.user.person.profile.diaspora_handle, + :service_name => provider.camelize ) end end diff --git a/spec/controllers/services_controller_spec.rb b/spec/controllers/services_controller_spec.rb index a4c9172d626859840fcc0cc90ff4b501d1d2b833..fd11b2150c1857a6ab0638317f0ff0eebae0f68b 100644 --- a/spec/controllers/services_controller_spec.rb +++ b/spec/controllers/services_controller_spec.rb @@ -36,50 +36,48 @@ describe ServicesController do end describe '#create' do - it 'creates a new OmniauthService' do - request.env['omniauth.auth'] = omniauth_auth - lambda{ - post :create, :provider => 'twitter' - }.should change(@user.services, :count).by(1) - end - - it 'redirects to getting started if the user is getting started' do - @user.getting_started = true - request.env['omniauth.auth'] = omniauth_auth - post :create, :provider => 'twitter' - response.should redirect_to getting_started_path - end - - it 'redirects to services url' do - @user.getting_started = false - request.env['omniauth.auth'] = omniauth_auth - post :create, :provider => 'twitter' - response.should redirect_to services_url - end + context 'when not fetching a photo' do + before do + request.env['omniauth.auth'] = omniauth_auth + end - it 'creates a twitter service' do - Service.delete_all - @user.getting_started = false - request.env['omniauth.auth'] = omniauth_auth - post :create, :provider => 'twitter' - @user.reload.services.first.class.name.should == "Services::Twitter" - end + it 'creates a new OmniauthService' do + expect { + post :create, :provider => 'twitter' + }.to change(@user.services, :count).by(1) + end - it 'returns error if the service is connected with that uid' do - request.env['omniauth.auth'] = omniauth_auth + it 'redirects to getting started if the user is getting started' do + @user.getting_started = true + post :create, :provider => 'twitter' + response.should redirect_to getting_started_path + end - Services::Twitter.create!(:nickname => omniauth_auth["info"]['nickname'], - :access_token => omniauth_auth['credentials']['token'], - :access_secret => omniauth_auth['credentials']['secret'], - :uid => omniauth_auth['uid'], - :user => bob) + it 'redirects to services url if user is not getting started' do + @user.getting_started = false + post :create, :provider => 'twitter' + response.should redirect_to services_url + end - post :create, :provider => 'twitter' + it 'creates a twitter service' do + Service.delete_all + @user.getting_started = false + post :create, :provider => 'twitter' + @user.reload.services.first.class.name.should == "Services::Twitter" + end - flash[:error].include?(bob.person.profile.diaspora_handle).should be_true + it 'returns error if the user already a service with that uid' do + Services::Twitter.create!(:nickname => omniauth_auth["info"]['nickname'], + :access_token => omniauth_auth['credentials']['token'], + :access_secret => omniauth_auth['credentials']['secret'], + :uid => omniauth_auth['uid'], + :user => bob) + post :create, :provider => 'twitter' + flash[:error].include?(bob.person.profile.diaspora_handle).should be_true + end end - context "photo fetching" do + context 'when fetching a photo' do before do omniauth_auth omniauth_auth["info"].merge!({"image" => "https://service.com/fallback_lowres.jpg"})