2017-07-09 13:49:52 -04:00
|
|
|
# frozen_string_literal: true
|
2017-07-10 09:40:03 -04:00
|
|
|
|
2016-08-06 12:41:18 -04:00
|
|
|
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"
|
2016-09-04 20:13:24 -04:00
|
|
|
require "jobs/inherited_job"
|
2018-09-12 01:22:17 -04:00
|
|
|
require "jobs/multiple_kwargs_job"
|
2016-08-06 12:41:18 -04:00
|
|
|
require "models/person"
|
2014-08-26 16:08:49 -04:00
|
|
|
|
|
|
|
class EnqueuedJobsTest < ActiveJob::TestCase
|
|
|
|
def test_assert_enqueued_jobs
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("david")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_repeated_enqueued_jobs_calls
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("abdelkader")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
|
|
|
HelloJob.perform_later("yves")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-01 02:53:18 -04:00
|
|
|
def test_assert_enqueued_jobs_message
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
2015-05-01 02:53:18 -04:00
|
|
|
e = assert_raises Minitest::Assertion do
|
|
|
|
assert_enqueued_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
2015-05-01 02:53:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_match "Expected: 2", e.message
|
|
|
|
assert_match "Actual: 1", e.message
|
|
|
|
end
|
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_enqueued_jobs_with_no_block
|
|
|
|
assert_nothing_raised do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("rafael")
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_enqueued_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("aaron")
|
|
|
|
HelloJob.perform_later("matthew")
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_enqueued_jobs 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-11-20 14:23:03 -05:00
|
|
|
def test_assert_no_enqueued_jobs_with_no_block
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_no_enqueued_jobs
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs do
|
2014-11-20 14:23:03 -05:00
|
|
|
HelloJob.perform_now
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_too_few_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("xavier")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/2 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_too_many_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("cristian")
|
|
|
|
HelloJob.perform_later("guillermo")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
2014-09-02 10:06:19 -04:00
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_no_enqueued_jobs_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-01-07 23:33:01 -05:00
|
|
|
def test_assert_enqueued_jobs_with_only_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1, only: HelloJob do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-01-07 23:33:01 -05:00
|
|
|
LoggingJob.perform_later
|
2017-07-16 04:35:17 -04:00
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_enqueued_jobs_with_only_option_as_proc
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs(1, only: ->(job) { job.fetch(:job).name == "HelloJob" }) do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1, except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_enqueued_jobs_with_except_option_as_proc
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs(1, except: ->(job) { job.fetch(:job).name == "LoggingJob" }) do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_option
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
LoggingJob.perform_later
|
2015-01-07 23:33:01 -05:00
|
|
|
end
|
|
|
|
end
|
2017-07-16 04:35:17 -04:00
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
2015-01-07 23:33:01 -05:00
|
|
|
end
|
|
|
|
|
2017-01-09 15:40:32 -05:00
|
|
|
def test_assert_enqueued_jobs_with_only_and_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1, only: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_and_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1, except: LoggingJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_and_queue_option
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 1, only: HelloJob, except: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-01-09 15:40:32 -05:00
|
|
|
def test_assert_enqueued_jobs_with_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 2, queue: :default do
|
|
|
|
HelloJob.perform_later
|
|
|
|
LoggingJob.perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-01-07 23:33:01 -05:00
|
|
|
def test_assert_enqueued_jobs_with_only_option_and_none_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 1, only: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_option_and_none_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 1, except: LoggingJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_option_and_none_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-01-07 23:33:01 -05:00
|
|
|
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
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-01-07 23:33:01 -05:00
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/5 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_option_and_too_few_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 5, except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/5 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_option_and_too_few_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 5, only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-01-07 23:33:01 -05:00
|
|
|
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
|
2016-08-06 12:41:18 -04:00
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
2015-01-07 23:33:01 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_option_and_too_many_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_jobs 1, except: LoggingJob do
|
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_option_and_too_many_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-10-03 07:25:16 -04:00
|
|
|
def test_assert_enqueued_jobs_with_only_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 2, only: [HelloJob, LoggingJob] do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
2015-10-03 07:25:16 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_enqueued_jobs_with_except_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_enqueued_jobs 1, except: [HelloJob, LoggingJob] do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_jobs_with_only_and_except_option_as_array
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_enqueued_jobs 2, only: [HelloJob, LoggingJob], except: [HelloJob, LoggingJob] do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-01-08 09:39:01 -05:00
|
|
|
def test_assert_no_enqueued_jobs_with_only_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs only: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_enqueued_jobs_with_except_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs except: LoggingJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_except_option
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_enqueued_jobs only: HelloJob, except: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-01-08 09:39:01 -05:00
|
|
|
def test_assert_no_enqueued_jobs_with_only_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs only: HelloJob do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-01-08 09:39:01 -05:00
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_enqueued_jobs_with_except_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_except_option_failure
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_enqueued_jobs only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-10-03 07:25:16 -04:00
|
|
|
def test_assert_no_enqueued_jobs_with_only_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs only: [HelloJob, RescueJob] do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_enqueued_jobs_with_except_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs except: [HelloJob, RescueJob] do
|
|
|
|
HelloJob.perform_later
|
|
|
|
RescueJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_except_option_as_array
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_enqueued_jobs only: [HelloJob, RescueJob], except: [HelloJob, RescueJob] do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-06-30 11:20:04 -04:00
|
|
|
def test_assert_no_enqueued_jobs_with_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs queue: :default do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_queue_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs queue: :other_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs only: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_queue_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs only: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_except_and_queue_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_enqueued_jobs except: LoggingJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_except_and_queue_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_enqueued_jobs except: LoggingJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_enqueued_jobs_with_only_and_except_and_queue_option
|
|
|
|
error = assert_raise ArgumentError do
|
|
|
|
assert_no_enqueued_jobs only: HelloJob, except: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_enqueued_with(job: LoggingJob, queue: "default") do
|
2014-11-20 14:23:03 -05:00
|
|
|
LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block
|
|
|
|
LoggingJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
assert_enqueued_with(job: LoggingJob, queue: "default")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_returns
|
2015-07-23 18:45:07 -04:00
|
|
|
job = assert_enqueued_with(job: LoggingJob) do
|
2018-10-09 13:46:16 -04:00
|
|
|
LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3, keyword: true)
|
2015-07-23 18:45:07 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
assert_instance_of LoggingJob, job
|
|
|
|
assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_equal "default", job.queue_name
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_equal [1, 2, 3, { keyword: true }], job.arguments
|
2015-07-23 18:45:07 -04:00
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block_returns
|
2018-10-09 13:46:16 -04:00
|
|
|
LoggingJob.set(wait_until: 5.minutes.from_now).perform_later(1, 2, 3, keyword: true)
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
job = assert_enqueued_with(job: LoggingJob)
|
|
|
|
|
|
|
|
assert_instance_of LoggingJob, job
|
|
|
|
assert_in_delta 5.minutes.from_now, job.scheduled_at, 1
|
|
|
|
assert_equal "default", job.queue_name
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_equal [1, 2, 3, { keyword: true }], job.arguments
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_failure
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_enqueued_with(job: LoggingJob, queue: "default") do
|
2014-08-25 10:34:50 -04:00
|
|
|
NestedJob.perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
LoggingJob.perform_later
|
2018-09-25 13:18:20 -04:00
|
|
|
assert_enqueued_with(job: LoggingJob) { }
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
end
|
|
|
|
|
2014-09-22 10:40:41 -04:00
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_enqueued_with(job: NestedJob, queue: "low") do
|
2014-08-25 10:34:50 -04:00
|
|
|
NestedJob.perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
2014-09-22 10:40:41 -04:00
|
|
|
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No enqueued job found with {:job=>NestedJob, :queue=>"low"}/, error.message)
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block_failure
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
NestedJob.perform_later
|
|
|
|
assert_enqueued_with(job: LoggingJob, queue: "default")
|
|
|
|
end
|
|
|
|
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
NestedJob.perform_later
|
|
|
|
assert_enqueued_with(job: NestedJob, queue: "low")
|
|
|
|
end
|
|
|
|
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No enqueued job found with {:job=>NestedJob, :queue=>"low"}/, error.message)
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_args
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_raise ArgumentError do
|
2014-08-29 16:11:17 -04:00
|
|
|
assert_enqueued_with(class: LoggingJob) do
|
2014-08-25 10:34:50 -04:00
|
|
|
NestedJob.set(wait_until: Date.tomorrow.noon).perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 06:01:25 -05:00
|
|
|
|
2018-09-26 18:45:52 -04:00
|
|
|
def test_assert_enqueued_with_selective_args
|
|
|
|
args = ->(job_args) do
|
|
|
|
assert_equal 1, job_args.first[:argument1]
|
|
|
|
assert job_args.first[:argument2].key?(:b)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_selective_args_fails
|
|
|
|
args = ->(job_args) do
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-22 15:52:36 -04:00
|
|
|
def test_assert_enqueued_with_time
|
|
|
|
now = Time.now
|
|
|
|
args = [{ argument1: [now] }]
|
|
|
|
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: [now])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_date_time
|
|
|
|
now = DateTime.now
|
|
|
|
args = [{ argument1: [now] }]
|
|
|
|
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: [now])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_time_with_zone
|
|
|
|
now = Time.now.in_time_zone("Tokyo")
|
|
|
|
args = [{ argument1: [now] }]
|
|
|
|
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: [now])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block_args
|
|
|
|
assert_raise ArgumentError do
|
|
|
|
NestedJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
assert_enqueued_with(class: LoggingJob)
|
2015-10-03 09:18:25 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-06-29 12:35:47 -04:00
|
|
|
def test_assert_enqueued_with_with_at_option
|
|
|
|
assert_enqueued_with(job: HelloJob, at: Date.tomorrow.noon) do
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-25 18:41:15 -04:00
|
|
|
def test_assert_enqueued_with_with_relative_at_option
|
|
|
|
assert_enqueued_with(job: HelloJob, at: 5.minutes.from_now) do
|
|
|
|
HelloJob.set(wait: 5.minutes).perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block_with_at_option
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
assert_enqueued_with(job: HelloJob, at: Date.tomorrow.noon)
|
|
|
|
end
|
|
|
|
|
2018-09-12 01:22:17 -04:00
|
|
|
def test_assert_enqueued_with_with_hash_arg
|
|
|
|
assert_enqueued_with(job: MultipleKwargsJob, args: [{ argument1: 1, argument2: { a: 1, b: 2 } }]) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_global_id_args
|
2015-01-23 06:01:25 -05:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
assert_enqueued_with(job: HelloJob, args: [ricardo]) do
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
def test_assert_enqueued_with_with_no_block_with_global_id_args
|
|
|
|
ricardo = Person.new(9)
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
assert_enqueued_with(job: HelloJob, args: [ricardo])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_enqueued_with_failure_with_global_id_args
|
2015-01-23 06:01:25 -05:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
wilma = Person.new(11)
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_enqueued_with(job: HelloJob, args: [wilma]) do
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
end
|
|
|
|
end
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No enqueued job found with {:job=>HelloJob, :args=>\[#{wilma.inspect}\]}/, error.message)
|
|
|
|
assert_match(/Potential matches: {:job=>HelloJob, :args=>\[#<Person.* @id=\"9\"\>\], :queue=>\"default\"}/, error.message)
|
2015-01-23 06:01:25 -05:00
|
|
|
end
|
2015-10-07 13:55:57 -04:00
|
|
|
|
2018-06-29 12:35:47 -04:00
|
|
|
def test_assert_enqueued_with_failure_with_no_block_with_global_id_args
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
wilma = Person.new(11)
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
assert_enqueued_with(job: HelloJob, args: [wilma])
|
|
|
|
end
|
|
|
|
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No enqueued job found with {:job=>HelloJob, :args=>\[#{wilma.inspect}\]}/, error.message)
|
|
|
|
assert_match(/Potential matches: {:job=>HelloJob, :args=>\[#<Person.* @id=\"9\"\>\], :queue=>\"default\"}/, error.message)
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
end
|
|
|
|
|
2018-06-29 12:35:47 -04:00
|
|
|
def test_assert_enqueued_with_does_not_change_jobs_count
|
2015-10-07 13:55:57 -04:00
|
|
|
HelloJob.perform_later
|
|
|
|
assert_enqueued_with(job: HelloJob) do
|
|
|
|
HelloJob.perform_later
|
|
|
|
end
|
|
|
|
|
2016-10-24 22:25:48 -04:00
|
|
|
assert_equal 2, queue_adapter.enqueued_jobs.count
|
2015-10-07 13:55:57 -04:00
|
|
|
end
|
Allow call `assert_enqueued_with` and `assert_enqueued_email_with` with no block
Example of `assert_enqueued_with` with no block
```ruby
def test_assert_enqueued_with
MyJob.perform_later(1,2,3)
assert_enqueued_with(job: MyJob, args: [1,2,3], queue: 'low')
MyJob.set(wait_until: Date.tomorrow.noon).perform_later
assert_enqueued_with(job: MyJob, at: Date.tomorrow.noon)
end
```
Example of `assert_enqueued_email_with` with no block:
```ruby
def test_email
ContactMailer.welcome.deliver_later
assert_enqueued_email_with ContactMailer, :welcome
end
def test_email_with_arguments
ContactMailer.welcome("Hello", "Goodbye").deliver_later
assert_enqueued_email_with ContactMailer, :welcome, args: ["Hello", "Goodbye"]
end
```
Related to #33243
2018-06-29 08:17:26 -04:00
|
|
|
|
|
|
|
def test_assert_enqueued_with_with_no_block_does_not_change_jobs_count
|
|
|
|
HelloJob.perform_later
|
|
|
|
HelloJob.perform_later
|
|
|
|
assert_enqueued_with(job: HelloJob)
|
|
|
|
|
|
|
|
assert_equal 2, queue_adapter.enqueued_jobs.count
|
|
|
|
end
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
class PerformedJobsTest < ActiveJob::TestCase
|
2018-08-15 15:00:40 -04:00
|
|
|
def test_perform_enqueued_jobs_with_only_option_doesnt_leak_outside_the_block
|
2016-12-24 12:29:52 -05:00
|
|
|
assert_nil queue_adapter.filter
|
2015-03-06 12:41:46 -05:00
|
|
|
perform_enqueued_jobs only: HelloJob do
|
|
|
|
assert_equal HelloJob, queue_adapter.filter
|
|
|
|
end
|
2016-12-24 12:29:52 -05:00
|
|
|
assert_nil queue_adapter.filter
|
2015-03-06 12:41:46 -05:00
|
|
|
end
|
|
|
|
|
2018-08-16 11:14:53 -04:00
|
|
|
def test_perform_enqueued_jobs_without_block_with_only_option_doesnt_leak
|
|
|
|
perform_enqueued_jobs only: HelloJob
|
|
|
|
|
|
|
|
assert_nil queue_adapter.filter
|
|
|
|
end
|
|
|
|
|
2018-08-15 15:00:40 -04:00
|
|
|
def test_perform_enqueued_jobs_with_except_option_doesnt_leak_outside_the_block
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_nil queue_adapter.reject
|
|
|
|
perform_enqueued_jobs except: HelloJob do
|
|
|
|
assert_equal HelloJob, queue_adapter.reject
|
|
|
|
end
|
|
|
|
assert_nil queue_adapter.reject
|
|
|
|
end
|
|
|
|
|
2018-08-16 11:14:53 -04:00
|
|
|
def test_perform_enqueued_jobs_without_block_with_except_option_doesnt_leak
|
|
|
|
perform_enqueued_jobs except: HelloJob
|
|
|
|
|
|
|
|
assert_nil queue_adapter.reject
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_queue_option_doesnt_leak_outside_the_block
|
|
|
|
assert_nil queue_adapter.queue
|
|
|
|
perform_enqueued_jobs queue: :some_queue do
|
|
|
|
assert_equal :some_queue, queue_adapter.queue
|
|
|
|
end
|
|
|
|
assert_nil queue_adapter.queue
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_without_block_with_queue_option_doesnt_leak
|
|
|
|
perform_enqueued_jobs queue: :some_queue
|
|
|
|
|
|
|
|
assert_nil queue_adapter.reject
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_block
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 2
|
|
|
|
end
|
|
|
|
|
2018-08-15 15:00:40 -04:00
|
|
|
def test_perform_enqueued_jobs_without_block
|
|
|
|
HelloJob.perform_later("kevin")
|
2018-08-16 11:14:53 -04:00
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_performed_jobs 2
|
|
|
|
end
|
2018-08-15 15:00:40 -04:00
|
|
|
|
2018-08-16 11:14:53 -04:00
|
|
|
def test_perform_enqueued_jobs_with_block_with_only_option
|
|
|
|
perform_enqueued_jobs only: LoggingJob do
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
2018-08-15 15:00:40 -04:00
|
|
|
end
|
2018-08-16 11:14:53 -04:00
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob
|
2018-08-15 15:00:40 -04:00
|
|
|
end
|
|
|
|
|
2018-08-16 11:14:53 -04:00
|
|
|
def test_perform_enqueued_jobs_without_block_with_only_option
|
2018-08-15 15:00:40 -04:00
|
|
|
HelloJob.perform_later("kevin")
|
2018-08-16 11:14:53 -04:00
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs only: LoggingJob
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
2018-08-15 15:00:40 -04:00
|
|
|
|
2018-08-16 11:14:53 -04:00
|
|
|
def test_perform_enqueued_jobs_with_block_with_except_option
|
|
|
|
perform_enqueued_jobs except: HelloJob do
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
2018-08-15 15:00:40 -04:00
|
|
|
end
|
2018-08-16 11:14:53 -04:00
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_without_block_with_except_option
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs except: HelloJob
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_block_with_queue_option
|
|
|
|
perform_enqueued_jobs queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later("kevin")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, queue: :some_queue
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_without_block_with_queue_option
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later("kevin")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs queue: :some_queue
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, queue: :some_queue
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_block_with_only_and_queue_options
|
|
|
|
perform_enqueued_jobs only: HelloJob, queue: :other_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later("kevin")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, queue: :other_queue
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_without_block_with_only_and_queue_options
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later("kevin")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs only: HelloJob, queue: :other_queue
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, queue: :other_queue
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_block_with_except_and_queue_options
|
|
|
|
perform_enqueued_jobs except: HelloJob, queue: :other_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("kevin")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob, queue: :other_queue
|
2018-08-16 11:14:53 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_without_block_with_except_and_queue_options
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("kevin")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs except: HelloJob, queue: :other_queue
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
2018-08-16 14:54:26 -04:00
|
|
|
assert_performed_jobs 1, only: LoggingJob, queue: :other_queue
|
2018-08-15 15:00:40 -04:00
|
|
|
end
|
|
|
|
|
2019-08-06 09:08:23 -04:00
|
|
|
def test_perform_enqueued_jobs_with_at_with_job_performed_now
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
|
|
|
|
perform_enqueued_jobs(at: Time.now)
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_at_with_job_wait_in_past
|
|
|
|
HelloJob.set(wait_until: Time.now - 100).perform_later("kevin")
|
|
|
|
|
|
|
|
perform_enqueued_jobs(at: Time.now)
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_with_at_with_job_wait_in_future
|
|
|
|
HelloJob.set(wait_until: Time.now + 100).perform_later("kevin")
|
|
|
|
|
|
|
|
perform_enqueued_jobs(at: Time.now)
|
|
|
|
|
|
|
|
assert_performed_jobs 0
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_block_with_at_with_job_performed_now
|
|
|
|
perform_enqueued_jobs(at: Time.now) do
|
|
|
|
HelloJob.perform_later("kevin")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_block_with_at_with_job_wait_in_past
|
|
|
|
perform_enqueued_jobs(at: Time.now) do
|
|
|
|
HelloJob.set(wait_until: Time.now - 100).perform_later("kevin")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_perform_enqueued_jobs_block_with_at_with_job_wait_in_future
|
|
|
|
perform_enqueued_jobs(at: Time.now) do
|
|
|
|
HelloJob.set(wait_until: Time.now + 100).perform_later("kevin")
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_jobs 0
|
|
|
|
end
|
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_performed_jobs
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("david")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_repeated_performed_jobs_calls
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("abdelkader")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
|
|
|
HelloJob.perform_later("yves")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2015-05-01 02:53:18 -04:00
|
|
|
def test_assert_performed_jobs_message
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
2015-05-01 02:53:18 -04:00
|
|
|
e = assert_raises Minitest::Assertion do
|
|
|
|
assert_performed_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("sean")
|
2015-05-01 02:53:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
assert_match "Expected: 2", e.message
|
|
|
|
assert_match "Actual: 1", e.message
|
|
|
|
end
|
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_performed_jobs_with_no_block
|
|
|
|
assert_nothing_raised do
|
2014-11-20 14:23:03 -05:00
|
|
|
perform_enqueued_jobs do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("rafael")
|
2014-11-20 14:23:03 -05:00
|
|
|
end
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_performed_jobs 1
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_nothing_raised do
|
2014-11-20 14:23:03 -05:00
|
|
|
perform_enqueued_jobs do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("aaron")
|
|
|
|
HelloJob.perform_later("matthew")
|
2014-11-20 14:23:03 -05:00
|
|
|
assert_performed_jobs 3
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_performed_jobs_with_no_block
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_performed_jobs
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs do
|
2014-11-20 14:23:03 -05:00
|
|
|
# empty block won't perform jobs
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_too_few_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 2 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("xavier")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/2 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_too_many_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1 do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("cristian")
|
|
|
|
HelloJob.perform_later("guillermo")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
2014-09-02 10:06:19 -04:00
|
|
|
|
2014-08-26 16:08:49 -04:00
|
|
|
def test_assert_no_performed_jobs_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_performed_jobs do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_performed_jobs_with_only_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 1, only: HelloJob do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-02-06 13:05:28 -05:00
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_performed_jobs_with_only_option_as_proc
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs(1, only: ->(job) { job.is_a?(HelloJob) }) do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_performed_jobs_without_block_with_only_option_as_proc
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_performed_jobs(1, only: ->(job) { job.fetch(:job).name == "HelloJob" })
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_except_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 1, except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_performed_jobs_with_except_option_as_proc
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs(1, except: ->(job) { job.is_a?(HelloJob) }) do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-11-21 16:43:14 -05:00
|
|
|
def test_assert_performed_jobs_without_block_with_except_option_as_proc
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("bogdan")
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_performed_jobs(1, except: ->(job) { job.fetch(:job).name == "HelloJob" })
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_only_and_except_option
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_performed_jobs_with_only_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 2, only: [HelloJob, LoggingJob] do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
2015-02-06 13:05:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_except_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_performed_jobs 1, except: [LoggingJob, RescueJob] do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_only_and_except_option_as_array
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_performed_jobs 2, only: [HelloJob, LoggingJob], except: [HelloJob, LoggingJob] do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later("stewie")
|
|
|
|
RescueJob.perform_later("david")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_performed_jobs_with_only_option_and_none_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, only: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_except_option_and_none_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, except: LoggingJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_only_and_except_option_and_none_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
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
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-02-06 13:05:28 -05:00
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/5 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_except_option_and_too_few_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 5, except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/5 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_only_and_except_option_and_too_few_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_performed_jobs 5, only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
4.times { LoggingJob.perform_later }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
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
|
2016-08-06 12:41:18 -04:00
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
2015-02-06 13:05:28 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_performed_jobs_with_except_option_and_too_many_sent
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, except: LoggingJob do
|
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 2/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_only_and_except_option_and_too_many_sent
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_performed_jobs 1, only: HelloJob, except: HelloJob do
|
|
|
|
2.times { HelloJob.perform_later("jeremy") }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 12:21:12 -04:00
|
|
|
def test_assert_performed_jobs_with_queue_option
|
|
|
|
assert_performed_jobs 1, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :some_queue).perform_later("jeremy")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_queue_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("jeremy")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 12:21:12 -04:00
|
|
|
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")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_jobs_with_only_and_queue_options_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, only: HelloJob, queue: :some_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("jeremy")
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 12:21:12 -04:00
|
|
|
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")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :other_queue).perform_later("jeremy")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-22 02:53:36 -04:00
|
|
|
def test_assert_performed_jobs_with_except_and_queue_options_failure
|
2018-08-16 12:21:12 -04:00
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_jobs 1, except: HelloJob, queue: :other_queue do
|
|
|
|
HelloJob.set(queue: :other_queue).perform_later("jeremy")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("bogdan")
|
|
|
|
LoggingJob.set(queue: :some_queue).perform_later("jeremy")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/1 .* but 0/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-22 02:53:36 -04:00
|
|
|
def test_assert_performed_jobs_without_block_with_except_and_queue_options_failure
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_no_performed_jobs_with_only_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs only: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_performed_jobs_with_except_option
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs except: LoggingJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_performed_jobs_with_only_and_except_option
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_performed_jobs only: HelloJob, except: HelloJob do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_no_performed_jobs_with_only_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs only: [HelloJob, RescueJob] do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_performed_jobs_with_except_option_as_array
|
|
|
|
assert_nothing_raised do
|
|
|
|
assert_no_performed_jobs except: [HelloJob, RescueJob] do
|
|
|
|
HelloJob.perform_later
|
|
|
|
RescueJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_performed_jobs_with_only_and_except_option_as_array
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_performed_jobs only: [HelloJob, RescueJob], except: [HelloJob, RescueJob] do
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2015-02-06 13:05:28 -05:00
|
|
|
def test_assert_no_performed_jobs_with_only_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_performed_jobs only: HelloJob do
|
2016-08-06 12:41:18 -04:00
|
|
|
HelloJob.perform_later("jeremy")
|
2015-02-06 13:05:28 -05:00
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
2017-07-16 04:35:17 -04:00
|
|
|
def test_assert_no_performed_jobs_with_except_option_failure
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_no_performed_jobs except: LoggingJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/0 .* but 1/, error.message)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_no_performed_jobs_with_only_and_except_option_failure
|
2017-07-19 18:38:26 -04:00
|
|
|
error = assert_raise ArgumentError do
|
2017-07-16 04:35:17 -04:00
|
|
|
assert_no_performed_jobs only: HelloJob, except: HelloJob do
|
|
|
|
HelloJob.perform_later("jeremy")
|
|
|
|
LoggingJob.perform_later
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_match(/`:only` and `:except`/, error.message)
|
|
|
|
end
|
|
|
|
|
2018-08-16 12:49:14 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 12:49:14 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 12:49:14 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 14:54:26 -04:00
|
|
|
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
|
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_performed_with(job: NestedJob, queue: "default") do
|
2014-08-25 10:34:50 -04:00
|
|
|
NestedJob.perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with_without_block
|
|
|
|
NestedJob.perform_later
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_performed_with(job: NestedJob, queue: "default")
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_returns
|
2018-10-09 13:46:16 -04:00
|
|
|
job = assert_performed_with(job: LoggingJob, queue: "default") do
|
|
|
|
LoggingJob.perform_later(keyword: :sym)
|
2015-07-23 18:45:07 -04:00
|
|
|
end
|
|
|
|
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_instance_of LoggingJob, job
|
2015-07-23 18:45:07 -04:00
|
|
|
assert_nil job.scheduled_at
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_equal [{ keyword: :sym }], job.arguments
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_equal "default", job.queue_name
|
2015-07-23 18:45:07 -04:00
|
|
|
end
|
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with_without_block_returns
|
2018-10-09 13:46:16 -04:00
|
|
|
LoggingJob.perform_later(keyword: :sym)
|
2018-08-16 15:38:35 -04:00
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
2018-10-09 13:46:16 -04:00
|
|
|
job = assert_performed_with(job: LoggingJob, queue: "default")
|
2018-08-16 15:38:35 -04:00
|
|
|
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_instance_of LoggingJob, job
|
2018-08-16 15:38:35 -04:00
|
|
|
assert_nil job.scheduled_at
|
2018-10-09 13:46:16 -04:00
|
|
|
assert_equal [{ keyword: :sym }], job.arguments
|
2018-08-16 15:38:35 -04:00
|
|
|
assert_equal "default", job.queue_name
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_failure
|
2014-08-26 16:08:49 -04:00
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
2015-10-03 09:18:25 -04:00
|
|
|
assert_performed_with(job: LoggingJob) do
|
|
|
|
HelloJob.perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
2016-08-06 12:41:18 -04:00
|
|
|
assert_performed_with(job: HelloJob, queue: "low") do
|
|
|
|
HelloJob.set(queue: "important").perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 06:01:25 -05:00
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with_without_block_failure
|
|
|
|
HelloJob.perform_later
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: LoggingJob)
|
|
|
|
end
|
|
|
|
|
|
|
|
HelloJob.set(queue: "important").perform_later
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, queue: "low")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_with_at_option
|
2015-10-03 09:18:25 -04:00
|
|
|
assert_performed_with(job: HelloJob, at: Date.tomorrow.noon) do
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
end
|
2015-10-05 03:01:12 -04:00
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, at: Date.today.noon) do
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
2019-07-25 18:41:15 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_with_relative_at_option
|
|
|
|
assert_performed_with(job: HelloJob, at: 5.minutes.from_now) do
|
|
|
|
HelloJob.set(wait: 5.minutes).perform_later
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, at: 2.minutes.from_now) do
|
|
|
|
HelloJob.set(wait: 1.minute).perform_later
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2015-01-23 06:01:25 -05:00
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with_without_block_with_at_option
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_performed_with(job: HelloJob, at: Date.tomorrow.noon)
|
|
|
|
|
|
|
|
HelloJob.set(wait_until: Date.tomorrow.noon).perform_later
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, at: Date.today.noon)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-12 01:22:17 -04:00
|
|
|
def test_assert_performed_with_with_hash_arg
|
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: [{ argument1: 1, argument2: { a: 1, b: 2 } }]) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-26 18:45:52 -04:00
|
|
|
def test_assert_performed_with_selective_args
|
|
|
|
args = ->(job_args) do
|
|
|
|
assert_equal 1, job_args.first[:argument1]
|
|
|
|
assert job_args.first[:argument2].key?(:b)
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_selective_args_fails
|
|
|
|
args = ->(job_args) do
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument2: { b: 2, a: 1 }, argument1: 1)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-03-22 15:52:36 -04:00
|
|
|
def test_assert_performed_with_time
|
|
|
|
now = Time.now
|
2019-03-25 01:31:17 -04:00
|
|
|
args = [{ argument1: { now: now }, argument2: now }]
|
2019-03-22 15:52:36 -04:00
|
|
|
|
2019-03-25 01:31:17 -04:00
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: { now: now }, argument2: now)
|
2019-03-22 15:52:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_date_time
|
|
|
|
now = DateTime.now
|
2019-03-25 01:31:17 -04:00
|
|
|
args = [{ argument1: { now: now }, argument2: now }]
|
2019-03-22 15:52:36 -04:00
|
|
|
|
2019-03-25 01:31:17 -04:00
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: { now: now }, argument2: now)
|
2019-03-22 15:52:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_time_with_zone
|
|
|
|
now = Time.now.in_time_zone("Tokyo")
|
2019-03-25 01:31:17 -04:00
|
|
|
args = [{ argument1: { now: now }, argument2: now }]
|
2019-03-22 15:52:36 -04:00
|
|
|
|
2019-03-25 01:31:17 -04:00
|
|
|
assert_performed_with(job: MultipleKwargsJob, args: args) do
|
|
|
|
MultipleKwargsJob.perform_later(argument1: { now: now }, argument2: now)
|
2019-03-22 15:52:36 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-09-12 06:05:22 -04:00
|
|
|
def test_assert_performed_with_with_global_id_args
|
2015-01-23 06:01:25 -05:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
assert_performed_with(job: HelloJob, args: [ricardo]) do
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-01-29 10:45:12 -05:00
|
|
|
def test_assert_performed_with_without_block_with_global_id_args
|
2018-08-16 15:38:35 -04:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
perform_enqueued_jobs
|
|
|
|
assert_performed_with(job: HelloJob, args: [ricardo])
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_failure_with_global_id_args
|
2015-01-23 06:01:25 -05:00
|
|
|
ricardo = Person.new(9)
|
|
|
|
wilma = Person.new(11)
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, args: [wilma]) do
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
end
|
|
|
|
end
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No performed job found with {:job=>HelloJob, :args=>\[#{wilma.inspect}\]}/, error.message)
|
|
|
|
assert_match(/Potential matches: {:job=>HelloJob, :args=>\[#<Person.* @id=\"9\"\>\], :queue=>\"default\"}/, error.message)
|
2015-01-23 06:01:25 -05:00
|
|
|
end
|
2015-10-07 13:55:57 -04:00
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
def test_assert_performed_with_without_block_failure_with_global_id_args
|
|
|
|
ricardo = Person.new(9)
|
|
|
|
wilma = Person.new(11)
|
|
|
|
HelloJob.perform_later(ricardo)
|
|
|
|
perform_enqueued_jobs
|
|
|
|
error = assert_raise ActiveSupport::TestCase::Assertion do
|
|
|
|
assert_performed_with(job: HelloJob, args: [wilma])
|
|
|
|
end
|
|
|
|
|
2019-08-12 15:12:23 -04:00
|
|
|
assert_match(/No performed job found with {:job=>HelloJob, :args=>\[#{wilma.inspect}\]}/, error.message)
|
|
|
|
assert_match(/Potential matches: {:job=>HelloJob, :args=>\[#<Person.* @id=\"9\"\>\], :queue=>\"default\"}/, error.message)
|
2018-08-16 15:38:35 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_does_not_change_jobs_count
|
2015-10-07 13:55:57 -04:00
|
|
|
assert_performed_with(job: HelloJob) do
|
|
|
|
HelloJob.perform_later
|
|
|
|
end
|
|
|
|
|
|
|
|
assert_performed_with(job: HelloJob) do
|
|
|
|
HelloJob.perform_later
|
|
|
|
end
|
|
|
|
|
2018-08-16 15:38:35 -04:00
|
|
|
assert_equal 2, queue_adapter.performed_jobs.count
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_assert_performed_with_without_block_does_not_change_jobs_count
|
|
|
|
HelloJob.perform_later
|
|
|
|
perform_enqueued_jobs
|
|
|
|
assert_performed_with(job: HelloJob)
|
|
|
|
|
|
|
|
perform_enqueued_jobs
|
|
|
|
HelloJob.perform_later
|
|
|
|
assert_performed_with(job: HelloJob)
|
|
|
|
|
2016-10-24 22:25:48 -04:00
|
|
|
assert_equal 2, queue_adapter.performed_jobs.count
|
2015-10-07 13:55:57 -04:00
|
|
|
end
|
2014-08-26 16:08:49 -04:00
|
|
|
end
|
2016-06-11 15:18:52 -04:00
|
|
|
|
|
|
|
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
|
2016-09-04 20:13:24 -04:00
|
|
|
|
|
|
|
class InheritedJobTest < ActiveJob::TestCase
|
|
|
|
def test_queue_adapter_is_test_adapter
|
|
|
|
assert_instance_of ActiveJob::QueueAdapters::TestAdapter, InheritedJob.queue_adapter
|
|
|
|
end
|
|
|
|
end
|
2017-01-31 16:37:16 -05:00
|
|
|
|
|
|
|
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
|