Skip to content
Browse files

Only set backend if one is not already set

  • Loading branch information...
1 parent ffbf53a commit 77b0482febced944fba0104b3b2431773414fccf @bkeepers bkeepers committed Sep 5, 2010
Showing with 20 additions and 2 deletions.
  1. +1 −1 lib/delayed/worker.rb
  2. +19 −1 spec/worker_spec.rb
View
2 lib/delayed/worker.rb
@@ -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={})
View
20 spec/worker_spec.rb
@@ -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.
Something went wrong with that request. Please try again.