Skip to content

Commit

Permalink
The send_* options now insert in to the default configured queue if o…
Browse files Browse the repository at this point in the history
…ne is configured.
  • Loading branch information
bracken committed Feb 23, 2010
1 parent 95ca6d5 commit 42a983a
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/delayed/backend/base.rb
Expand Up @@ -23,7 +23,7 @@ def enqueue(*args)
options = args.first || {} options = args.first || {}
options[:priority] ||= 0 options[:priority] ||= 0
options[:payload_object] = object options[:payload_object] = object

options[:queue] ||= Delayed::Worker.queue
self.create(options) self.create(options)
end end
end end
Expand Down
29 changes: 28 additions & 1 deletion spec/delayed_method_spec.rb
@@ -1,7 +1,10 @@
require 'spec_helper' require 'spec_helper'


describe 'random ruby objects' do describe 'random ruby objects' do
before { Delayed::Job.delete_all } before :each do
Delayed::Worker.queue = nil
Delayed::Job.delete_all
end


it "should respond_to :send_later method" do it "should respond_to :send_later method" do
Object.new.respond_to?(:send_later) Object.new.respond_to?(:send_later)
Expand Down Expand Up @@ -56,6 +59,19 @@
job.payload_object.args.should == [1, 5] job.payload_object.args.should == [1, 5]
job.payload_object.perform.should == 'Once upon...' job.payload_object.perform.should == 'Once upon...'
end end

context "send_later" do
it "should use the default queue if there is one" do
Delayed::Worker.queue = "testqueue"
job = "string".send_later :reverse
job.queue.should == "testqueue"
end

it "should have nil queue if there is not a default" do
job = "string".send_later :reverse
job.queue.should == nil
end
end


context "send_at" do context "send_at" do
it "should queue a new job" do it "should queue a new job" do
Expand All @@ -77,6 +93,17 @@
job.payload_object.args.should == ['r'] job.payload_object.args.should == ['r']
job.payload_object.perform.should == 1 job.payload_object.perform.should == 1
end end

it "should use the default queue if there is one" do
Delayed::Worker.queue = "testqueue"
job = "string".send_at 1.hour.from_now, :reverse
job.queue.should == "testqueue"
end

it "should have nil queue if there is not a default" do
job = "string".send_at 1.hour.from_now, :reverse
job.queue.should == nil
end
end end


context "send_at_with_queue" do context "send_at_with_queue" do
Expand Down

0 comments on commit 42a983a

Please sign in to comment.