diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-30 21:05:29 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-12-30 21:05:29 -0300 |
commit | 0d1ab3491522a6b757e864412c84406764f10b9d (patch) | |
tree | 636632992460e0c29c882f11b8fb39d87a9c93f6 | |
parent | 04852b875ec5c2bd5e5f8bf525b7be60682d0c27 (diff) | |
parent | 8a73f4b5b9d342a45b3c8e29a13142adbca9ab21 (diff) | |
download | rails-0d1ab3491522a6b757e864412c84406764f10b9d.tar.gz rails-0d1ab3491522a6b757e864412c84406764f10b9d.tar.bz2 rails-0d1ab3491522a6b757e864412c84406764f10b9d.zip |
Merge pull request #18266 from cristianbica/ajfixes
ActiveJob testing improvements
-rw-r--r-- | activejob/Rakefile | 2 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapter.rb | 6 | ||||
-rw-r--r-- | activejob/lib/active_job/queue_adapters/test_adapter.rb | 17 | ||||
-rw-r--r-- | activejob/lib/active_job/test_helper.rb | 2 | ||||
-rw-r--r-- | activejob/test/adapters/test.rb | 3 | ||||
-rw-r--r-- | activejob/test/cases/adapter_test.rb | 3 |
6 files changed, 21 insertions, 12 deletions
diff --git a/activejob/Rakefile b/activejob/Rakefile index 7e66860b36..b215ba65fa 100644 --- a/activejob/Rakefile +++ b/activejob/Rakefile @@ -1,7 +1,7 @@ require 'rake/testtask' require 'rubygems/package_task' -ACTIVEJOB_ADAPTERS = %w(inline delayed_job qu que queue_classic resque sidekiq sneakers sucker_punch backburner) +ACTIVEJOB_ADAPTERS = %w(inline delayed_job qu que queue_classic resque sidekiq sneakers sucker_punch backburner test) ACTIVEJOB_ADAPTERS -= %w(queue_classic) if defined?(JRUBY_VERSION) task default: :test 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 diff --git a/activejob/test/adapters/test.rb b/activejob/test/adapters/test.rb new file mode 100644 index 0000000000..7180b38a57 --- /dev/null +++ b/activejob/test/adapters/test.rb @@ -0,0 +1,3 @@ +ActiveJob::Base.queue_adapter = :test +ActiveJob::Base.queue_adapter.perform_enqueued_jobs = true +ActiveJob::Base.queue_adapter.perform_enqueued_at_jobs = true diff --git a/activejob/test/cases/adapter_test.rb b/activejob/test/cases/adapter_test.rb index 61a7cae5bf..6570c55a83 100644 --- a/activejob/test/cases/adapter_test.rb +++ b/activejob/test/cases/adapter_test.rb @@ -2,7 +2,6 @@ require 'helper' class AdapterTest < ActiveSupport::TestCase test "should load #{ENV['AJADAPTER']} adapter" do - ActiveJob::Base.queue_adapter = ENV['AJADAPTER'].to_sym - assert_equal "active_job/queue_adapters/#{ENV['AJADAPTER']}_adapter".classify.constantize, ActiveJob::Base.queue_adapter + assert_equal "active_job/queue_adapters/#{ENV['AJADAPTER']}_adapter".classify, ActiveJob::Base.queue_adapter.name end end |