class ActiveJob::QueueAdapters::TestAdapter
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
Attributes
at[RW]
enqueued_jobs[W]
filter[RW]
perform_enqueued_at_jobs[RW]
perform_enqueued_jobs[RW]
performed_jobs[W]
queue[RW]
reject[RW]
Public Instance Methods
enqueued_jobs()
click to toggle source
Provides a store of all the enqueued jobs with the TestAdapter
so you can check them.
# File lib/active_job/queue_adapters/test_adapter.rb, line 19 def enqueued_jobs @enqueued_jobs ||= [] end
performed_jobs()
click to toggle source
Provides a store of all the performed jobs with the TestAdapter
so you can check them.
# File lib/active_job/queue_adapters/test_adapter.rb, line 24 def performed_jobs @performed_jobs ||= [] end
Private Instance Methods
filter_as_proc(filter)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 79 def filter_as_proc(filter) return filter if filter.is_a?(Proc) ->(job) { Array(filter).include?(job.class) } end
filtered?(job)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 57 def filtered?(job) filtered_queue?(job) || filtered_job_class?(job) || filtered_time?(job) end
filtered_job_class?(job)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 71 def filtered_job_class?(job) if filter !filter_as_proc(filter).call(job) elsif reject filter_as_proc(reject).call(job) end end
filtered_queue?(job)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 65 def filtered_queue?(job) if queue job.queue_name != queue.to_s end end
filtered_time?(job)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 61 def filtered_time?(job) job.scheduled_at > at.to_f if at && job.scheduled_at end
job_to_hash(job, extras = {})
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 39 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
perform_or_enqueue(perform, job, job_data)
click to toggle source
# File lib/active_job/queue_adapters/test_adapter.rb, line 48 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