lib/resque_spec.rb in resque_spec-0.6.6 vs lib/resque_spec.rb in resque_spec-0.6.7
- old
+ new
@@ -12,13 +12,24 @@
job[:class] == klass.to_s && args.empty? || job[:args] == args
end
end
def enqueue(queue_name, klass, *args)
- store(queue_name, klass, { :class => klass.to_s, :args => args })
+ store(queue_name, :class => klass.to_s, :args => args)
end
+ def perform_next(queue_name)
+ perform(queue_name, queue_by_name(queue_name).shift)
+ end
+
+ def perform_all(queue_name)
+ queue = queue_by_name(queue_name)
+ until queue.empty?
+ perform(queue_name, queue.shift)
+ end
+ end
+
def queue_by_name(name)
queues[name]
end
def queue_for(klass)
@@ -39,10 +50,11 @@
@queues ||= Hash.new {|h,k| h[k] = []}
end
def reset!
queues.clear
+ self.inline = false
end
private
def name_from_instance_var(klass)
@@ -51,12 +63,16 @@
def name_from_queue_accessor(klass)
klass.respond_to?(:queue) and klass.queue
end
- def store(queue_name, klass, payload)
+ def perform(queue_name, payload)
+ Resque::Job.new(queue_name, payload_with_string_keys(payload)).perform
+ end
+
+ def store(queue_name, payload)
if inline
- Resque::Job.new(queue_name, payload_with_string_keys(payload)).perform
+ perform(queue_name, payload)
else
queue_by_name(queue_name) << payload
end
end