lib/resque_spec/ext.rb in resque_spec-0.7.0 vs lib/resque_spec/ext.rb in resque_spec-0.8.0
- old
+ new
@@ -19,22 +19,39 @@
old_count - ResqueSpec.queue_by_name(queue).size
end
end
def enqueue(klass, *args)
+ enqueue_to(queue_from_class(klass), klass, *args)
+ end
+
+ def enqueue_to(queue, klass, *args)
if ResqueSpec.inline
+ return if run_before_enqueue(klass, *args)
run_after_enqueue(klass, *args)
- Job.create(queue_from_class(klass), klass, *args)
+ Job.create(queue, klass, *args)
else
- Job.create(queue_from_class(klass), klass, *args)
+ return if run_before_enqueue(klass, *args)
+ Job.create(queue, klass, *args)
run_after_enqueue(klass, *args)
end
end
+ def reserve(queue_name)
+ ResqueSpec.pop(queue_name)
+ end
+
private
def run_after_enqueue(klass, *args)
Plugin.after_enqueue_hooks(klass).each do |hook|
klass.send(hook, *args)
end
+ end
+
+ def run_before_enqueue(klass, *args)
+ before_hooks = Plugin.before_enqueue_hooks(klass).collect do |hook|
+ klass.send(hook, *args)
+ end
+ before_hooks.any? { |result| result == false }
end
end