forked from diaspora/diaspora
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservices_controller_spec.rb
110 lines (88 loc) · 3.16 KB
/
services_controller_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
# Copyright (c) 2010-2011, Diaspora Inc. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.
require 'spec_helper'
describe ServicesController do
let(:mock_access_token) { Object.new }
let(:omniauth_auth) {
{ 'provider' => 'twitter',
'uid' => '2',
'info' => { 'nickname' => 'grimmin' },
'credentials' => { 'token' => 'tokin', 'secret' =>"not_so_much" }
}
}
before do
@user = alice
@aspect = @user.aspects.first
sign_in :user, @user
@controller.stub!(:current_user).and_return(@user)
mock_access_token.stub!(:token => "12345", :secret => "56789")
end
describe '#index' do
it 'displays all connected serivices for a user' do
4.times do
Factory(:service, :user => @user)
end
get :index
assigns[:services].should == @user.services
end
end
describe '#create' do
context 'when not fetching a photo' do
before do
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 '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
context 'when fetching a photo' do
before do
omniauth_auth
omniauth_auth["info"].merge!({"image" => "https://service.com/fallback_lowres.jpg"})
request.env['omniauth.auth'] = omniauth_auth
end
it 'does not queue a job if the profile photo is set' do
profile = @user.person.profile
profile[:image_url] = "/non/default/image.jpg"
profile.save
Resque.should_not_receive(:enqueue)
post :create, :provider => 'twitter'
end
it 'queues a job to save user photo if the photo does not exist' do
profile = @user.person.profile
profile[:image_url] = nil
profile.save
Resque.should_receive(:enqueue).with(Jobs::FetchProfilePhoto, @user.id, anything(), "https://service.com/fallback_lowres.jpg")
post :create, :provider => 'twitter'
end
end
end
describe '#destroy' do
before do
@service1 = Factory(:service, :user => @user)
end
it 'destroys a service selected by id' do
lambda{
delete :destroy, :id => @service1.id
}.should change(@user.services, :count).by(-1)
end
end
end