Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

adding more tests around callback inconsistencies

  • Loading branch information...
commit 5d2c3a14a3bfbde2b48d9021a3e58c3f6fe024e7 1 parent d32b329
@tenderlove tenderlove authored
Showing with 47 additions and 5 deletions.
  1. +47 −5 activesupport/test/callbacks_test.rb
View
52 activesupport/test/callbacks_test.rb
@@ -802,17 +802,18 @@ def test_excludes_duplicates_in_one_call
end
end
- class AddCallbackTypeTest < ActiveSupport::TestCase
+ class CallbackTypeTest < ActiveSupport::TestCase
def build_class(callback, n = 10)
Class.new {
include ActiveSupport::Callbacks
define_callbacks :foo
n.times { set_callback :foo, callback }
def run; run_callbacks :foo; end
+ def self.skip(thing); skip_callback :foo, thing; end
}
end
- def test_class
+ def test_add_class
calls = []
callback = Class.new {
define_singleton_method(:before) { |o| calls << o }
@@ -821,13 +822,13 @@ def test_class
assert_equal 10, calls.length
end
- def test_lambda
+ def test_add_lambda
calls = []
build_class(->(o) { calls << o }).new.run
assert_equal 10, calls.length
end
- def test_symbol
+ def test_add_symbol
calls = []
klass = build_class(:bar)
klass.class_eval { define_method(:bar) { calls << klass } }
@@ -835,12 +836,53 @@ def test_symbol
assert_equal 1, calls.length
end
- def test_string
+ def test_add_eval
calls = []
klass = build_class("bar")
klass.class_eval { define_method(:bar) { calls << klass } }
klass.new.run
assert_equal 1, calls.length
end
+
+ def test_skip_class # removes one at a time
+ calls = []
+ callback = Class.new {
+ define_singleton_method(:before) { |o| calls << o }
+ }
+ klass = build_class(callback)
+ 9.downto(0) { |i|
+ klass.skip callback
+ klass.new.run
+ assert_equal i, calls.length
+ calls.clear
+ }
+ end
+
+ def test_skip_lambda # removes nothing
+ calls = []
+ callback = ->(o) { calls << o }
+ klass = build_class(callback)
+ 10.times { klass.skip callback }
+ klass.new.run
+ assert_equal 10, calls.length
+ end
+
+ def test_skip_symbol # removes all
+ calls = []
+ klass = build_class(:bar)
+ klass.class_eval { define_method(:bar) { calls << klass } }
+ klass.skip :bar
+ klass.new.run
+ assert_equal 0, calls.length
+ end
+
+ def test_skip_eval # removes nothing
+ calls = []
+ klass = build_class("bar")
+ klass.class_eval { define_method(:bar) { calls << klass } }
+ klass.skip "bar"
+ klass.new.run
+ assert_equal 1, calls.length
+ end
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.