Skip to content

Commit

Permalink
Only set backend if one is not already set
Browse files Browse the repository at this point in the history
  • Loading branch information
bkeepers committed Sep 5, 2010
1 parent ffbf53a commit 77b0482
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/delayed/worker.rb
Expand Up @@ -38,7 +38,7 @@ def self.backend=(backend)
end

def self.guess_backend
self.backend = :active_record if defined?(ActiveRecord)
self.backend ||= :active_record if defined?(ActiveRecord)
end

def initialize(options={})
Expand Down
20 changes: 19 additions & 1 deletion spec/worker_spec.rb
Expand Up @@ -10,10 +10,28 @@
it "should set the Delayed::Job constant to the backend" do
Delayed::Job.should == @clazz
end

it "should set backend with a symbol" do
Delayed::Worker.backend = :active_record
Delayed::Worker.backend.should == Delayed::Backend::ActiveRecord::Job
end
end

describe "guess_backend" do
after do
Delayed::Worker.backend = :active_record
end

it "should set to active_record if nil" do
Delayed::Worker.backend = nil
lambda {
Delayed::Worker.guess_backend
}.should change { Delayed::Worker.backend }.to(Delayed::Backend::ActiveRecord::Job)
end

it "should not override the existing backend" do
Delayed::Worker.backend = Class.new
lambda { Delayed::Worker.guess_backend }.should_not change { Delayed::Worker.backend }
end
end
end

0 comments on commit 77b0482

Please sign in to comment.