From 80dc309821732c68a6fb347230c99f2f6abf2f6f Mon Sep 17 00:00:00 2001 From: Yuji Yaginuma Date: Wed, 1 Feb 2017 06:37:16 +0900 Subject: correctly set test adapter when configure the queue adapter on a per job (#26690) The `ActiveJob::TestHelper` replace the adapter to test adapter in `before_setup`. It gets the target class using the `descendants`, but if the test target job class is not loaded, will not be a replacement of the adapter. Therefore, instead of replacing with `before_setup`, modified to replace when setting adapter. Fixes #26360 --- activejob/test/cases/queue_adapter_test.rb | 1 + activejob/test/cases/test_helper_test.rb | 17 +++++++++++++++++ activejob/test/jobs/queue_adapter_job.rb | 3 +++ 3 files changed, 21 insertions(+) create mode 100644 activejob/test/jobs/queue_adapter_job.rb (limited to 'activejob/test') diff --git a/activejob/test/cases/queue_adapter_test.rb b/activejob/test/cases/queue_adapter_test.rb index f1e0cf78ad..9611b0909b 100644 --- a/activejob/test/cases/queue_adapter_test.rb +++ b/activejob/test/cases/queue_adapter_test.rb @@ -21,6 +21,7 @@ class QueueAdapterTest < ActiveJob::TestCase end test "should allow overriding the queue_adapter at the child class level without affecting the parent or its sibling" do + ActiveJob::Base.disable_test_adapter base_queue_adapter = ActiveJob::Base.queue_adapter child_job_one = Class.new(ActiveJob::Base) diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index 372b68c2f5..2e6357f824 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -560,3 +560,20 @@ class InheritedJobTest < ActiveJob::TestCase assert_instance_of ActiveJob::QueueAdapters::TestAdapter, InheritedJob.queue_adapter end end + +class QueueAdapterJobTest < ActiveJob::TestCase + def before_setup + @original_autoload_paths = ActiveSupport::Dependencies.autoload_paths + ActiveSupport::Dependencies.autoload_paths = %w(test/jobs) + super + end + + def after_teardown + ActiveSupport::Dependencies.autoload_paths = @original_autoload_paths + super + end + + def test_queue_adapter_is_test_adapter + assert_instance_of ActiveJob::QueueAdapters::TestAdapter, QueueAdapterJob.queue_adapter + end +end diff --git a/activejob/test/jobs/queue_adapter_job.rb b/activejob/test/jobs/queue_adapter_job.rb new file mode 100644 index 0000000000..160dfd74ec --- /dev/null +++ b/activejob/test/jobs/queue_adapter_job.rb @@ -0,0 +1,3 @@ +class QueueAdapterJob < ActiveJob::Base + self.queue_adapter = :inline +end -- cgit v1.2.3