mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Merge pull request #31913 from rywall/define-callbacks-desc
Define callbacks on descendants.
This commit is contained in:
commit
77e3b4faa4
2 changed files with 13 additions and 1 deletions
|
@ -809,7 +809,9 @@ module ActiveSupport
|
|||
names.each do |name|
|
||||
name = name.to_sym
|
||||
|
||||
set_callbacks name, CallbackChain.new(name, options)
|
||||
([self] + ActiveSupport::DescendantsTracker.descendants(self)).each do |target|
|
||||
target.set_callbacks name, CallbackChain.new(name, options)
|
||||
end
|
||||
|
||||
module_eval <<-RUBY, __FILE__, __LINE__ + 1
|
||||
def _run_#{name}_callbacks(&block)
|
||||
|
|
|
@ -176,3 +176,13 @@ class DynamicInheritedCallbacks < ActiveSupport::TestCase
|
|||
assert_equal 1, child.count
|
||||
end
|
||||
end
|
||||
|
||||
class DynamicDefinedCallbacks < ActiveSupport::TestCase
|
||||
def test_callbacks_should_be_performed_once_in_child_class_after_dynamic_define
|
||||
GrandParent.define_callbacks(:foo)
|
||||
GrandParent.set_callback(:foo, :before, :before1)
|
||||
parent = Parent.new("foo")
|
||||
parent.run_callbacks(:foo)
|
||||
assert_equal %w(before1), parent.log
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue