Permalink
Browse files

Don't save jobs with empty handlers

  • Loading branch information...
tobi committed Mar 24, 2008
1 parent 0880b0f commit b9dc92b9ca14e7cf2ec892c3ca3a1cb006989838
Showing with 43 additions and 3 deletions.
  1. +42 −2 spec/delayed_method_spec.rb
  2. +1 −1 spec/job_spec.rb
@@ -1,4 +1,11 @@
require File.dirname(__FILE__) + '/database'
+
+if not defined?(:ActiveRecord)
+ module ActiveRecord
+ class RecordNotFound < StandardError
+ end
+ end
+end
class SimpleJob
@@ -10,7 +17,16 @@ class RandomRubyObject
def say_hello
'hello'
end
-end
+end
+
+class ErrorObject
+
+ def throw
+ raise ActiveRecord::RecordNotFound, '...'
+ false
+ end
+
+end
class StoryReader
@@ -20,7 +36,15 @@ def read(story)
end
+class StoryReader
+
+ def read(story)
+ "Epilog: #{story.tell}"
+ end
+
+end
+
describe 'random ruby objects' do
before { reset_db }
@@ -48,7 +72,23 @@ def read(story)
RandomRubyObject.new.send_later(:say_hello)
Delayed::Job.count.should == 1
- end
+ end
+
+ it "should ignore ActiveRecord::RecordNotFound errors because they are permanent" do
+
+ ErrorObject.new.send_later(:throw)
+
+ Delayed::Job.count.should == 1
+
+ output = nil
+
+ Delayed::Job.reserve do |e|
+ output = e.perform
+ end
+
+ output.should == true
+
+ end
it "should store the object as string if its an active record" do
story = Story.create :text => 'Once upon...'
View
@@ -17,7 +17,7 @@ def perform; raise 'did not work'; end
end
it "should set run_at automatically" do
- Delayed::Job.create.run_at.should_not == nil
+ Delayed::Job.create(:payload_object => ErrorJob.new ).run_at.should_not == nil
end
it "should raise ArgumentError when handler doesn't respond_to :perform" do

0 comments on commit b9dc92b

Please sign in to comment.