aboutsummaryrefslogtreecommitdiffstats
path: root/activesupport/test
diff options
context:
space:
mode:
authorkennyj <kennyj@gmail.com>2012-01-22 03:23:40 +0900
committerkennyj <kennyj@gmail.com>2012-01-24 17:36:30 +0900
commit5e59d755361e50e3f8c54d80f2a769b84f52dcc7 (patch)
tree5c472784fb86e793548db8c9c52961d8da207e7c /activesupport/test
parentdea2523232a0b2f9e7ba0b1d271aff4584a4e2a3 (diff)
downloadrails-5e59d755361e50e3f8c54d80f2a769b84f52dcc7.tar.gz
rails-5e59d755361e50e3f8c54d80f2a769b84f52dcc7.tar.bz2
rails-5e59d755361e50e3f8c54d80f2a769b84f52dcc7.zip
Fix GH #4344. A defined callback in extended module is called too.
Diffstat (limited to 'activesupport/test')
-rw-r--r--activesupport/test/callbacks_test.rb56
1 files changed, 56 insertions, 0 deletions
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