Class: ActiveJob::QueueAdapters::TestAdapter
- Inherits:
-
Object
- Object
- ActiveJob::QueueAdapters::TestAdapter
- Defined in:
- lib/active_job/queue_adapters/test_adapter.rb
Overview
Test adapter for Active Job
The test adapter should be used only in testing. Along with ActiveJob::TestCase and ActiveJob::TestHelper it makes a great tool to test your Rails application.
To use the test adapter set queue_adapter config to :test.
Rails.application.config.active_job.queue_adapter = :test
Instance Attribute Summary collapse
-
#enqueued_jobs ⇒ Object
Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
-
#perform_enqueued_at_jobs ⇒ Object
Returns the value of attribute perform_enqueued_at_jobs.
-
#perform_enqueued_jobs ⇒ Object
Returns the value of attribute perform_enqueued_jobs.
-
#performed_jobs ⇒ Object
Provides a store of all the performed jobs with the TestAdapter so you can check them.
Instance Method Summary collapse
-
#enqueue(job) ⇒ Object
:nodoc:.
-
#enqueue_at(job, timestamp) ⇒ Object
:nodoc:.
-
#initialize ⇒ TestAdapter
constructor
A new instance of TestAdapter.
Constructor Details
#initialize ⇒ TestAdapter
Returns a new instance of TestAdapter.
17 18 19 20 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 17 def initialize self.perform_enqueued_jobs = false self.perform_enqueued_at_jobs = false end |
Instance Attribute Details
#enqueued_jobs ⇒ Object
Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
23 24 25 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 23 def enqueued_jobs @enqueued_jobs ||= [] end |
#perform_enqueued_at_jobs ⇒ Object
Returns the value of attribute perform_enqueued_at_jobs.
14 15 16 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 14 def perform_enqueued_at_jobs @perform_enqueued_at_jobs end |
#perform_enqueued_jobs ⇒ Object
Returns the value of attribute perform_enqueued_jobs.
14 15 16 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 14 def perform_enqueued_jobs @perform_enqueued_jobs end |
#performed_jobs ⇒ Object
Provides a store of all the performed jobs with the TestAdapter so you can check them.
28 29 30 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 28 def performed_jobs @performed_jobs ||= [] end |
Instance Method Details
#enqueue(job) ⇒ Object
:nodoc:
32 33 34 35 36 37 38 39 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 32 def enqueue(job) #:nodoc: if perform_enqueued_jobs performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name} Base.execute job.serialize else enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name} end end |
#enqueue_at(job, timestamp) ⇒ Object
:nodoc:
41 42 43 44 45 46 47 48 |
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 41 def enqueue_at(job, ) #:nodoc: if perform_enqueued_at_jobs performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: } Base.execute job.serialize else enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: } end end |