diff options
Diffstat (limited to 'activejob/test/cases/test_helper_test.rb')
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 137 |
1 files changed, 78 insertions, 59 deletions
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index f7ee763e8a..685c93da2d 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -1,17 +1,18 @@ -require 'helper' -require 'active_support/core_ext/time' -require 'active_support/core_ext/date' -require 'jobs/hello_job' -require 'jobs/logging_job' -require 'jobs/nested_job' -require 'jobs/rescue_job' -require 'models/person' +require "helper" +require "active_support/core_ext/time" +require "active_support/core_ext/date" +require "jobs/hello_job" +require "jobs/logging_job" +require "jobs/nested_job" +require "jobs/rescue_job" +require "jobs/inherited_job" +require "models/person" class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs assert_nothing_raised do assert_enqueued_jobs 1 do - HelloJob.perform_later('david') + HelloJob.perform_later("david") end end end @@ -19,23 +20,23 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_repeated_enqueued_jobs_calls assert_nothing_raised do assert_enqueued_jobs 1 do - HelloJob.perform_later('abdelkader') + HelloJob.perform_later("abdelkader") end end assert_nothing_raised do assert_enqueued_jobs 2 do - HelloJob.perform_later('sean') - HelloJob.perform_later('yves') + HelloJob.perform_later("sean") + HelloJob.perform_later("yves") end end end def test_assert_enqueued_jobs_message - HelloJob.perform_later('sean') + HelloJob.perform_later("sean") e = assert_raises Minitest::Assertion do assert_enqueued_jobs 2 do - HelloJob.perform_later('sean') + HelloJob.perform_later("sean") end end assert_match "Expected: 2", e.message @@ -44,13 +45,13 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_with_no_block assert_nothing_raised do - HelloJob.perform_later('rafael') + HelloJob.perform_later("rafael") assert_enqueued_jobs 1 end assert_nothing_raised do - HelloJob.perform_later('aaron') - HelloJob.perform_later('matthew') + HelloJob.perform_later("aaron") + HelloJob.perform_later("matthew") assert_enqueued_jobs 3 end end @@ -72,7 +73,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 2 do - HelloJob.perform_later('xavier') + HelloJob.perform_later("xavier") end end @@ -82,8 +83,8 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 1 do - HelloJob.perform_later('cristian') - HelloJob.perform_later('guillermo') + HelloJob.perform_later("cristian") + HelloJob.perform_later("guillermo") end end @@ -93,7 +94,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_no_enqueued_jobs_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_enqueued_jobs do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") end end @@ -103,7 +104,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_with_only_option assert_nothing_raised do assert_enqueued_jobs 1, only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") LoggingJob.perform_later end end @@ -122,7 +123,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_with_only_option_and_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 5, only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") 4.times { LoggingJob.perform_later } end end @@ -133,7 +134,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_with_only_option_and_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_enqueued_jobs 1, only: HelloJob do - 2.times { HelloJob.perform_later('jeremy') } + 2.times { HelloJob.perform_later("jeremy") } end end @@ -143,9 +144,9 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_enqueued_jobs_with_only_option_as_array assert_nothing_raised do assert_enqueued_jobs 2, only: [HelloJob, LoggingJob] do - HelloJob.perform_later('jeremy') - LoggingJob.perform_later('stewie') - RescueJob.perform_later('david') + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") end end end @@ -161,7 +162,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase def test_assert_no_enqueued_jobs_with_only_option_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_enqueued_jobs only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") LoggingJob.perform_later end end @@ -178,7 +179,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase end def test_assert_enqueued_job - assert_enqueued_with(job: LoggingJob, queue: 'default') do + assert_enqueued_with(job: LoggingJob, queue: "default") do LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later end end @@ -190,19 +191,19 @@ class EnqueuedJobsTest < ActiveJob::TestCase assert_instance_of LoggingJob, job assert_in_delta 5.minutes.from_now, job.scheduled_at, 1 - assert_equal 'default', job.queue_name + assert_equal "default", job.queue_name assert_equal [1, 2, 3], job.arguments end def test_assert_enqueued_job_failure assert_raise ActiveSupport::TestCase::Assertion do - assert_enqueued_with(job: LoggingJob, queue: 'default') do + assert_enqueued_with(job: LoggingJob, queue: "default") do NestedJob.perform_later end end error = assert_raise ActiveSupport::TestCase::Assertion do - assert_enqueued_with(job: NestedJob, queue: 'low') do + assert_enqueued_with(job: NestedJob, queue: "low") do NestedJob.perform_later end end @@ -249,7 +250,7 @@ class EnqueuedJobsTest < ActiveJob::TestCase HelloJob.perform_later end - assert_equal 2, ActiveJob::Base.queue_adapter.enqueued_jobs.count + assert_equal 2, queue_adapter.enqueued_jobs.count end end @@ -265,7 +266,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs assert_nothing_raised do assert_performed_jobs 1 do - HelloJob.perform_later('david') + HelloJob.perform_later("david") end end end @@ -273,23 +274,23 @@ class PerformedJobsTest < ActiveJob::TestCase def test_repeated_performed_jobs_calls assert_nothing_raised do assert_performed_jobs 1 do - HelloJob.perform_later('abdelkader') + HelloJob.perform_later("abdelkader") end end assert_nothing_raised do assert_performed_jobs 2 do - HelloJob.perform_later('sean') - HelloJob.perform_later('yves') + HelloJob.perform_later("sean") + HelloJob.perform_later("yves") end end end def test_assert_performed_jobs_message - HelloJob.perform_later('sean') + HelloJob.perform_later("sean") e = assert_raises Minitest::Assertion do assert_performed_jobs 2 do - HelloJob.perform_later('sean') + HelloJob.perform_later("sean") end end assert_match "Expected: 2", e.message @@ -299,15 +300,15 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_with_no_block assert_nothing_raised do perform_enqueued_jobs do - HelloJob.perform_later('rafael') + HelloJob.perform_later("rafael") end assert_performed_jobs 1 end assert_nothing_raised do perform_enqueued_jobs do - HelloJob.perform_later('aaron') - HelloJob.perform_later('matthew') + HelloJob.perform_later("aaron") + HelloJob.perform_later("matthew") assert_performed_jobs 3 end end @@ -330,7 +331,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 2 do - HelloJob.perform_later('xavier') + HelloJob.perform_later("xavier") end end @@ -340,8 +341,8 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 1 do - HelloJob.perform_later('cristian') - HelloJob.perform_later('guillermo') + HelloJob.perform_later("cristian") + HelloJob.perform_later("guillermo") end end @@ -351,7 +352,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_no_performed_jobs_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_performed_jobs do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") end end @@ -361,7 +362,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_with_only_option assert_nothing_raised do assert_performed_jobs 1, only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") LoggingJob.perform_later end end @@ -370,9 +371,9 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_with_only_option_as_array assert_nothing_raised do assert_performed_jobs 2, only: [HelloJob, LoggingJob] do - HelloJob.perform_later('jeremy') - LoggingJob.perform_later('stewie') - RescueJob.perform_later('david') + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("stewie") + RescueJob.perform_later("david") end end end @@ -390,7 +391,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_with_only_option_and_too_few_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 5, only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") 4.times { LoggingJob.perform_later } end end @@ -401,7 +402,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_performed_jobs_with_only_option_and_too_many_sent error = assert_raise ActiveSupport::TestCase::Assertion do assert_performed_jobs 1, only: HelloJob do - 2.times { HelloJob.perform_later('jeremy') } + 2.times { HelloJob.perform_later("jeremy") } end end @@ -427,7 +428,7 @@ class PerformedJobsTest < ActiveJob::TestCase def test_assert_no_performed_jobs_with_only_option_failure error = assert_raise ActiveSupport::TestCase::Assertion do assert_no_performed_jobs only: HelloJob do - HelloJob.perform_later('jeremy') + HelloJob.perform_later("jeremy") LoggingJob.perform_later end end @@ -436,20 +437,20 @@ class PerformedJobsTest < ActiveJob::TestCase end def test_assert_performed_job - assert_performed_with(job: NestedJob, queue: 'default') do + assert_performed_with(job: NestedJob, queue: "default") do NestedJob.perform_later end end def test_assert_performed_job_returns - job = assert_performed_with(job: NestedJob, queue: 'default') do + job = assert_performed_with(job: NestedJob, queue: "default") do NestedJob.perform_later end assert_instance_of NestedJob, job assert_nil job.scheduled_at assert_equal [], job.arguments - assert_equal 'default', job.queue_name + assert_equal "default", job.queue_name end def test_assert_performed_job_failure @@ -460,8 +461,8 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_raise ActiveSupport::TestCase::Assertion do - assert_performed_with(job: HelloJob, queue: 'low') do - HelloJob.set(queue: 'important').perform_later + assert_performed_with(job: HelloJob, queue: "low") do + HelloJob.set(queue: "important").perform_later end end end @@ -506,6 +507,24 @@ class PerformedJobsTest < ActiveJob::TestCase HelloJob.perform_later end - assert_equal 2, ActiveJob::Base.queue_adapter.performed_jobs.count + assert_equal 2, queue_adapter.performed_jobs.count + end +end + +class OverrideQueueAdapterTest < ActiveJob::TestCase + class CustomQueueAdapter < ActiveJob::QueueAdapters::TestAdapter; end + + def queue_adapter_for_test + CustomQueueAdapter.new + end + + def test_assert_job_has_custom_queue_adapter_set + assert_instance_of CustomQueueAdapter, HelloJob.queue_adapter + end +end + +class InheritedJobTest < ActiveJob::TestCase + def test_queue_adapter_is_test_adapter + assert_instance_of ActiveJob::QueueAdapters::TestAdapter, InheritedJob.queue_adapter end end |