Browse files

Merge branch 'master' into normalizecb

* master:
  adding more callback type coverage
  • Loading branch information...
2 parents 1ad68e3 + 099e827 commit edf116a91b617bc941e2fcfbe60ce2f8cb92ee8a @tenderlove tenderlove committed May 13, 2013
Showing with 40 additions and 0 deletions.
  1. +40 −0 activesupport/test/callbacks_test.rb
View
40 activesupport/test/callbacks_test.rb
@@ -802,6 +802,46 @@ def test_excludes_duplicates_in_one_call
end
end
+ class CallbackProcTest < ActiveSupport::TestCase
+ def build_class(callback)
+ Class.new {
+ include ActiveSupport::Callbacks
+ define_callbacks :foo
+ set_callback :foo, :before, callback
+ def run; run_callbacks :foo; end
+ }
+ end
+
+ def test_proc_arity_0
+ calls = []
+ klass = build_class(->() { calls << :foo })
+ klass.new.run
+ assert_equal [:foo], calls
+ end
+
+ def test_proc_arity_1
+ calls = []
+ klass = build_class(->(o) { calls << o })
+ instance = klass.new
+ instance.run
+ assert_equal [instance], calls
+ end
+
+ def test_proc_arity_2
+ assert_raises(ArgumentError) do
+ klass = build_class(->(x,y) { })
+ klass.new.run
+ end
+ end
+
+ def test_proc_negative_called_with_empty_list
+ calls = []
+ klass = build_class(->(*args) { calls << args })
+ klass.new.run
+ assert_equal [[]], calls
+ end
+ end
+
class ConditionalTests < ActiveSupport::TestCase
def build_class(callback)
Class.new {

0 comments on commit edf116a

Please sign in to comment.