Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow users to explicitly specify the queue backend to use
* Add a configuration block for the main module * Make backend auto detection more specific * Refactor the job dispatching logic * Add some basic specs * Update the README with usage info * Rearrange autoload to the top of the main module * Suppress warning output in specs
- Loading branch information
Jay Zeschin
committed
Oct 15, 2012
1 parent
333365c
commit 844c155
Showing
6 changed files
with
181 additions
and
35 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
require 'spec_helper' | ||
require 'carrierwave_backgrounder' | ||
|
||
describe CarrierWave::Backgrounder do | ||
|
||
describe 'enumerating available backends' do | ||
|
||
it 'detects GirlFriday' do | ||
CarrierWave::Backgrounder.available_backends.should include(:girl_friday) | ||
end | ||
it 'detects Delayed::Job' do | ||
CarrierWave::Backgrounder.available_backends.should include(:delayed_job) | ||
end | ||
it 'detects Resque' do | ||
CarrierWave::Backgrounder.available_backends.should include(:resque) | ||
end | ||
it 'detects Qu' do | ||
CarrierWave::Backgrounder.available_backends.should include(:qu) | ||
end | ||
it 'detects Sidekiq' do | ||
CarrierWave::Backgrounder.available_backends.should include(:sidekiq) | ||
end | ||
it 'detects QC' do | ||
CarrierWave::Backgrounder.available_backends.should include(:qc) | ||
end | ||
end | ||
|
||
describe 'automatically setting backends' do | ||
|
||
before do | ||
CarrierWave::Backgrounder.instance_variable_set('@backend', nil) | ||
end | ||
|
||
it 'does not set a backend if none are available' do | ||
suppress_warnings do | ||
CarrierWave::Backgrounder.stubs(:available_backends).returns([]) | ||
CarrierWave::Backgrounder.backend.should be_nil | ||
end | ||
end | ||
it 'sets a backend automatically if only one is available' do | ||
CarrierWave::Backgrounder.stubs(:available_backends).returns([ :qu ]) | ||
CarrierWave::Backgrounder.backend.should eq(:qu) | ||
end | ||
it 'does not set a backend if more than one is available' do | ||
suppress_warnings do | ||
CarrierWave::Backgrounder.stubs(:available_backends).returns([:qu, :resque]) | ||
CarrierWave::Backgrounder.backend.should be_nil | ||
end | ||
end | ||
|
||
it 'does not clobber a manually set backend' do | ||
CarrierWave::Backgrounder.backend = :not_a_backend | ||
CarrierWave::Backgrounder.backend.should eq(:not_a_backend) | ||
end | ||
|
||
it 'calls configure_backend when setting the backend' do | ||
CarrierWave::Backgrounder.stubs(:available_backends).returns([ :qu ]) | ||
CarrierWave::Backgrounder.expects(:configure_backend).once | ||
CarrierWave::Backgrounder.backend.should eq(:qu) | ||
end | ||
|
||
end | ||
|
||
|
||
|
||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,21 @@ | ||
# encoding: utf-8 | ||
require 'rubygems' | ||
require 'bundler/setup' | ||
require 'support/backend_constants' | ||
require 'logger' | ||
|
||
module WarningSuppression | ||
def suppress_warnings | ||
original_verbosity = $VERBOSE | ||
$VERBOSE = nil | ||
result = yield | ||
$VERBOSE = original_verbosity | ||
return result | ||
end | ||
end | ||
|
||
RSpec.configure do |c| | ||
c.mock_with :mocha | ||
end | ||
c.include WarningSuppression | ||
end | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# Fixture module declarations for backend detection testing | ||
|
||
module GirlFriday | ||
end | ||
|
||
module Delayed | ||
module Job | ||
end | ||
end | ||
|
||
module Resque | ||
end | ||
|
||
module Qu | ||
end | ||
|
||
module Sidekiq | ||
module Worker | ||
end | ||
end | ||
|
||
module QC | ||
end |