diff options
Diffstat (limited to 'activejob/test/cases')
-rw-r--r-- | activejob/test/cases/callbacks_test.rb | 25 | ||||
-rw-r--r-- | activejob/test/cases/exceptions_test.rb | 20 | ||||
-rw-r--r-- | activejob/test/cases/logging_test.rb | 8 | ||||
-rw-r--r-- | activejob/test/cases/queuing_test.rb | 20 |
4 files changed, 44 insertions, 29 deletions
diff --git a/activejob/test/cases/callbacks_test.rb b/activejob/test/cases/callbacks_test.rb index df6ce16858..895edb34a5 100644 --- a/activejob/test/cases/callbacks_test.rb +++ b/activejob/test/cases/callbacks_test.rb @@ -2,6 +2,7 @@ require "helper" require "jobs/callback_job" +require "jobs/abort_before_enqueue_job" require "active_support/core_ext/object/inclusion" @@ -22,4 +23,28 @@ class CallbacksTest < ActiveSupport::TestCase assert "CallbackJob ran around_enqueue_start".in? enqueued_callback_job.history assert "CallbackJob ran around_enqueue_stop".in? enqueued_callback_job.history end + + test "#enqueue returns false when before_enqueue aborts callback chain and return_false_on_aborted_enqueue = true" do + prev = ActiveJob::Base.return_false_on_aborted_enqueue + ActiveJob::Base.return_false_on_aborted_enqueue = true + assert_equal false, AbortBeforeEnqueueJob.new.enqueue + ensure + ActiveJob::Base.return_false_on_aborted_enqueue = prev + end + + test "#enqueue returns self when before_enqueue aborts callback chain and return_false_on_aborted_enqueue = false" do + prev = ActiveJob::Base.return_false_on_aborted_enqueue + ActiveJob::Base.return_false_on_aborted_enqueue = false + job = AbortBeforeEnqueueJob.new + assert_deprecated do + assert_equal job, job.enqueue + end + ensure + ActiveJob::Base.return_false_on_aborted_enqueue = prev + end + + test "#enqueue returns self when the job was enqueued" do + job = CallbackJob.new + assert_equal job, job.enqueue + end end diff --git a/activejob/test/cases/exceptions_test.rb b/activejob/test/cases/exceptions_test.rb index b5328b8d6a..67327e0bbd 100644 --- a/activejob/test/cases/exceptions_test.rb +++ b/activejob/test/cases/exceptions_test.rb @@ -54,23 +54,19 @@ class ExceptionsTest < ActiveJob::TestCase test "failed retry job when exception kept occurring against defaults" do perform_enqueued_jobs do - begin - RetryJob.perform_later "DefaultsError", 6 - assert_equal "Raised DefaultsError for the 5th time", JobBuffer.last_value - rescue DefaultsError - pass - end + RetryJob.perform_later "DefaultsError", 6 + assert_equal "Raised DefaultsError for the 5th time", JobBuffer.last_value + rescue DefaultsError + pass end end test "failed retry job when exception kept occurring against higher limit" do perform_enqueued_jobs do - begin - RetryJob.perform_later "ShortWaitTenAttemptsError", 11 - assert_equal "Raised ShortWaitTenAttemptsError for the 10th time", JobBuffer.last_value - rescue ShortWaitTenAttemptsError - pass - end + RetryJob.perform_later "ShortWaitTenAttemptsError", 11 + assert_equal "Raised ShortWaitTenAttemptsError for the 10th time", JobBuffer.last_value + rescue ShortWaitTenAttemptsError + pass end end diff --git a/activejob/test/cases/logging_test.rb b/activejob/test/cases/logging_test.rb index 48ef39aaca..6154ba301d 100644 --- a/activejob/test/cases/logging_test.rb +++ b/activejob/test/cases/logging_test.rb @@ -187,11 +187,9 @@ class LoggingTest < ActiveSupport::TestCase def test_retry_stopped_logging_without_block perform_enqueued_jobs do - begin - RetryJob.perform_later "DefaultsError", 6 - rescue DefaultsError - assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages) - end + RetryJob.perform_later "DefaultsError", 6 + rescue DefaultsError + assert_match(/Stopped retrying RetryJob due to a DefaultsError, which reoccurred on \d+ attempts\./, @logger.messages) end end diff --git a/activejob/test/cases/queuing_test.rb b/activejob/test/cases/queuing_test.rb index 0e843b7215..e7bad83400 100644 --- a/activejob/test/cases/queuing_test.rb +++ b/activejob/test/cases/queuing_test.rb @@ -20,12 +20,10 @@ class QueuingTest < ActiveSupport::TestCase end test "run queued job later" do - begin - result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie" - assert result - rescue NotImplementedError - skip - end + result = HelloJob.set(wait_until: 1.second.ago).perform_later "Jamie" + assert result + rescue NotImplementedError + skip end test "job returned by enqueue has the arguments available" do @@ -34,11 +32,9 @@ class QueuingTest < ActiveSupport::TestCase end test "job returned by perform_at has the timestamp available" do - begin - job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later - assert_equal Time.utc(2014, 1, 1).to_f, job.scheduled_at - rescue NotImplementedError - skip - end + job = HelloJob.set(wait_until: Time.utc(2014, 1, 1)).perform_later + assert_equal Time.utc(2014, 1, 1).to_f, job.scheduled_at + rescue NotImplementedError + skip end end |