diff options
Diffstat (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb')
-rw-r--r-- | activejob/lib/active_job/queue_adapters/test_adapter.rb | 72 |
1 files changed, 21 insertions, 51 deletions
diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 185d6fc7e6..e4fdf60008 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -1,76 +1,46 @@ module ActiveJob module QueueAdapters + # == Test adapter for Active Job + # + # The test adapter should be used only in testing. Along with + # <tt>ActiveJob::TestCase</tt> and <tt>ActiveJob::TestHelper</tt> + # 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 class TestAdapter - attr_accessor(:perform_enqueued_jobs) { false } - attr_accessor(:perform_enqueued_at_jobs) { false } delegate :name, to: :class + attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs) + attr_writer(:enqueued_jobs, :performed_jobs) # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. def enqueued_jobs @enqueued_jobs ||= [] end - # Allows you to overwrite the default enqueued jobs store from an array to some - # other object. If you just want to clear the store, - # call ActiveJob::QueueAdapters::TestAdapter.enqueued_jobs.clear. - # - # If you place another object here, please make sure it responds to: - # - # * << (message) - # * clear - # * length - # * size - # * and other common Array methods - def enqueued_jobs=(val) - @enqueued_jobs = val - end - # Provides a store of all the performed jobs with the TestAdapter so you can check them. def performed_jobs @performed_jobs ||= [] end - # Allows you to overwrite the default performed jobs store from an array to some - # other object. If you just want to clear the store, - # call ActiveJob::QueueAdapters::TestAdapter.performed_jobs.clear. - # - # If you place another object here, please make sure it responds to: - # - # * << (message) - # * clear - # * length - # * size - # * and other common Array methods - def performed_jobs=(val) - @performed_jobs = val - end - - def enqueue(job, *args) - if perform_enqueued_jobs? - performed_jobs << {job: job, args: args, queue: job.queue_name} - job.new.execute(*args) + def enqueue(job) #:nodoc: + if perform_enqueued_jobs + performed_jobs << {job: job.class, args: job.arguments, queue: job.queue_name} + job.perform_now else - enqueued_jobs << {job: job, args: args, queue: job.queue_name} + enqueued_jobs << {job: job.class, args: job.arguments, queue: job.queue_name} end end - def enqueue_at(job, timestamp, *args) - if perform_enqueued_at_jobs? - performed_jobs << {job: job, args: args, queue: job.queue_name, run_at: timestamp} - job.new.execute(*args) + def enqueue_at(job, timestamp) #:nodoc: + if perform_enqueued_at_jobs + performed_jobs << {job: job.class, args: job.arguments, queue: job.queue_name, at: timestamp} + job.perform_now else - enqueued_jobs << {job: job, args: args, queue: job.queue_name, run_at: timestamp} + enqueued_jobs << {job: job.class, args: job.arguments, queue: job.queue_name, at: timestamp} end end - - private - def perform_enqueued_jobs? - perform_enqueued_jobs - end - - def perform_enqueued_at_jobs? - perform_enqueued_at_jobs - end end end end |