Skip to content

Commit 3a25cdc

Browse files
committed
Remove deprecated behavior that halts callbacks when the return is false
1 parent 64f4930 commit 3a25cdc

File tree

12 files changed

+24
-188
lines changed

12 files changed

+24
-188
lines changed

activemodel/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated behavior that halts callbacks when the return is false.
2+
3+
*Rafael Mendonça França*
4+
15
* Remove unused `ActiveModel::TestCase` class.
26

37
*Yuji Yaginuma*

activemodel/lib/active_model/callbacks.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ def self.extended(base) #:nodoc:
103103
def define_model_callbacks(*callbacks)
104104
options = callbacks.extract_options!
105105
options = {
106-
terminator: deprecated_false_terminator,
107106
skip_after_callbacks_if_terminated: true,
108107
scope: [:kind, :name],
109108
only: [:before, :around, :after]

activemodel/lib/active_model/validations/callbacks.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ module Callbacks
2323
included do
2424
include ActiveSupport::Callbacks
2525
define_callbacks :validation,
26-
terminator: deprecated_false_terminator,
2726
skip_after_callbacks_if_terminated: true,
2827
scope: [:kind, :name]
2928
end

activemodel/test/cases/callbacks_test.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,10 @@ def create
6363
assert_equal model.callbacks.last, :final_callback
6464
end
6565

66-
test "the callback chain is halted when a before callback returns false (deprecated)" do
66+
test "the callback chain is not halted when a before callback returns false)" do
6767
model = ModelCallbacks.new(before_create_returns: false)
68-
assert_deprecated do
69-
model.create
70-
assert_equal model.callbacks.last, :before_create
71-
end
68+
model.create
69+
assert_equal model.callbacks.last, :final_callback
7270
end
7371

7472
test "the callback chain is halted when a callback throws :abort" do
@@ -127,6 +125,7 @@ class Violin2 < Violin
127125
test "after_create callbacks with both callbacks declared in one line" do
128126
assert_equal ["callback1", "callback2"], Violin1.new.create.history
129127
end
128+
130129
test "after_create callbacks with both callbacks declared in different lines" do
131130
assert_equal ["callback1", "callback2"], Violin2.new.create.history
132131
end

activemodel/test/cases/validations/callbacks_test.rb

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class DogWithTwoValidators < Dog
2929
before_validation { history << "before_validation_marker2" }
3030
end
3131

32-
class DogDeprecatedBeforeValidatorReturningFalse < Dog
32+
class DogBeforeValidatorReturningFalse < Dog
3333
before_validation { false }
3434
before_validation { history << "before_validation_marker2" }
3535
end
@@ -121,13 +121,11 @@ def test_further_callbacks_should_not_be_called_if_before_validation_throws_abor
121121
assert_equal false, output
122122
end
123123

124-
def test_deprecated_further_callbacks_should_not_be_called_if_before_validation_returns_false
125-
d = DogDeprecatedBeforeValidatorReturningFalse.new
126-
assert_deprecated do
127-
output = d.valid?
128-
assert_equal [], d.history
129-
assert_equal false, output
130-
end
124+
def test_further_callbacks_should_be_called_if_before_validation_returns_false
125+
d = DogBeforeValidatorReturningFalse.new
126+
output = d.valid?
127+
assert_equal ["before_validation_marker2"], d.history
128+
assert_equal true, output
131129
end
132130

133131
def test_further_callbacks_should_be_called_if_after_validation_returns_false

activerecord/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated behavior that halts callbacks when the return is false.
2+
3+
*Rafael Mendonça França*
4+
15
* Deprecate `ColumnDumper#migration_keys`.
26

37
*Ryuta Kamizono*

activerecord/lib/active_record/transactions.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ module Transactions
1111
:before_commit_without_transaction_enrollment,
1212
:commit_without_transaction_enrollment,
1313
:rollback_without_transaction_enrollment,
14-
terminator: deprecated_false_terminator,
1514
scope: [:kind, :name]
1615
end
1716

activerecord/test/cases/callbacks_test.rb

Lines changed: 0 additions & 110 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ def history
3939
end
4040
end
4141

42-
class CallbackDeveloperWithFalseValidation < CallbackDeveloper
43-
before_validation proc { |model| model.history << [:before_validation, :returning_false]; false }
44-
before_validation proc { |model| model.history << [:before_validation, :should_never_get_here] }
45-
end
46-
4742
class CallbackDeveloperWithHaltedValidation < CallbackDeveloper
4843
before_validation proc { |model| model.history << [:before_validation, :throwing_abort]; throw(:abort) }
4944
before_validation proc { |model| model.history << [:before_validation, :should_never_get_here] }
@@ -132,23 +127,6 @@ def history
132127
end
133128
end
134129

135-
class CallbackCancellationDeveloper < ActiveRecord::Base
136-
self.table_name = "developers"
137-
138-
attr_reader :after_save_called, :after_create_called, :after_update_called, :after_destroy_called
139-
attr_accessor :cancel_before_save, :cancel_before_create, :cancel_before_update, :cancel_before_destroy
140-
141-
before_save { defined?(@cancel_before_save) ? !@cancel_before_save : false }
142-
before_create { !@cancel_before_create }
143-
before_update { !@cancel_before_update }
144-
before_destroy { !@cancel_before_destroy }
145-
146-
after_save { @after_save_called = true }
147-
after_update { @after_update_called = true }
148-
after_create { @after_create_called = true }
149-
after_destroy { @after_destroy_called = true }
150-
end
151-
152130
class CallbackHaltedDeveloper < ActiveRecord::Base
153131
self.table_name = "developers"
154132

@@ -404,70 +382,6 @@ def test_delete
404382
], david.history
405383
end
406384

407-
def test_deprecated_before_save_returning_false
408-
david = ImmutableDeveloper.find(1)
409-
assert_deprecated do
410-
assert david.valid?
411-
assert !david.save
412-
exc = assert_raise(ActiveRecord::RecordNotSaved) { david.save! }
413-
assert_equal david, exc.record
414-
assert_equal "Failed to save the record", exc.message
415-
end
416-
417-
david = ImmutableDeveloper.find(1)
418-
david.salary = 10_000_000
419-
assert !david.valid?
420-
assert !david.save
421-
assert_raise(ActiveRecord::RecordInvalid) { david.save! }
422-
423-
someone = CallbackCancellationDeveloper.find(1)
424-
someone.cancel_before_save = true
425-
assert_deprecated do
426-
assert someone.valid?
427-
assert !someone.save
428-
end
429-
assert_save_callbacks_not_called(someone)
430-
end
431-
432-
def test_deprecated_before_create_returning_false
433-
someone = CallbackCancellationDeveloper.new
434-
someone.cancel_before_create = true
435-
assert_deprecated do
436-
assert someone.valid?
437-
assert !someone.save
438-
end
439-
assert_save_callbacks_not_called(someone)
440-
end
441-
442-
def test_deprecated_before_update_returning_false
443-
someone = CallbackCancellationDeveloper.find(1)
444-
someone.cancel_before_update = true
445-
assert_deprecated do
446-
assert someone.valid?
447-
assert !someone.save
448-
end
449-
assert_save_callbacks_not_called(someone)
450-
end
451-
452-
def test_deprecated_before_destroy_returning_false
453-
david = ImmutableDeveloper.find(1)
454-
assert_deprecated do
455-
assert !david.destroy
456-
exc = assert_raise(ActiveRecord::RecordNotDestroyed) { david.destroy! }
457-
assert_equal david, exc.record
458-
assert_equal "Failed to destroy the record", exc.message
459-
end
460-
assert_not_nil ImmutableDeveloper.find_by_id(1)
461-
462-
someone = CallbackCancellationDeveloper.find(1)
463-
someone.cancel_before_destroy = true
464-
assert_deprecated do
465-
assert !someone.destroy
466-
assert_raise(ActiveRecord::RecordNotDestroyed) { someone.destroy! }
467-
end
468-
assert !someone.after_destroy_called
469-
end
470-
471385
def assert_save_callbacks_not_called(someone)
472386
assert !someone.after_save_called
473387
assert !someone.after_create_called
@@ -525,30 +439,6 @@ def test_before_destroy_throwing_abort
525439
assert !someone.after_destroy_called
526440
end
527441

528-
def test_callback_returning_false
529-
david = CallbackDeveloperWithFalseValidation.find(1)
530-
assert_deprecated { david.save }
531-
assert_equal [
532-
[ :after_find, :method ],
533-
[ :after_find, :proc ],
534-
[ :after_find, :object ],
535-
[ :after_find, :block ],
536-
[ :after_initialize, :method ],
537-
[ :after_initialize, :proc ],
538-
[ :after_initialize, :object ],
539-
[ :after_initialize, :block ],
540-
[ :before_validation, :method ],
541-
[ :before_validation, :proc ],
542-
[ :before_validation, :object ],
543-
[ :before_validation, :block ],
544-
[ :before_validation, :returning_false ],
545-
[ :after_rollback, :block ],
546-
[ :after_rollback, :object ],
547-
[ :after_rollback, :proc ],
548-
[ :after_rollback, :method ],
549-
], david.history
550-
end
551-
552442
def test_callback_throwing_abort
553443
david = CallbackDeveloperWithHaltedValidation.find(1)
554444
david.save

activerecord/test/cases/transactions_test.rb

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,16 +206,6 @@ def test_update_should_rollback_on_failure!
206206
assert_equal posts_count, author.posts.reload.size
207207
end
208208

209-
def test_cancellation_from_returning_false_in_before_filter
210-
def @first.before_save_for_transaction
211-
false
212-
end
213-
214-
assert_deprecated do
215-
@first.save
216-
end
217-
end
218-
219209
def test_cancellation_from_before_destroy_rollbacks_in_destroy
220210
add_cancelling_before_destroy_with_db_side_effect_to_topic @first
221211
nbooks_before_destroy = Book.count

activesupport/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* Remove deprecated behavior that halts callbacks when the return is false.
2+
3+
*Rafael Mendonça França*
4+
15
* Deprecate passing string to `:if` and `:unless` conditional options
26
on `set_callback` and `skip_callback`.
37

0 commit comments

Comments
 (0)