Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Show object when throwing "non-persisted record" error #655

Merged
merged 3 commits into from

3 participants

Dorian Marié David Genord II Coveralls
Dorian Marié

When calling delay on a non-persisted record, the error raised now also contains the details about the object.

This make debugging this error easier. And is consistent with the previous error.

Basically I had errors like:

 Failure/Error: product.destroy
 ArgumentError:
   Jobs cannot be created for non-persisted records
 # ./spec/models/product_spec.rb:18:in `block (3 levels) in <top (required)>'

But there is no actual details about the record that was not persisted here (eg: it's not the product)

Dorian Marié Dorian Show object when throwing "non-persisted record" error
When calling `delay` on a non-persisted record, the error raised now also contains the details about the object.

This make debugging this error easier. And is consistent with the previous error.
59f072d
David Genord II
Owner

Looks like you have some specs to fix

Dorian Marié

Oops, I forgot to look at that, I fixed the specs, and BTW, I needed to use rspec 2.14 (https://gist.github.com/Dorian/3948ca1323e9629ab00e).

Dorian Marié Dorian Merge branch 'master' of https://github.com/collectiveidea/delayed_job
…into patch-1

Conflicts:
	lib/delayed/backend/shared_spec.rb
	lib/delayed/performable_method.rb
941adb7
Coveralls

Coverage Status

Coverage increased (+0.04%) when pulling 941adb7 on Dorian:patch-1 into c0e0a81 on collectiveidea:master.

David Genord II albus522 merged commit f9a07f4 into from
Dorian Marié Dorian deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 2, 2014
  1. Dorian Marié

    Show object when throwing "non-persisted record" error

    Dorian authored
    When calling `delay` on a non-persisted record, the error raised now also contains the details about the object.
    
    This make debugging this error easier. And is consistent with the previous error.
Commits on Sep 22, 2014
  1. Dorian Marié
  2. Dorian Marié

    Merge branch 'master' of https://github.com/collectiveidea/delayed_job

    Dorian authored
    …into patch-1
    
    Conflicts:
    	lib/delayed/backend/shared_spec.rb
    	lib/delayed/performable_method.rb
This page is out of date. Refresh to see the latest.
10 lib/delayed/backend/shared_spec.rb
View
@@ -409,14 +409,20 @@ def create_job(opts = {})
it 'raises error ArgumentError for new records' do
story = Story.new(:text => 'hello')
if story.respond_to?(:new_record?)
- expect { story.delay.tell }.to raise_error(ArgumentError, 'Jobs cannot be created for non-persisted records')
+ expect { story.delay.tell }.to raise_error(
+ ArgumentError,
+ "job cannot be created for non-persisted record: #{story.inspect}"
+ )
end
end
it 'raises error ArgumentError for destroyed records' do
story = Story.create(:text => 'hello')
story.destroy
- expect { story.delay.tell }.to raise_error(ArgumentError, 'Jobs cannot be created for non-persisted records')
+ expect { story.delay.tell }.to raise_error(
+ ArgumentError,
+ "job cannot be created for non-persisted record: #{story.inspect}"
+ )
end
end
2  lib/delayed/performable_method.rb
View
@@ -10,7 +10,7 @@ def initialize(object, method_name, args)
raise NoMethodError, "undefined method `#{method_name}' for #{object.inspect}" unless object.respond_to?(method_name, true)
if object.respond_to?(:persisted?) && !object.persisted?
- raise ArgumentError, 'Jobs cannot be created for non-persisted records'
+ raise(ArgumentError, "job cannot be created for non-persisted record: #{object.inspect}")
end
self.object = object
Something went wrong with that request. Please try again.