Class: ActiveJob::QueueAdapters::TestAdapter

Inherits:
AbstractAdapter show all
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

Instance Method Summary collapse

Constructor Details

#initialize(enqueue_after_transaction_commit: true) ⇒ TestAdapter

Returns a new instance of TestAdapter.



18
19
20
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 18

def initialize(enqueue_after_transaction_commit: true)
  @enqueue_after_transaction_commit = enqueue_after_transaction_commit
end

Instance Attribute Details

#atObject

Returns the value of attribute at.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def at
  @at
end

#enqueue_after_transaction_commitObject

Returns the value of attribute enqueue_after_transaction_commit.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def enqueue_after_transaction_commit
  @enqueue_after_transaction_commit
end

#enqueued_jobsObject

Provides a store of all the enqueued jobs with the TestAdapter so you can check them.



27
28
29
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 27

def enqueued_jobs
  @enqueued_jobs ||= []
end

#filterObject

Returns the value of attribute filter.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def filter
  @filter
end

#perform_enqueued_at_jobsObject

Returns the value of attribute perform_enqueued_at_jobs.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def perform_enqueued_at_jobs
  @perform_enqueued_at_jobs
end

#perform_enqueued_jobsObject

Returns the value of attribute perform_enqueued_jobs.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def perform_enqueued_jobs
  @perform_enqueued_jobs
end

#performed_jobsObject

Provides a store of all the performed jobs with the TestAdapter so you can check them.



32
33
34
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 32

def performed_jobs
  @performed_jobs ||= []
end

#queueObject

Returns the value of attribute queue.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def queue
  @queue
end

#rejectObject

Returns the value of attribute reject.



15
16
17
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 15

def reject
  @reject
end

Instance Method Details

#enqueue(job) ⇒ Object

:nodoc:



36
37
38
39
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 36

def enqueue(job) # :nodoc:
  job_data = job_to_hash(job)
  perform_or_enqueue(perform_enqueued_jobs && !filtered?(job), job, job_data)
end

#enqueue_after_transaction_commit?Boolean

:nodoc:

Returns:

  • (Boolean)


22
23
24
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 22

def enqueue_after_transaction_commit? # :nodoc:
  @enqueue_after_transaction_commit
end

#enqueue_at(job, timestamp) ⇒ Object

:nodoc:



41
42
43
44
# File 'lib/active_job/queue_adapters/test_adapter.rb', line 41

def enqueue_at(job, timestamp) # :nodoc:
  job_data = job_to_hash(job, at: timestamp)
  perform_or_enqueue(perform_enqueued_at_jobs && !filtered?(job), job, job_data)
end