aboutsummaryrefslogtreecommitdiffstats
path: root/activejob/test/cases
diff options
context:
space:
mode:
authorKir Shatrov <shatrov@me.com>2018-09-26 17:25:20 +0100
committerKir Shatrov <shatrov@me.com>2018-10-28 15:02:44 -0400
commitee9fc120242b83c64bf77af1b72082ac76319332 (patch)
tree7b9fef67646c221c85c71be236d8bd50ffa2c7e4 /activejob/test/cases
parent3295e23755744b7f9426d752481bb928fb02a89e (diff)
downloadrails-ee9fc120242b83c64bf77af1b72082ac76319332.tar.gz
rails-ee9fc120242b83c64bf77af1b72082ac76319332.tar.bz2
rails-ee9fc120242b83c64bf77af1b72082ac76319332.zip
Make AJ::Base#enqueue return false if the job wasn't enqueued
Diffstat (limited to 'activejob/test/cases')
-rw-r--r--activejob/test/cases/callbacks_test.rb29
1 files changed, 29 insertions, 0 deletions
diff --git a/activejob/test/cases/callbacks_test.rb b/activejob/test/cases/callbacks_test.rb
index df6ce16858..267d58a7c8 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,32 @@ 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
+ begin
+ 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
+ end
+
+ test "#enqueue returns self when before_enqueue aborts callback chain and return_false_on_aborted_enqueue = false" do
+ begin
+ 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
+ end
+
+ test "#enqueue returns self when the job was enqueued" do
+ job = CallbackJob.new
+ assert_equal job, job.enqueue
+ end
end