diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 10:04:43 -0800 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2009-02-06 10:04:43 -0800 |
commit | 676b0c87642786080ab9e22fcc86a13d15324d4b (patch) | |
tree | 8e03242f8b67e17a4ebd8630e2ab7dc194037867 /activesupport/test/core_ext | |
parent | 7564d98929af0bb039cb10c59dff6d177c11bd13 (diff) | |
download | rails-676b0c87642786080ab9e22fcc86a13d15324d4b.tar.gz rails-676b0c87642786080ab9e22fcc86a13d15324d4b.tar.bz2 rails-676b0c87642786080ab9e22fcc86a13d15324d4b.zip |
Introduce Array.wrap(foo) to wrap the argument in an array unless it's already an array. Wraps nil as an empty array. Use instead of Array(foo) and foo.to_a since they treat String as Enumerable.
Diffstat (limited to 'activesupport/test/core_ext')
-rw-r--r-- | activesupport/test/core_ext/array_ext_test.rb | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 93f4482307..a90d6891cf 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -302,3 +302,27 @@ class ArrayExtRandomTests < Test::Unit::TestCase assert_equal 2, [1, 2, 3].rand end end + +class ArrayWrapperTests < Test::Unit::TestCase + def test_array + ary = %w(foo bar) + assert_same ary, Array.wrap(ary) + end + + def test_nil + assert_equal [], Array.wrap(nil) + end + + def test_object + o = Object.new + assert_equal [o], Array.wrap(o) + end + + def test_string + assert_equal ["foo"], Array.wrap("foo") + end + + def test_string_with_newline + assert_equal ["foo\nbar"], Array.wrap("foo\nbar") + end +end |