lib/delayed/performable_method.rb in delayed_job-3.0.1 vs lib/delayed/performable_method.rb in delayed_job-3.0.2
- old
+ new
@@ -7,9 +7,13 @@
delegate :method, :to => :object
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?
+ end
+
self.object = object
self.args = args
self.method_name = method_name.to_sym
end