From b4d8c7d148c6b44eea6701687ca2a97df9088747 Mon Sep 17 00:00:00 2001 From: Jon Leighton Date: Thu, 30 Jun 2011 00:08:43 +0100 Subject: Array.wrap should follow Kernel#Array semantics when the object's to_ary is nil. In this case, the object should be wrapped. --- activesupport/lib/active_support/core_ext/array/wrap.rb | 2 +- activesupport/test/core_ext/array_ext_test.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/activesupport/lib/active_support/core_ext/array/wrap.rb b/activesupport/lib/active_support/core_ext/array/wrap.rb index f420270dc4..4834eca8b1 100644 --- a/activesupport/lib/active_support/core_ext/array/wrap.rb +++ b/activesupport/lib/active_support/core_ext/array/wrap.rb @@ -40,7 +40,7 @@ class Array if object.nil? [] elsif object.respond_to?(:to_ary) - object.to_ary + object.to_ary || [object] else [object] end diff --git a/activesupport/test/core_ext/array_ext_test.rb b/activesupport/test/core_ext/array_ext_test.rb index 0e5407bc35..e532010b18 100644 --- a/activesupport/test/core_ext/array_ext_test.rb +++ b/activesupport/test/core_ext/array_ext_test.rb @@ -456,8 +456,9 @@ class ArrayWrapperTests < Test::Unit::TestCase assert_equal [o], Array.wrap(o) end - def test_wrap_returns_nil_if_to_ary_returns_nil - assert_nil Array.wrap(NilToAry.new) + def test_wrap_returns_wrapped_if_to_ary_returns_nil + o = NilToAry.new + assert_equal [o], Array.wrap(o) end def test_wrap_does_not_complain_if_to_ary_does_not_return_an_array -- cgit v1.2.3