diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-02 11:31:08 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-09-02 11:31:08 -0300 |
commit | 2e500e5c93dd398bf40448321e9c455d6e4f4689 (patch) | |
tree | 87f546132ccc7e78499addec752656b7ca38355c /activejob/lib/active_job/queue_adapters | |
parent | 2f52f969885b2834198de0045748436a4651a94e (diff) | |
parent | d7add5352e7c8b31850431bb93acb56d93c5dc64 (diff) | |
download | rails-2e500e5c93dd398bf40448321e9c455d6e4f4689.tar.gz rails-2e500e5c93dd398bf40448321e9c455d6e4f4689.tar.bz2 rails-2e500e5c93dd398bf40448321e9c455d6e4f4689.zip |
Merge pull request #16724 from seuros/testcase
[ActiveJob] TestCase
Diffstat (limited to 'activejob/lib/active_job/queue_adapters')
-rw-r--r-- | activejob/lib/active_job/queue_adapters/test_adapter.rb | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb new file mode 100644 index 0000000000..971db9d7de --- /dev/null +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -0,0 +1,75 @@ +module ActiveJob + module QueueAdapters + class TestAdapter + attr_accessor(:perform_enqueued_jobs) { false } + attr_accessor(:perform_enqueued_at_jobs) { false } + + # 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) + else + enqueued_jobs << {job: job, args: args, 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) + else + enqueued_jobs << {job: job, args: args, queue: job.queue_name, run_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 |