diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-13 15:42:01 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-13 15:42:01 -0700 |
commit | edf116a91b617bc941e2fcfbe60ce2f8cb92ee8a (patch) | |
tree | 72b7624ed70377f78f3e3d2cdd81e0f8b26f16f5 /activesupport | |
parent | 1ad68e360065623d5d947d3375b9ab5aae78f461 (diff) | |
parent | 099e827f5757ebda559c6f656f7d24f1494867e9 (diff) | |
download | rails-edf116a91b617bc941e2fcfbe60ce2f8cb92ee8a.tar.gz rails-edf116a91b617bc941e2fcfbe60ce2f8cb92ee8a.tar.bz2 rails-edf116a91b617bc941e2fcfbe60ce2f8cb92ee8a.zip |
Merge branch 'master' into normalizecb
* master:
adding more callback type coverage
Diffstat (limited to 'activesupport')
-rw-r--r-- | activesupport/test/callbacks_test.rb | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/activesupport/test/callbacks_test.rb b/activesupport/test/callbacks_test.rb index 68878c0189..b97001b652 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -802,6 +802,46 @@ module CallbacksTest 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 { |