aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2013-05-13 11:44:15 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2013-05-13 11:44:15 -0700
commit37ca5b09662797928a4f74878595a4e577c5aedd (patch)
treefe39f7187b264e23f5e41c7ab7bb0aaf0a042cf4
parent465e459bcc56792933c3639d40cc07f53e4d0667 (diff)
downloadrails-37ca5b09662797928a4f74878595a4e577c5aedd.tar.gz
rails-37ca5b09662797928a4f74878595a4e577c5aedd.tar.bz2
rails-37ca5b09662797928a4f74878595a4e577c5aedd.zip
add tests for reset_calbacks
-rw-r--r--activesupport/test/callbacks_test.rb40
1 files changed, 40 insertions, 0 deletions
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb
index 9659f141cb..091fe90bcc 100644
--- a/activesupport/test/callbacks_test.rb
+++ b/activesupport/test/callbacks_test.rb
@@ -873,6 +873,46 @@ module CallbacksTest
end
end
+ class ResetCallbackTest < ActiveSupport::TestCase
+ def build_class(memo)
+ klass = Class.new {
+ include ActiveSupport::Callbacks
+ define_callbacks :foo
+ set_callback :foo, :before, :hello
+ def run; run_callbacks :foo; end
+ }
+ klass.class_eval {
+ define_method(:hello) { memo << :hi }
+ }
+ klass
+ end
+
+ def test_reset_callbacks
+ events = []
+ klass = build_class events
+ klass.new.run
+ assert_equal 1, events.length
+
+ klass.reset_callbacks :foo
+ klass.new.run
+ assert_equal 1, events.length
+ end
+
+ def test_reset_impacts_subclasses
+ events = []
+ klass = build_class events
+ subclass = Class.new(klass) { set_callback :foo, :before, :world }
+ subclass.class_eval { define_method(:world) { events << :world } }
+
+ subclass.new.run
+ assert_equal 2, events.length
+
+ klass.reset_callbacks :foo
+ subclass.new.run
+ assert_equal 3, events.length
+ end
+ end
+
class CallbackTypeTest < ActiveSupport::TestCase
def build_class(callback, n = 10)
Class.new {