diff options
author | José Valim <jose.valim@gmail.com> | 2012-01-24 00:51:44 -0800 |
---|---|---|
committer | José Valim <jose.valim@gmail.com> | 2012-01-24 00:51:44 -0800 |
commit | e23dbec33094bfb38f97b7f300fdc70299521f56 (patch) | |
tree | 5c472784fb86e793548db8c9c52961d8da207e7c /activesupport | |
parent | dea2523232a0b2f9e7ba0b1d271aff4584a4e2a3 (diff) | |
parent | 5e59d755361e50e3f8c54d80f2a769b84f52dcc7 (diff) | |
download | rails-e23dbec33094bfb38f97b7f300fdc70299521f56.tar.gz rails-e23dbec33094bfb38f97b7f300fdc70299521f56.tar.bz2 rails-e23dbec33094bfb38f97b7f300fdc70299521f56.zip |
Merge pull request #4596 from kennyj/fix_4344
Fix GH #4344. Callback defined in a module is not triggered when the module extends an object under Rails 3.2rc2
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/lib/active_support/callbacks.rb | 2 | ||||
-rw-r--r-- | activesupport/test/callbacks_test.rb | 56 |
2 files changed, 57 insertions, 1 deletions
diff --git a/activesupport/lib/active_support/callbacks.rb b/activesupport/lib/active_support/callbacks.rb index 9cea09db41..5eaeac2cb3 100644 --- a/activesupport/lib/active_support/callbacks.rb +++ b/activesupport/lib/active_support/callbacks.rb @@ -359,7 +359,7 @@ module ActiveSupport def __run_callbacks(key, kind, object, &blk) #:nodoc: name = __callback_runner_name(kind) unless object.respond_to?(name) - str = send("_#{kind}_callbacks").compile(key, object) + str = object.send("_#{kind}_callbacks").compile(key, object) class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1 def #{name}() #{str} end protected :#{name} diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 2c2a420619..032787f0f4 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -344,6 +344,54 @@ module CallbacksTest end end + module ExtendModule + def self.extended(base) + base.class_eval do + set_callback :save, :before, :record3 + end + end + def record3 + @recorder << 3 + end + end + + module IncludeModule + def self.included(base) + base.class_eval do + set_callback :save, :before, :record2 + end + end + def record2 + @recorder << 2 + end + end + + class ExtendCallbacks + + include ActiveSupport::Callbacks + + define_callbacks :save + set_callback :save, :before, :record1 + + include IncludeModule + + def save + run_callbacks :save + end + + attr_reader :recorder + + def initialize + @recorder = [] + end + + private + + def record1 + @recorder << 1 + end + end + class AroundCallbacksTest < ActiveSupport::TestCase def test_save_around around = AroundPerson.new @@ -645,4 +693,12 @@ module CallbacksTest end end + class ExtendCallbacksTest < ActiveSupport::TestCase + def test_save + model = ExtendCallbacks.new.extend ExtendModule + model.save + assert_equal [1, 2, 3], model.recorder + end + end + end |