class ActiveJob::QueueAdapters::TestAdapter
Rails.application.config.active_job.queue_adapter = :test
To use the test adapter set queue_adapter
config to :test
.
it makes a great tool to test your Rails application.
ActiveJob::TestCase and ActiveJob::TestHelper
The test adapter should be used only in testing. Along with
== Test adapter for Active Job
def enqueue(job) # :nodoc:
def enqueue(job) # :nodoc: job_data = job_to_hash(job) perform_or_enqueue(perform_enqueued_jobs && !filtered?(job), job, job_data) end
def enqueue_at(job, timestamp) # :nodoc:
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
def enqueued_jobs
def enqueued_jobs @enqueued_jobs ||= [] end
def filter_as_proc(filter)
def filter_as_proc(filter) return filter if filter.is_a?(Proc) ->(job) { Array(filter).include?(job.class) } end
def filtered?(job)
def filtered?(job) filtered_queue?(job) || filtered_job_class?(job) || filtered_time?(job) end
def filtered_job_class?(job)
def filtered_job_class?(job) if filter !filter_as_proc(filter).call(job) elsif reject filter_as_proc(reject).call(job) end end
def filtered_queue?(job)
def filtered_queue?(job) if queue job.queue_name != queue.to_s end end
def filtered_time?(job)
def filtered_time?(job) job.scheduled_at > at.to_f if at && job.scheduled_at end
def job_to_hash(job, extras = {})
def job_to_hash(job, extras = {}) job.serialize.tap do |job_data| job_data[:job] = job.class job_data[:args] = job_data.fetch("arguments") job_data[:queue] = job_data.fetch("queue_name") job_data[:priority] = job_data.fetch("priority") end.merge(extras) end
def perform_or_enqueue(perform, job, job_data)
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
def performed_jobs
def performed_jobs @performed_jobs ||= [] end