From eb4245dd17ba66c0551f3d4ed841b471bcf01b91 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 26 Aug 2014 20:08:49 +0000 Subject: [ActiveJob] TestCase --- .../lib/active_job/queue_adapters/test_adapter.rb | 77 ++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 activejob/lib/active_job/queue_adapters/test_adapter.rb (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb') 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..f7c4d19638 --- /dev/null +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -0,0 +1,77 @@ +module ActiveJob + module QueueAdapters + class TestAdapter + mattr_accessor(:perform_enqueued_jobs) { false } + mattr_accessor(:perform_enqueued_at_jobs) { false } + + class << self + # 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 over write 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 over write 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 +end -- cgit v1.2.3 From fccf3d0b6304a7b8dacad05b63f24cdf41e652df Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Fri, 29 Aug 2014 20:11:17 +0000 Subject: [ActiveJob] TestCase --- .../lib/active_job/queue_adapters/test_adapter.rb | 118 ++++++++++----------- 1 file changed, 58 insertions(+), 60 deletions(-) (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb') diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index f7c4d19638..2cab9e946d 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -1,76 +1,74 @@ module ActiveJob module QueueAdapters class TestAdapter - mattr_accessor(:perform_enqueued_jobs) { false } - mattr_accessor(:perform_enqueued_at_jobs) { false } + attr_accessor(:perform_enqueued_jobs) { false } + attr_accessor(:perform_enqueued_at_jobs) { false } - class << self - # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. - def enqueued_jobs - @@enqueued_jobs ||= [] - end + # 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 over write 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 + # Allows you to over write 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 + # 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 over write 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 + # Allows you to over write 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 + 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 + 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 + private + def perform_enqueued_jobs? + perform_enqueued_jobs + end - def perform_enqueued_at_jobs? - perform_enqueued_at_jobs - end + def perform_enqueued_at_jobs? + perform_enqueued_at_jobs end end end -- cgit v1.2.3 From d7add5352e7c8b31850431bb93acb56d93c5dc64 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 2 Sep 2014 14:06:19 +0000 Subject: [ActiveJob] TestCase (Will squash before merge) --- .../lib/active_job/queue_adapters/test_adapter.rb | 24 +++++++++++----------- 1 file changed, 12 insertions(+), 12 deletions(-) (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb') diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 2cab9e946d..971db9d7de 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -6,10 +6,10 @@ module ActiveJob # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. def enqueued_jobs - @@enqueued_jobs ||= [] + @enqueued_jobs ||= [] end - # Allows you to over write the default enqueued jobs store from an array to some + # 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. # @@ -21,15 +21,15 @@ module ActiveJob # * size # * and other common Array methods def enqueued_jobs=(val) - @@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 ||= [] + @performed_jobs ||= [] end - # Allows you to over write the default performed jobs store from an array to some + # 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. # @@ -41,7 +41,7 @@ module ActiveJob # * size # * and other common Array methods def performed_jobs=(val) - @@performed_jobs = val + @performed_jobs = val end def enqueue(job, *args) @@ -63,13 +63,13 @@ module ActiveJob end private - def perform_enqueued_jobs? - perform_enqueued_jobs - end + def perform_enqueued_jobs? + perform_enqueued_jobs + end - def perform_enqueued_at_jobs? - perform_enqueued_at_jobs - end + def perform_enqueued_at_jobs? + perform_enqueued_at_jobs + end end end end -- cgit v1.2.3 From a70bdfe6e391a35b74c42a96488d4e0e2f7c8200 Mon Sep 17 00:00:00 2001 From: Abdelkader Boudih Date: Tue, 2 Sep 2014 20:27:32 +0000 Subject: Fix failing tests in ActiveJob Adapter --- activejob/lib/active_job/queue_adapters/test_adapter.rb | 1 + 1 file changed, 1 insertion(+) (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb') diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 971db9d7de..185d6fc7e6 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -3,6 +3,7 @@ module ActiveJob class TestAdapter attr_accessor(:perform_enqueued_jobs) { false } attr_accessor(:perform_enqueued_at_jobs) { false } + delegate :name, to: :class # Provides a store of all the enqueued jobs with the TestAdapter so you can check them. def enqueued_jobs -- cgit v1.2.3 From 1e237b4e44b7de564c7d6b331dd2f2243c4113fd Mon Sep 17 00:00:00 2001 From: Cristian Bica Date: Mon, 25 Aug 2014 17:34:50 +0300 Subject: Active Job refactoring --- activejob/lib/active_job/queue_adapters/test_adapter.rb | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'activejob/lib/active_job/queue_adapters/test_adapter.rb') diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb index 185d6fc7e6..b9997efddf 100644 --- a/activejob/lib/active_job/queue_adapters/test_adapter.rb +++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb @@ -45,21 +45,21 @@ module ActiveJob @performed_jobs = val end - def enqueue(job, *args) + def enqueue(job) if perform_enqueued_jobs? - performed_jobs << {job: job, args: args, queue: job.queue_name} - job.new.execute(*args) + 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) + def enqueue_at(job, timestamp) if perform_enqueued_at_jobs? - performed_jobs << {job: job, args: args, queue: job.queue_name, run_at: timestamp} - job.new.execute(*args) + 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 -- cgit v1.2.3