Permalink
Browse files

Test that Array.wrap works with proxy objects and structs

  • Loading branch information...
1 parent 2cb47c7 commit c0ebc2149380a59371553765053f55671c737533 @jeremy jeremy committed Nov 13, 2009
Showing with 20 additions and 0 deletions.
  1. +20 −0 activesupport/test/core_ext/array_ext_test.rb
@@ -339,6 +339,11 @@ def to_ary
end
end
+ class Proxy
+ def initialize(target) @target = target end
+ def method_missing(*a) @target.send(*a) end
+ end
+
def test_array
ary = %w(foo bar)
assert_same ary, Array.wrap(ary)
@@ -364,4 +369,19 @@ def test_string_with_newline
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
end

0 comments on commit c0ebc21

Please sign in to comment.