diff options
author | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-29 10:59:53 -0300 |
---|---|---|
committer | Rafael Mendonça França <rafaelmfranca@gmail.com> | 2014-07-29 10:59:53 -0300 |
commit | 8426897086a3ad08cc7280d7af26cb5ccf352922 (patch) | |
tree | a70350dfa47c2249a4a422a3eb954d893ba0cc40 /activesupport/test/core_ext/array/wrap_test.rb | |
parent | aade0a0412c3b8dfada4628487f6fb4c615f0060 (diff) | |
parent | 00979fdb2c00de4e124a7c939b9024f57b4a835e (diff) | |
download | rails-8426897086a3ad08cc7280d7af26cb5ccf352922.tar.gz rails-8426897086a3ad08cc7280d7af26cb5ccf352922.tar.bz2 rails-8426897086a3ad08cc7280d7af26cb5ccf352922.zip |
Merge pull request #16334 from akshay-vishnoi/array-tests
Move array test files under array
Diffstat (limited to 'activesupport/test/core_ext/array/wrap_test.rb')
-rw-r--r-- | activesupport/test/core_ext/array/wrap_test.rb | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/activesupport/test/core_ext/array/wrap_test.rb b/activesupport/test/core_ext/array/wrap_test.rb new file mode 100644 index 0000000000..baf426506f --- /dev/null +++ b/activesupport/test/core_ext/array/wrap_test.rb @@ -0,0 +1,77 @@ +require 'abstract_unit' +require 'active_support/core_ext/array' + +class WrapTest < ActiveSupport::TestCase + class FakeCollection + def to_ary + ["foo", "bar"] + end + end + + class Proxy + def initialize(target) @target = target end + def method_missing(*a) @target.send(*a) end + end + + class DoubtfulToAry + def to_ary + :not_an_array + end + end + + class NilToAry + def to_ary + nil + end + end + + 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 + + def test_object_with_to_ary + assert_equal ["foo", "bar"], Array.wrap(FakeCollection.new) + end + + def test_proxy_object + p = Proxy.new(Object.new) + assert_equal [p], Array.wrap(p) + end + + def test_proxy_to_object_with_to_ary + p = Proxy.new(FakeCollection.new) + assert_equal [p], Array.wrap(p) + end + + def test_struct + o = Struct.new(:foo).new(123) + assert_equal [o], Array.wrap(o) + end + + 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 + assert_equal DoubtfulToAry.new.to_ary, Array.wrap(DoubtfulToAry.new) + end +end |