Skip to content
Browse files

Add Qu.configure, delegate connection to backend, and raise error if …

…backend not configured
  • Loading branch information...
1 parent 9dd308e commit 919d45fa6417303e0ce3b60979ca440ec7b458ed @bkeepers committed Sep 22, 2011
Showing with 19 additions and 11 deletions.
  1. +6 −6 lib/qu.rb
  2. +13 −5 spec/qu_spec.rb
View
12 lib/qu.rb
@@ -11,15 +11,15 @@ module Qu
extend SingleForwardable
extend self
- def_delegators :backend, :enqueue, :length, :queues, :reserve, :clear
+ attr_accessor :backend, :failure
- attr_accessor :failure
+ def_delegators :backend, :enqueue, :length, :queues, :reserve, :clear, :connection=
- def backend=(backend)
- @backend = backend
+ def backend
+ @backend || raise("Qu backend not configured. Install one of the backend gems like qu-redis.")
end
- def backend
- @backend ||= Backend::Redis.new
+ def configure(&block)
+ block.call(self)
end
end
View
18 spec/qu_spec.rb
@@ -1,17 +1,25 @@
require 'spec_helper'
describe Qu do
- %w(enqueue length queues reserve clear).each do |method|
+ %w(enqueue length queues reserve clear connection=).each do |method|
it "should delegate #{method} to backend" do
Qu.backend.should_receive(method).with(:arg)
Qu.send(method, :arg)
end
end
- describe 'enqueue' do
- it 'should call enqueue on the backend with a job' do
- Qu.backend.should_receive(:enqueue).with(SimpleJob, 'a', 'b')
- Qu.enqueue SimpleJob, 'a', 'b'
+ describe 'configure' do
+ it 'should yield Qu' do
+ Qu.configure do |c|
+ c.should == Qu
+ end
+ end
+ end
+
+ describe 'backend' do
+ it 'should raise error if backend not configured' do
+ Qu.backend = nil
+ lambda { Qu.backend }.should raise_error
end
end
end

0 comments on commit 919d45f

Please sign in to comment.
Something went wrong with that request. Please try again.