diff options
Diffstat (limited to 'activejob/test/cases')
-rw-r--r-- | activejob/test/cases/argument_serialization_test.rb | 10 | ||||
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 22 | ||||
-rw-r--r-- | activejob/test/cases/test_helper_test.rb | 56 |
3 files changed, 88 insertions, 0 deletions
diff --git a/activejob/test/cases/argument_serialization_test.rb b/activejob/test/cases/argument_serialization_test.rb index 8b2981926f..e4e14016d9 100644 --- a/activejob/test/cases/argument_serialization_test.rb +++ b/activejob/test/cases/argument_serialization_test.rb @@ -5,6 +5,7 @@ require "active_job/arguments" require "models/person" require "active_support/core_ext/hash/indifferent_access" require "jobs/kwargs_job" +require "support/stubs/strong_parameters" class ArgumentSerializationTest < ActiveSupport::TestCase setup do @@ -49,6 +50,15 @@ class ArgumentSerializationTest < ActiveSupport::TestCase assert_arguments_roundtrip([a: 1, "b" => 2]) end + test "serialize a ActionController::Parameters" do + parameters = Parameters.new(a: 1) + + assert_equal( + { "a" => 1, "_aj_hash_with_indifferent_access" => true }, + ActiveJob::Arguments.serialize([parameters]).first + ) + end + test "serialize a hash" do symbol_key = { a: 1 } string_key = { "a" => 1 } diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index 37bb65538a..b5328b8d6a 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -30,6 +30,28 @@ class ExceptionsTest < ActiveJob::TestCase end end + test "keeps the same attempts counter when several exceptions are listed in the same declaration" do + exceptions_to_raise = %w(FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo + SecondRetryableErrorOfTwo SecondRetryableErrorOfTwo) + + assert_raises SecondRetryableErrorOfTwo do + perform_enqueued_jobs do + ExceptionRetryJob.perform_later(exceptions_to_raise) + end + end + end + + test "keeps a separate attempts counter for each individual declaration" do + exceptions_to_raise = %w(FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo FirstRetryableErrorOfTwo + DefaultsError DefaultsError) + + assert_nothing_raised do + perform_enqueued_jobs do + ExceptionRetryJob.perform_later(exceptions_to_raise) + end + end + end + test "failed retry job when exception kept occurring against defaults" do perform_enqueued_jobs do begin 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") |