edge badge

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
Methods
E
F
J
P
Attributes
[W] enqueued_jobs
[RW] filter
[RW] perform_enqueued_at_jobs
[RW] perform_enqueued_jobs
[W] performed_jobs
[RW] queue
[RW] reject
Instance Public methods
enqueued_jobs()

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

# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 19
def enqueued_jobs
  @enqueued_jobs ||= []
end
filtered?(job)
# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 56
def filtered?(job)
  filtered_queue?(job) || filtered_job_class?(job)
end
filtered_job_class?(job)
# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 66
def filtered_job_class?(job)
  if filter
    !Array(filter).include?(job.class)
  elsif reject
    Array(reject).include?(job.class)
  end
end
filtered_queue?(job)
# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 60
def filtered_queue?(job)
  if queue
    job.queue_name != queue.to_s
  end
end
job_to_hash(job, extras = {})
# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 43
def job_to_hash(job, extras = {})
  { job: job.class, args: job.serialize.fetch("arguments"), queue: job.queue_name }.merge!(extras)
end
perform_or_enqueue(perform, job, job_data)
# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 47
def perform_or_enqueue(perform, job, job_data)
  if perform
    performed_jobs << job_data
    Base.execute job.serialize
  else
    enqueued_jobs << job_data
  end
end
performed_jobs()

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

# File activejob/lib/active_job/queue_adapters/test_adapter.rb, line 24
def performed_jobs
  @performed_jobs ||= []
end