diaspora/spec/controllers/services_controller_spec.rb
Jonne Haß 79a79d65d6 Bye Resque. Ohai Sidekiq.
* Dropped all references to Resque
* Moved all jobs under app/workers since that's the Sidekiq convention
* Renamed Jobs module to Worker to match new location
* Adapted all jobs to Sidekiq
* Replaced all enqueue calls with perform_async
* Dropped Resque hacks from specs and features, replaced with
  sidekig/testing in RSpec and sidekig/testing/inline in Cucumber
* Updated scripts to start a Sidekiq server
* Inline Sidekiq sinatra app
* Let Sidekiq create the actual Redis instance
* Workaround already initialized constant warnings in service models
* Resolved ToDo in one job definition by creating proper exception clases
  for some errors in receiving posts
* Added sidekiq section to configuration to make it completly
  configurable to the user
* Add Sidekiq middleware for clean backtraces
* Delay HttpMulti retry to give offline pods a chance to come back up
* Do not retry on GUID already taken and alike errors
* Be graceful about deleted posts in GatherOEmbedData
2013-03-21 23:39:07 +01:00

107 lines
3.2 KiB
Ruby

# 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
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
FactoryGirl.create(: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
Workers::FetchProfilePhoto.should_not_receive(:perform_async)
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
Workers::FetchProfilePhoto.should_receive(:perform_async).with(@user.id, anything(), "https://service.com/fallback_lowres.jpg")
post :create, :provider => 'twitter'
end
end
end
describe '#destroy' do
before do
@service1 = FactoryGirl.create(: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