diff options
author | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-08-16 21:54:26 +0300 |
---|---|---|
committer | bogdanvlviv <bogdanvlviv@gmail.com> | 2018-08-20 13:05:29 +0300 |
commit | 11634e8ef85870535bad61b999e0f9ec36f6f963 (patch) | |
tree | b5710303e045cab7479846bfa57e6f5faedfb3d9 /activejob/test | |
parent | 2bf8b4eb0eceb37fc278c71371a659979844dfb2 (diff) | |
download | rails-11634e8ef85870535bad61b999e0f9ec36f6f963.tar.gz rails-11634e8ef85870535bad61b999e0f9ec36f6f963.tar.bz2 rails-11634e8ef85870535bad61b999e0f9ec36f6f963.zip |
Fix `assert_performed_jobs` and `assert_no_performed_jobs`
Execution of `assert_performed_jobs`, and `assert_no_performed_jobs`
without a block should respect passed `:except`, `:only`, and `:queue` options.
Diffstat (limited to 'activejob/test')
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 266 |
1 files changed, 256 insertions, 10 deletions
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb index eade285412..f64b886d67 100644 --- a/activejob/test/cases/test_helper_test.rb +++ b/activejob/test/cases/test_helper_test.rb @@ -677,7 +677,7 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob + assert_performed_jobs 1, only: LoggingJob end def test_perform_enqueued_jobs_without_block_with_only_option @@ -687,7 +687,7 @@ class PerformedJobsTest < ActiveJob::TestCase perform_enqueued_jobs only: LoggingJob assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob + assert_performed_jobs 1, only: LoggingJob end def test_perform_enqueued_jobs_with_block_with_except_option @@ -697,7 +697,7 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob + assert_performed_jobs 1, only: LoggingJob end def test_perform_enqueued_jobs_without_block_with_except_option @@ -707,7 +707,7 @@ class PerformedJobsTest < ActiveJob::TestCase perform_enqueued_jobs except: HelloJob assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob + assert_performed_jobs 1, only: LoggingJob end def test_perform_enqueued_jobs_with_block_with_queue_option @@ -718,7 +718,7 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: HelloJob, queue: :some_queue + assert_performed_jobs 1, only: HelloJob, queue: :some_queue end def test_perform_enqueued_jobs_without_block_with_queue_option @@ -729,7 +729,7 @@ class PerformedJobsTest < ActiveJob::TestCase perform_enqueued_jobs queue: :some_queue assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: HelloJob, queue: :some_queue + assert_performed_jobs 1, only: HelloJob, queue: :some_queue end def test_perform_enqueued_jobs_with_block_with_only_and_queue_options @@ -740,7 +740,7 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: HelloJob, queue: :other_queue + assert_performed_jobs 1, only: HelloJob, queue: :other_queue end def test_perform_enqueued_jobs_without_block_with_only_and_queue_options @@ -751,7 +751,7 @@ class PerformedJobsTest < ActiveJob::TestCase perform_enqueued_jobs only: HelloJob, queue: :other_queue assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: HelloJob, queue: :other_queue + assert_performed_jobs 1, only: HelloJob, queue: :other_queue end def test_perform_enqueued_jobs_with_block_with_except_and_queue_options @@ -762,7 +762,7 @@ class PerformedJobsTest < ActiveJob::TestCase end assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob, queue: :other_queue + assert_performed_jobs 1, only: LoggingJob, queue: :other_queue end def test_perform_enqueued_jobs_without_block_with_except_and_queue_options @@ -773,7 +773,7 @@ class PerformedJobsTest < ActiveJob::TestCase perform_enqueued_jobs except: HelloJob, queue: :other_queue assert_performed_jobs 1 - # TODO assert_performed_jobs 1, only: LoggingJob, queue: :other_queue + assert_performed_jobs 1, only: LoggingJob, queue: :other_queue end def test_assert_performed_jobs @@ -881,6 +881,28 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_performed_jobs_without_block_with_only_option + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + assert_performed_jobs 1, only: HelloJob + end + + def test_assert_performed_jobs_without_block_with_only_option_failure + LoggingJob.perform_later("jeremy") + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, only: HelloJob + end + + assert_match(/1 .* but 0/, error.message) + end + def test_assert_performed_jobs_with_except_option assert_nothing_raised do assert_performed_jobs 1, except: LoggingJob do @@ -890,6 +912,28 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_performed_jobs_without_block_with_except_option + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + assert_performed_jobs 1, except: HelloJob + end + + def test_assert_performed_jobs_without_block_with_except_option_failure + HelloJob.perform_later("jeremy") + HelloJob.perform_later("bogdan") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, except: HelloJob + end + + assert_match(/1 .* but 0/, error.message) + end + def test_assert_performed_jobs_with_only_and_except_option error = assert_raise ArgumentError do assert_performed_jobs 1, only: HelloJob, except: HelloJob do @@ -901,6 +945,19 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/`:only` and `:except`/, error.message) end + def test_assert_performed_jobs_without_block_with_only_and_except_options + error = assert_raise ArgumentError do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + assert_performed_jobs 1, only: HelloJob, except: HelloJob + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_performed_jobs_with_only_option_as_array assert_nothing_raised do assert_performed_jobs 2, only: [HelloJob, LoggingJob] do @@ -1044,6 +1101,28 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 0/, error.message) end + def test_assert_performed_jobs_without_block_with_queue_option + HelloJob.set(queue: :some_queue).perform_later("jeremy") + HelloJob.set(queue: :other_queue).perform_later("bogdan") + + perform_enqueued_jobs + + assert_performed_jobs 1, queue: :some_queue + end + + def test_assert_performed_jobs_without_block_with_queue_option_failure + HelloJob.set(queue: :other_queue).perform_later("jeremy") + HelloJob.set(queue: :other_queue).perform_later("bogdan") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, queue: :some_queue + end + + assert_match(/1 .* but 0/, error.message) + end + def test_assert_performed_jobs_with_only_and_queue_options assert_performed_jobs 1, only: HelloJob, queue: :some_queue do HelloJob.set(queue: :some_queue).perform_later("jeremy") @@ -1064,6 +1143,30 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 0/, error.message) end + def test_assert_performed_jobs_without_block_with_only_and_queue_options + HelloJob.set(queue: :some_queue).perform_later("jeremy") + HelloJob.set(queue: :other_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + assert_performed_jobs 1, only: HelloJob, queue: :some_queue + end + + def test_assert_performed_jobs_without_block_with_only_and_queue_options_failure + HelloJob.set(queue: :other_queue).perform_later("jeremy") + HelloJob.set(queue: :other_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, only: HelloJob, queue: :some_queue + end + + assert_match(/1 .* but 0/, error.message) + end + def test_assert_performed_jobs_with_except_and_queue_options assert_performed_jobs 1, except: HelloJob, queue: :other_queue do HelloJob.set(queue: :other_queue).perform_later("jeremy") @@ -1084,6 +1187,30 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/1 .* but 0/, error.message) end + def test_assert_performed_jobs_without_block_with_except_and_queue_options + HelloJob.set(queue: :other_queue).perform_later("jeremy") + LoggingJob.set(queue: :some_queue).perform_later("bogdan") + LoggingJob.set(queue: :other_queue).perform_later("jeremy") + + perform_enqueued_jobs + + assert_performed_jobs 1, except: HelloJob, queue: :other_queue + end + + def test_assert_performed_jobs_with_except_and_queue_options_failuree + HelloJob.set(queue: :other_queue).perform_later("jeremy") + LoggingJob.set(queue: :some_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_performed_jobs 1, except: HelloJob, queue: :other_queue + end + + assert_match(/1 .* but 0/, error.message) + end + def test_assert_no_performed_jobs_with_only_option assert_nothing_raised do assert_no_performed_jobs only: HelloJob do @@ -1092,6 +1219,26 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_no_performed_jobs_without_block_with_only_option + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + assert_no_performed_jobs only: HelloJob + end + + def test_assert_no_performed_jobs_without_block_with_only_option_failure + HelloJob.perform_later("bogdan") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs only: HelloJob + end + + assert_match(/0 .* but 1/, error.message) + end + def test_assert_no_performed_jobs_with_except_option assert_nothing_raised do assert_no_performed_jobs except: LoggingJob do @@ -1100,6 +1247,26 @@ class PerformedJobsTest < ActiveJob::TestCase end end + def test_assert_no_performed_jobs_without_block_with_except_option + HelloJob.perform_later("jeremy") + + perform_enqueued_jobs + + assert_no_performed_jobs except: HelloJob + end + + def test_assert_no_performed_jobs_without_block_with_except_option_failure + LoggingJob.perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs except: HelloJob + end + + assert_match(/0 .* but 1/, error.message) + end + def test_assert_no_performed_jobs_with_only_and_except_option error = assert_raise ArgumentError do assert_no_performed_jobs only: HelloJob, except: HelloJob do @@ -1110,6 +1277,19 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/`:only` and `:except`/, error.message) end + def test_assert_no_performed_jobs_without_block_with_only_and_except_options + error = assert_raise ArgumentError do + HelloJob.perform_later("jeremy") + LoggingJob.perform_later("bogdan") + + perform_enqueued_jobs + + assert_no_performed_jobs only: HelloJob, except: HelloJob + end + + assert_match(/`:only` and `:except`/, error.message) + end + def test_assert_no_performed_jobs_with_only_option_as_array assert_nothing_raised do assert_no_performed_jobs only: [HelloJob, RescueJob] do @@ -1186,6 +1366,26 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/0 .* but 1/, error.message) end + def test_assert_no_performed_jobs_without_block_with_queue_option + HelloJob.set(queue: :other_queue).perform_later("jeremy") + + perform_enqueued_jobs + + assert_no_performed_jobs queue: :some_queue + end + + def test_assert_no_performed_jobs_without_block_with_queue_option_failure + HelloJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs queue: :some_queue + end + + assert_match(/0 .* but 1/, error.message) + end + def test_assert_no_performed_jobs_with_only_and_queue_options assert_no_performed_jobs only: HelloJob, queue: :some_queue do HelloJob.set(queue: :other_queue).perform_later("bogdan") @@ -1204,6 +1404,28 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/0 .* but 1/, error.message) end + def test_assert_no_performed_jobs_without_block_with_only_and_queue_options + HelloJob.set(queue: :other_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + assert_no_performed_jobs only: HelloJob, queue: :some_queue + end + + def test_assert_no_performed_jobs_without_block_with_only_and_queue_options_failure + HelloJob.set(queue: :some_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs only: HelloJob, queue: :some_queue + end + + assert_match(/0 .* but 1/, error.message) + end + def test_assert_no_performed_jobs_with_except_and_queue_options assert_no_performed_jobs except: HelloJob, queue: :some_queue do HelloJob.set(queue: :other_queue).perform_later("bogdan") @@ -1224,6 +1446,30 @@ class PerformedJobsTest < ActiveJob::TestCase assert_match(/0 .* but 1/, error.message) end + def test_assert_no_performed_jobs_without_block_with_except_and_queue_options + HelloJob.set(queue: :other_queue).perform_later("bogdan") + HelloJob.set(queue: :some_queue).perform_later("bogdan") + LoggingJob.set(queue: :other_queue).perform_later("jeremy") + + perform_enqueued_jobs + + assert_no_performed_jobs except: HelloJob, queue: :some_queue + end + + def test_assert_no_performed_jobs_without_block_with_except_and_queue_options_failure + HelloJob.set(queue: :other_queue).perform_later("bogdan") + HelloJob.set(queue: :some_queue).perform_later("bogdan") + LoggingJob.set(queue: :some_queue).perform_later("jeremy") + + perform_enqueued_jobs + + error = assert_raise ActiveSupport::TestCase::Assertion do + assert_no_performed_jobs except: HelloJob, queue: :some_queue + end + + assert_match(/0 .* but 1/, error.message) + end + def test_assert_performed_job assert_performed_with(job: NestedJob, queue: "default") do NestedJob.perform_later |