Skip to content

Instantly share code, notes, and snippets.

@albus522
Created November 9, 2012 14:26
Show Gist options
  • Save albus522/4045988 to your computer and use it in GitHub Desktop.
Save albus522/4045988 to your computer and use it in GitHub Desktop.
diff --git a/lib/delayed/backend/shared_spec.rb b/lib/delayed/backend/shared_spec.rb
index 8dc94eb..7a8caa6 100644
--- a/lib/delayed/backend/shared_spec.rb
+++ b/lib/delayed/backend/shared_spec.rb
@@ -289,16 +289,18 @@ shared_examples_for "a delayed_job backend" do
end
it "reads five jobs" do
- pending
- described_class.should_receive(:find_available).with(anything, 5, anything).and_return([])
- described_class.reserve(worker)
+ if described_class.respond_to?(:find_available)
+ described_class.should_receive(:find_available).with(anything, 5, anything).and_return([])
+ described_class.reserve(worker)
+ end
end
it "reads a configurable number of jobs" do
- pending
- Delayed::Worker.read_ahead = 15
- described_class.should_receive(:find_available).with(anything, Delayed::Worker.read_ahead, anything).and_return([])
- described_class.reserve(worker)
+ if described_class.respond_to?(:find_available)
+ Delayed::Worker.read_ahead = 15
+ described_class.should_receive(:find_available).with(anything, Delayed::Worker.read_ahead, anything).and_return([])
+ described_class.reserve(worker)
+ end
end
end
@@ -418,11 +420,12 @@ shared_examples_for "a delayed_job backend" do
end
it "raises error ArgumentError the record is not persisted" do
- pending
story = Story.new(:text => 'hello')
- expect {
- story.delay.tell
- }.to raise_error(ArgumentError, "Jobs cannot be created for records before they've been persisted")
+ if story.respond_to?(:new_record?)
+ expect {
+ story.delay.tell
+ }.to raise_error(ArgumentError, "Jobs cannot be created for records before they've been persisted")
+ end
end
it "raises deserialization error for destroyed records" do
@@ -486,7 +489,6 @@ shared_examples_for "a delayed_job backend" do
end
it "re-schedules jobs after failing" do
- pending
worker.work_off
@job.reload
expect(@job.last_error).to match(/did not work/)
diff --git a/lib/delayed/performable_method.rb b/lib/delayed/performable_method.rb
index 60edd18..40aaf68 100644
--- a/lib/delayed/performable_method.rb
+++ b/lib/delayed/performable_method.rb
@@ -9,8 +9,8 @@ module Delayed
def initialize(object, method_name, args)
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)
- if defined?(ActiveRecord) && object.kind_of?(ActiveRecord::Base)
- raise(ArgumentError, 'Jobs cannot be created for records before they\'ve been persisted') if object.attributes[object.class.primary_key].nil?
+ if object.respond_to?(:new_record?) && object.new_record?
+ raise(ArgumentError, 'Jobs cannot be created for records before they\'ve been persisted')
end
self.object = object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment