aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport
diff options
context:
space:
mode:
authorMatthew Draper <matthew@trebex.net>2018-04-12 10:44:39 -0400
committerGitHub <noreply@github.com>2018-04-12 10:44:39 -0400
commit77e3b4faa4c092212ceed0dc93e8eade33c0b190 (patch)
tree03c015baa161b0f79227d095a9679f2d5b21e4c4 /activesupport
parent2a54f9963eae0592f348b37996e3b9eef85b5b63 (diff)
parent4efba09e88c5f4cdd78102c1d43ceea2c242a435 (diff)
downloadrails-77e3b4faa4c092212ceed0dc93e8eade33c0b190.tar.gz
rails-77e3b4faa4c092212ceed0dc93e8eade33c0b190.tar.bz2
rails-77e3b4faa4c092212ceed0dc93e8eade33c0b190.zip
Merge pull request #31913 from rywall/define-callbacks-desc
Define callbacks on descendants.
Diffstat (limited to 'activesupport')
-rw-r--r--activesupport/lib/active_support/callbacks.rb4
-rw-r--r--activesupport/test/callback_inheritance_test.rb10
2 files changed, 13 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb
index 9a3728d986..a1b841ec3d 100644
--- a/activesupport/lib/active_support/callbacks.rb
+++ b/activesupport/lib/active_support/callbacks.rb
@@ -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)
diff --git a/activesupport/test/callback_inheritance_test.rb b/activesupport/test/callback_inheritance_test.rb
index 015e17deb9..5633b6e2b8 100644
--- a/activesupport/test/callback_inheritance_test.rb
+++ b/activesupport/test/callback_inheritance_test.rb
@@ -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