diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-08 14:35:43 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2013-05-08 14:35:43 -0700 |
commit | ece76f3840fb0327e58f91d6091beb66801deaed (patch) | |
tree | b67520364f3081d0e49a3c76582c799017e29acc /activesupport/test | |
parent | cecef59fa2f670bbd5b61fcaf54bceae2c4628b0 (diff) | |
download | rails-ece76f3840fb0327e58f91d6091beb66801deaed.tar.gz rails-ece76f3840fb0327e58f91d6091beb66801deaed.tar.bz2 rails-ece76f3840fb0327e58f91d6091beb66801deaed.zip |
adding tests for lambdas as conditions
Diffstat (limited to 'activesupport/test')
-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 0a79cb037c..b48145aab7 100644 --- a/activesupport/test/callbacks_test.rb +++ b/activesupport/test/callbacks_test.rb @@ -802,6 +802,46 @@ module CallbacksTest end end + class ConditionalTests < ActiveSupport::TestCase + def build_class(callback) + Class.new { + include ActiveSupport::Callbacks + define_callbacks :foo + set_callback :foo, :before, :foo, :if => callback + def foo; end + def run; run_callbacks :foo; end + } + end + + def test_proc_negative_arity # passes an empty list if *args + z = [] + object = build_class(->(*args) { z << args }).new + object.run + assert_equal [], z.flatten + end + + def test_proc_arity0 + z = [] + object = build_class(->() { z << 0 }).new + object.run + assert_equal [0], z + end + + def test_proc_arity1 + z = [] + object = build_class(->(x) { z << x }).new + object.run + assert_equal [object], z + end + + def test_proc_arity2 + assert_raises(ArgumentError) do + object = build_class(->(a,b) { }).new + object.run + end + end + end + class CallbackTypeTest < ActiveSupport::TestCase def build_class(callback, n = 10) Class.new { |