diff options
author | Steven Harman <steven@harmanly.com> | 2016-07-21 13:15:59 -0400 |
---|---|---|
committer | Steven Harman <steven@harmanly.com> | 2016-07-26 10:38:58 -0400 |
commit | ae75930b59e7b41133c5a62c09da3c02309f81f3 (patch) | |
tree | ec4505977e8ee9be40ac27658a8c46f16ca659bd /actionview/test | |
parent | c59715fa256b940f7bce912c5b4b2584fac05154 (diff) | |
download | rails-ae75930b59e7b41133c5a62c09da3c02309f81f3.tar.gz rails-ae75930b59e7b41133c5a62c09da3c02309f81f3.tar.bz2 rails-ae75930b59e7b41133c5a62c09da3c02309f81f3.zip |
Fix collection_from_options to allow Enumerators
An optimization was introduced in
https://github.com/rails/rails/commit/27f4ffd11a91b534fde9b484cb7c4e515ec0fe77
which tried to `#to_ary` the collection to prevent unnecessary queries
for ActiveRecord scopes/relations. If the given collection did not
respond to `#to_ary`, and empty collection was returned. That meant you
couldn't use collections built from `Enumerator` nor `Enumerable`.
With this change, `#collection_from_options` will attempt the
optimization, but fall back to passing along the given collection,
as-is.
Diffstat (limited to 'actionview/test')
-rw-r--r-- | actionview/test/template/render_test.rb | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/actionview/test/template/render_test.rb b/actionview/test/template/render_test.rb index 25b21850b1..e991fae491 100644 --- a/actionview/test/template/render_test.rb +++ b/actionview/test/template/render_test.rb @@ -309,6 +309,14 @@ module RenderTestCases assert_nil @view.render(:partial => "test/customer", :collection => nil) end + def test_render_partial_collection_for_non_array + customers = Enumerator.new do |y| + y.yield(Customer.new("david")) + y.yield(Customer.new("mary")) + end + assert_equal "Hello: davidHello: mary", @view.render(:partial => "test/customer", collection: customers) + end + def test_render_partial_without_object_does_not_put_partial_name_to_local_assigns assert_equal 'false', @view.render(partial: 'test/partial_name_in_local_assigns') end |