Class: ActiveJob::QueueAdapters::TestAdapter

Inherits:
Object
  • Object
show all
Defined in:
activejob/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

#initializeTestAdapter

Returns a new instance of TestAdapter.


17
18
19
20
# File 'activejob/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_jobsObject

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


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

def enqueued_jobs
  @enqueued_jobs ||= []
end

#perform_enqueued_at_jobsObject

Returns the value of attribute perform_enqueued_at_jobs


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

def perform_enqueued_at_jobs
  @perform_enqueued_at_jobs
end

#perform_enqueued_jobsObject

Returns the value of attribute perform_enqueued_jobs


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

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.


28
29
30
# File 'activejob/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 'activejob/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 'activejob/lib/active_job/queue_adapters/test_adapter.rb', line 41

def enqueue_at(job, timestamp) #:nodoc:
  if perform_enqueued_at_jobs
    performed_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp}
    Base.execute job.serialize
  else
    enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp}
  end
end