aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test
diff options
context:
space:
mode:
authorEdouard CHIN <edouard.chin@shopify.com>2018-11-21 22:43:14 +0100
committerEdouard CHIN <edouard.chin@shopify.com>2018-11-21 23:14:43 +0100
commitcdb16ac576198607916cde6d55fe14cb775a98c9 (patch)
tree2904093cd2a45b8a3b42cbfde48f65ede86c41d7 /activejob/test
parentca0339215f07dfbb927d727b3f66701f176d0a67 (diff)
downloadrails-cdb16ac576198607916cde6d55fe14cb775a98c9.tar.gz
rails-cdb16ac576198607916cde6d55fe14cb775a98c9.tar.bz2
rails-cdb16ac576198607916cde6d55fe14cb775a98c9.zip
Allow all ActiveJob assertion helper to accept Proc in their `only` kw:
- That feature is useful to enqueue or assert that jobs got enqueued or performed based on dynamic conditions. We will be able to leverage that feature to fix all ActionMailer assertion helper issue when a Mailer define a custom delivery job (see next commit).
Diffstat (limited to 'activejob/test')
-rw-r--r--activejob/test/cases/test_helper_test.rb56
1 files changed, 56 insertions, 0 deletions
diff --git a/activejob/test/cases/test_helper_test.rb b/activejob/test/cases/test_helper_test.rb
index 8dc32037ff..046033921d 100644
--- a/activejob/test/cases/test_helper_test.rb
+++ b/activejob/test/cases/test_helper_test.rb
@@ -114,6 +114,16 @@ class EnqueuedJobsTest < ActiveJob::TestCase
end
end
+ 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
+
def test_assert_enqueued_jobs_with_except_option
assert_nothing_raised do
assert_enqueued_jobs 1, except: LoggingJob do
@@ -124,6 +134,16 @@ class EnqueuedJobsTest < ActiveJob::TestCase
end
end
+ 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
+
def test_assert_enqueued_jobs_with_only_and_except_option
error = assert_raise ArgumentError do
assert_enqueued_jobs 1, only: HelloJob, except: HelloJob do
@@ -911,6 +931,15 @@ class PerformedJobsTest < ActiveJob::TestCase
end
end
+ 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
+
def test_assert_performed_jobs_without_block_with_only_option
HelloJob.perform_later("jeremy")
LoggingJob.perform_later("bogdan")
@@ -920,6 +949,15 @@ class PerformedJobsTest < ActiveJob::TestCase
assert_performed_jobs 1, only: HelloJob
end
+ 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
+
def test_assert_performed_jobs_without_block_with_only_option_failure
LoggingJob.perform_later("jeremy")
LoggingJob.perform_later("bogdan")
@@ -942,6 +980,15 @@ class PerformedJobsTest < ActiveJob::TestCase
end
end
+ 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
+
def test_assert_performed_jobs_without_block_with_except_option
HelloJob.perform_later("jeremy")
LoggingJob.perform_later("bogdan")
@@ -951,6 +998,15 @@ class PerformedJobsTest < ActiveJob::TestCase
assert_performed_jobs 1, except: HelloJob
end
+ 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
+
def test_assert_performed_jobs_without_block_with_except_option_failure
HelloJob.perform_later("jeremy")
HelloJob.perform_later("bogdan")