Class: Rails::Queue::TestQueue

Inherits:
Queue
  • Object
show all
Defined in:
lib/rails/queue/queue.rb

Overview

In test mode, the Rails queue is backed by an Array so that assertions can be made about its contents. The test queue provides a jobs method to make assertions about the queue’s contents and a drain method to drain the queue and run the jobs.

Jobs are run in a separate thread to catch mistakes where code assumes that the job is run in the same thread.

Instance Attribute Summary

Attributes inherited from Queue

#consumer

Instance Method Summary collapse

Methods inherited from Queue

#drain, #initialize

Constructor Details

This class inherits a constructor from Rails::Queue::Queue

Instance Method Details

#jobsObject

Get a list of the jobs off this queue. This method may not be available on production queues.



50
51
52
# File 'lib/rails/queue/queue.rb', line 50

def jobs
  @que.dup
end

#push(job) ⇒ Object

Marshal and unmarshal job before pushing it onto the queue. This will raise an exception on any attempts in tests to push jobs that can’t (or shouldn’t) be marshalled.



57
58
59
# File 'lib/rails/queue/queue.rb', line 57

def push(job)
  super Marshal.load(Marshal.dump(job))
end