Skip to content
Extraits de code Groupes Projets
Valider 872a96dc rédigé par Sarah Mei's avatar Sarah Mei
Parcourir les fichiers

Refactor services controller spec

parent ebfc3de8
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
# Copyright (c) 2010-2011, Diaspora Inc. This file is # 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 class ServicesController < ApplicationController
before_filter :authenticate_user! before_filter :authenticate_user!
...@@ -38,8 +39,8 @@ class ServicesController < ApplicationController ...@@ -38,8 +39,8 @@ class ServicesController < ApplicationController
if existing_service = Service.where(:type => service.type.to_s, :uid => service.uid).first if existing_service = Service.where(:type => service.type.to_s, :uid => service.uid).first
flash[:error] << I18n.t('services.create.already_authorized', flash[:error] << I18n.t('services.create.already_authorized',
:diaspora_id => existing_service.user.person.profile.diaspora_handle, :diaspora_id => existing_service.user.person.profile.diaspora_handle,
:service_name => provider.camelize ) :service_name => provider.camelize )
end end
end end
......
...@@ -36,50 +36,48 @@ describe ServicesController do ...@@ -36,50 +36,48 @@ describe ServicesController do
end end
describe '#create' do describe '#create' do
it 'creates a new OmniauthService' do context 'when not fetching a photo' do
request.env['omniauth.auth'] = omniauth_auth before do
lambda{ request.env['omniauth.auth'] = omniauth_auth
post :create, :provider => 'twitter' end
}.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
it 'creates a twitter service' do it 'creates a new OmniauthService' do
Service.delete_all expect {
@user.getting_started = false post :create, :provider => 'twitter'
request.env['omniauth.auth'] = omniauth_auth }.to change(@user.services, :count).by(1)
post :create, :provider => 'twitter' end
@user.reload.services.first.class.name.should == "Services::Twitter"
end
it 'returns error if the service is connected with that uid' do it 'redirects to getting started if the user is getting started' do
request.env['omniauth.auth'] = omniauth_auth @user.getting_started = true
post :create, :provider => 'twitter'
response.should redirect_to getting_started_path
end
Services::Twitter.create!(:nickname => omniauth_auth["info"]['nickname'], it 'redirects to services url if user is not getting started' do
:access_token => omniauth_auth['credentials']['token'], @user.getting_started = false
:access_secret => omniauth_auth['credentials']['secret'], post :create, :provider => 'twitter'
:uid => omniauth_auth['uid'], response.should redirect_to services_url
:user => bob) 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 end
context "photo fetching" do context 'when fetching a photo' do
before do before do
omniauth_auth omniauth_auth
omniauth_auth["info"].merge!({"image" => "https://service.com/fallback_lowres.jpg"}) omniauth_auth["info"].merge!({"image" => "https://service.com/fallback_lowres.jpg"})
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter