aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/lib
diff options
context:
space:
mode:
authorCristian Bica <cristian.bica@gmail.com>2014-12-30 17:53:42 +0200
committerCristian Bica <cristian.bica@gmail.com>2014-12-30 17:53:42 +0200
commit8a73f4b5b9d342a45b3c8e29a13142adbca9ab21 (patch)
tree7330f4490ec4b7dd9cd880d1187ffb41fb4f0da6 /activejob/lib
parent0c070ae568767a2c8e9bdec49ab3a1a24f113382 (diff)
downloadrails-8a73f4b5b9d342a45b3c8e29a13142adbca9ab21.tar.gz
rails-8a73f4b5b9d342a45b3c8e29a13142adbca9ab21.tar.bz2
rails-8a73f4b5b9d342a45b3c8e29a13142adbca9ab21.zip
ActiveJob testing improvements
1. The :test adapter wasn't going through a full cycle of serialize/deserialize when performing jobs. Now it does 2. Regular AJ tests were not run for the :test adapter. Now they are 3. ActiveJob::TestHelper uses assert_valid_keys but doesn’t requires the file that implements that method. Now it does
Diffstat (limited to 'activejob/lib')
-rw-r--r--activejob/lib/active_job/queue_adapter.rb6
-rw-r--r--activejob/lib/active_job/queue_adapters/test_adapter.rb17
-rw-r--r--activejob/lib/active_job/test_helper.rb2
3 files changed, 16 insertions, 9 deletions
diff --git a/activejob/lib/active_job/queue_adapter.rb b/activejob/lib/active_job/queue_adapter.rb
index 85d7c44bb8..d48d56e1da 100644
--- a/activejob/lib/active_job/queue_adapter.rb
+++ b/activejob/lib/active_job/queue_adapter.rb
@@ -2,7 +2,7 @@ require 'active_job/queue_adapters/inline_adapter'
require 'active_support/core_ext/string/inflections'
module ActiveJob
- # The <tt>ActionJob::QueueAdapter</tt> module is used to load the
+ # The <tt>ActionJob::QueueAdapter</tt> module is used to load the
# correct adapter. The default queue adapter is the :inline queue.
module QueueAdapter #:nodoc:
extend ActiveSupport::Concern
@@ -21,8 +21,8 @@ module ActiveJob
ActiveJob::QueueAdapters::TestAdapter.new
when Symbol, String
load_adapter(name_or_adapter)
- when Class
- name_or_adapter
+ else
+ name_or_adapter if name_or_adapter.respond_to?(:enqueue)
end
end
diff --git a/activejob/lib/active_job/queue_adapters/test_adapter.rb b/activejob/lib/active_job/queue_adapters/test_adapter.rb
index e4fdf60008..ea9df9a063 100644
--- a/activejob/lib/active_job/queue_adapters/test_adapter.rb
+++ b/activejob/lib/active_job/queue_adapters/test_adapter.rb
@@ -14,6 +14,11 @@ module ActiveJob
attr_accessor(:perform_enqueued_jobs, :perform_enqueued_at_jobs)
attr_writer(:enqueued_jobs, :performed_jobs)
+ def initialize
+ self.perform_enqueued_jobs = false
+ self.perform_enqueued_at_jobs = false
+ end
+
# Provides a store of all the enqueued jobs with the TestAdapter so you can check them.
def enqueued_jobs
@enqueued_jobs ||= []
@@ -26,19 +31,19 @@ module ActiveJob
def enqueue(job) #:nodoc:
if perform_enqueued_jobs
- performed_jobs << {job: job.class, args: job.arguments, queue: job.queue_name}
- job.perform_now
+ 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.arguments, queue: job.queue_name}
+ enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name}
end
end
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
+ 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.arguments, queue: job.queue_name, at: timestamp}
+ enqueued_jobs << {job: job.class, args: job.serialize['arguments'], queue: job.queue_name, at: timestamp}
end
end
end
diff --git a/activejob/lib/active_job/test_helper.rb b/activejob/lib/active_job/test_helper.rb
index 1720b140e5..2efcea7f2e 100644
--- a/activejob/lib/active_job/test_helper.rb
+++ b/activejob/lib/active_job/test_helper.rb
@@ -1,3 +1,5 @@
+require 'active_support/core_ext/hash/keys'
+
module ActiveJob
# Provides helper methods for testing Active Job
module TestHelper