Skip to content

Commit 245af31

Browse files
authored
Merge pull request rails#51823 from Shopify/gm/memoize-queue_adapter_for_test
[Bugfix] Memoize `queue_adapter_for_test`
2 parents db4bbb7 + 9b069ee commit 245af31

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

activejob/lib/active_job/test_helper.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def enable_test_adapter(test_adapter)
3939
end
4040

4141
def before_setup # :nodoc:
42+
queue_adapter_specific_to_this_test_class = queue_adapter_for_test
4243
queue_adapter_changed_jobs.each do |klass|
43-
if (queue_adapter_specific_to_this_test_class = queue_adapter_for_test)
44+
if queue_adapter_specific_to_this_test_class
4445
klass.enable_test_adapter(queue_adapter_specific_to_this_test_class)
4546
elsif klass._queue_adapter.nil?
4647
klass.enable_test_adapter(ActiveJob::QueueAdapters::TestAdapter.new)

activejob/test/cases/test_helper_test.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -806,6 +806,24 @@ def test_assert_enqueued_jobs_with_performed
806806
end
807807
end
808808

809+
class QueueAdapterTest < ActiveJob::TestCase
810+
class JobWithAnAdapter < ActiveJob::Base
811+
self.queue_adapter = :async
812+
813+
def perform; end
814+
end
815+
816+
def queue_adapter_for_test
817+
ActiveJob::QueueAdapters::TestAdapter.new
818+
end
819+
820+
test "assert_enqueued_with enqueues a job with a queue_adapter and queue_adapter_for_test" do
821+
assert_enqueued_with(job: JobWithAnAdapter) do
822+
JobWithAnAdapter.perform_later
823+
end
824+
end
825+
end
826+
809827
class PerformedJobsTest < ActiveJob::TestCase
810828
if adapter_is?(:test)
811829
include DoNotPerformEnqueuedJobs

0 commit comments

Comments
 (0)