Refactor services controller spec
This commit is contained in:
parent
ebfc3de878
commit
872a96dc71
2 changed files with 43 additions and 44 deletions
|
|
@ -1,5 +1,6 @@
|
||||||
# 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
|
||||||
|
|
||||||
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
|
||||||
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
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'creates a new OmniauthService' do
|
||||||
|
expect {
|
||||||
|
post :create, :provider => 'twitter'
|
||||||
|
}.to change(@user.services, :count).by(1)
|
||||||
|
end
|
||||||
|
|
||||||
|
it 'redirects to getting started if the user is getting started' do
|
||||||
|
@user.getting_started = true
|
||||||
post :create, :provider => 'twitter'
|
post :create, :provider => 'twitter'
|
||||||
}.should change(@user.services, :count).by(1)
|
response.should redirect_to getting_started_path
|
||||||
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
it 'redirects to getting started if the user is getting started' do
|
context 'when fetching a photo' 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
|
|
||||||
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 'returns error if the service is connected with that uid' do
|
|
||||||
request.env['omniauth.auth'] = omniauth_auth
|
|
||||||
|
|
||||||
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
|
|
||||||
|
|
||||||
context "photo fetching" 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"})
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue