* 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
58 lines
2.1 KiB
Ruby
58 lines
2.1 KiB
Ruby
require 'spec_helper'
|
|
|
|
describe Workers::FetchProfilePhoto do
|
|
before do
|
|
@user = alice
|
|
@service = FactoryGirl.build(:service, :user => alice)
|
|
|
|
@url = "https://service.com/user/profile_image"
|
|
|
|
@service.stub(:profile_photo_url).and_return(@url)
|
|
@user.stub(:update_profile)
|
|
|
|
User.stub(:find).and_return(@user)
|
|
Service.stub(:find).and_return(@service)
|
|
|
|
@photo_stub = stub
|
|
@photo_stub.stub(:save!).and_return(true)
|
|
@photo_stub.stub(:url).and_return("image.jpg")
|
|
end
|
|
|
|
it 'saves the profile image' do
|
|
@photo_stub.should_receive(:save!).and_return(true)
|
|
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => @url, :pending => true)).and_return(@photo_stub)
|
|
|
|
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
|
|
end
|
|
|
|
context "service does not have a profile_photo_url" do
|
|
it "does nothing without fallback" do
|
|
@service.stub!(:profile_photo_url).and_return(nil)
|
|
Photo.should_not_receive(:diaspora_initialize)
|
|
|
|
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
|
|
end
|
|
|
|
it "fetches fallback if it's provided" do
|
|
@photo_stub.should_receive(:save!).and_return(true)
|
|
@service.stub!(:profile_photo_url).and_return(nil)
|
|
Photo.should_receive(:diaspora_initialize).with(hash_including(:author => @user.person, :image_url => "https://service.com/fallback_lowres.jpg", :pending => true)).and_return(@photo_stub)
|
|
|
|
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id, "https://service.com/fallback_lowres.jpg")
|
|
end
|
|
end
|
|
|
|
|
|
it 'updates the profile' do
|
|
@photo_stub.stub(:url).and_return("large.jpg", "medium.jpg", "small.jpg")
|
|
|
|
Photo.should_receive(:diaspora_initialize).and_return(@photo_stub)
|
|
@user.should_receive(:update_profile).with(hash_including({
|
|
:image_url => "large.jpg",
|
|
:image_url_medium => "medium.jpg",
|
|
:image_url_small => "small.jpg"
|
|
}))
|
|
|
|
Workers::FetchProfilePhoto.new.perform(@user.id, @service.id)
|
|
end
|
|
end
|