mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Allow :queue
option to assert_no_performed_jobs
.
If the `:queue` option is specified, then only the job(s) enqueued to a specific queue will not be performed. Example: ``` def test_assert_no_performed_jobs_with_queue_option assert_no_performed_jobs queue: :some_queue do HelloJob.set(queue: :other_queue).perform_later("jeremy") end end ```
This commit is contained in:
parent
d50fb21e4d
commit
de4420da44
2 changed files with 65 additions and 2 deletions
|
@ -297,11 +297,20 @@ module ActiveJob
|
|||
# end
|
||||
# end
|
||||
#
|
||||
# If the +:queue+ option is specified,
|
||||
# then only the job(s) enqueued to a specific queue will not be performed.
|
||||
#
|
||||
# def test_assert_no_performed_jobs_with_queue_option
|
||||
# assert_no_performed_jobs queue: :some_queue do
|
||||
# HelloJob.set(queue: :other_queue).perform_later("jeremy")
|
||||
# end
|
||||
# end
|
||||
#
|
||||
# Note: This assertion is simply a shortcut for:
|
||||
#
|
||||
# assert_performed_jobs 0, &block
|
||||
def assert_no_performed_jobs(only: nil, except: nil, &block)
|
||||
assert_performed_jobs 0, only: only, except: except, &block
|
||||
def assert_no_performed_jobs(only: nil, except: nil, queue: nil, &block)
|
||||
assert_performed_jobs 0, only: only, except: except, queue: queue, &block
|
||||
end
|
||||
|
||||
# Asserts that the job has been enqueued with the given arguments.
|
||||
|
|
|
@ -1170,6 +1170,60 @@ class PerformedJobsTest < ActiveJob::TestCase
|
|||
assert_match(/`:only` and `:except`/, error.message)
|
||||
end
|
||||
|
||||
def test_assert_no_performed_jobs_with_queue_option
|
||||
assert_no_performed_jobs queue: :some_queue do
|
||||
HelloJob.set(queue: :other_queue).perform_later("jeremy")
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_no_performed_jobs_with_queue_option_failure
|
||||
error = assert_raise ActiveSupport::TestCase::Assertion do
|
||||
assert_no_performed_jobs queue: :some_queue do
|
||||
HelloJob.set(queue: :some_queue).perform_later("jeremy")
|
||||
end
|
||||
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")
|
||||
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_no_performed_jobs_with_only_and_queue_options_failure
|
||||
error = assert_raise ActiveSupport::TestCase::Assertion do
|
||||
assert_no_performed_jobs only: HelloJob, queue: :some_queue do
|
||||
HelloJob.set(queue: :some_queue).perform_later("bogdan")
|
||||
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
||||
end
|
||||
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")
|
||||
HelloJob.set(queue: :some_queue).perform_later("bogdan")
|
||||
LoggingJob.set(queue: :other_queue).perform_later("jeremy")
|
||||
end
|
||||
end
|
||||
|
||||
def test_assert_no_performed_jobs_with_except_and_queue_options_failure
|
||||
error = assert_raise ActiveSupport::TestCase::Assertion do
|
||||
assert_no_performed_jobs except: HelloJob, queue: :some_queue do
|
||||
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
||||
HelloJob.set(queue: :some_queue).perform_later("bogdan")
|
||||
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
||||
end
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue