lib/resque_spec/ext.rb in resque_spec-0.9.3 vs lib/resque_spec/ext.rb in resque_spec-0.10.0

- old
+ new

@@ -1,16 +1,25 @@ require 'resque' module Resque class Job + class << self + alias :create_without_resque_spec :create + alias :destroy_without_resque_spec :destroy + end + def self.create(queue, klass, *args) + return create_without_resque_spec(queue, klass, *args) if ResqueSpec.disable_ext + raise ::Resque::NoQueueError.new("Jobs must be placed onto a queue.") if !queue raise ::Resque::NoClassError.new("Jobs must be given a class.") if klass.to_s.empty? ResqueSpec.enqueue(queue, klass, *args) end def self.destroy(queue, klass, *args) + return destroy_without_resque_spec(queue, klass, *args) if ResqueSpec.disable_ext + raise ::Resque::NoQueueError.new("Jobs must have been placed onto a queue.") if !queue raise ::Resque::NoClassError.new("Jobs must have been given a class.") if klass.to_s.empty? old_count = ResqueSpec.queue_by_name(queue).size @@ -18,15 +27,23 @@ old_count - ResqueSpec.queue_by_name(queue).size end end + alias :enqueue_without_resque_spec :enqueue + alias :enqueue_to_without_resque_spec :enqueue_to if Resque.respond_to? :enqueue_to + alias :reserve_without_resque_spec :reserve + def enqueue(klass, *args) + return enqueue_without_resque_spec(klass, *args) if ResqueSpec.disable_ext + enqueue_to(queue_from_class(klass), klass, *args) end def enqueue_to(queue, klass, *args) + return enqueue_to_without_resque_spec(queue, klass, *args) if ResqueSpec.disable_ext + if ResqueSpec.inline return if run_before_enqueue(klass, *args) run_after_enqueue(klass, *args) Job.create(queue, klass, *args) else @@ -36,9 +53,11 @@ true end end def reserve(queue_name) + return reserve_without_resque_spec(queue_name) if ResqueSpec.disable_ext + ResqueSpec.pop(queue_name) end private