From bd67937f808d29373aacab40131c73ff207331d4 Mon Sep 17 00:00:00 2001 From: Ryan Bates Date: Fri, 22 Aug 2008 08:04:27 -0700 Subject: [PATCH] behave the same when rendering partial with and without :collection option --- actionpack/lib/action_view/partials.rb | 2 +- ...nder_partial_with_record_identification_test.rb | 10 ++++++++++ actionpack/test/template/render_test.rb | 4 ++++ 3 files changed, 15 insertions(+), 1 deletions(-) diff --git a/actionpack/lib/action_view/partials.rb b/actionpack/lib/action_view/partials.rb index a914172..4d19d99 100644 --- a/actionpack/lib/action_view/partials.rb +++ b/actionpack/lib/action_view/partials.rb @@ -156,7 +156,7 @@ module ActionView local_assigns.merge!(builder_partial_path.to_sym => partial_path) render_partial(:partial => builder_partial_path, :object => options[:object], :locals => local_assigns) when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope - partial_path.any? ? render_partial(:collection => partial_path, :locals => local_assigns) : "" + render_partial_collection(options.except(:partial).merge(:collection => partial_path)) else object = partial_path render_partial( diff --git a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb index a82a1a3..d75cb2b 100644 --- a/actionpack/test/activerecord/render_partial_with_record_identification_test.rb +++ b/actionpack/test/activerecord/render_partial_with_record_identification_test.rb @@ -39,6 +39,11 @@ class RenderPartialWithRecordIdentificationController < ActionController::Base @developers = Developer.find(:all) render :partial => @developers end + + def render_with_record_collection_and_spacer_template + @developer = Developer.find(1) + render :partial => @developer.projects, :spacer_template => 'test/partial_only' + end end class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase @@ -81,6 +86,11 @@ class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body end + def test_render_with_record_collection_and_spacer_template + get :render_with_record_collection_and_spacer_template + assert_equal 'Active Recordonly partialActive Controller', @response.body + end + def test_rendering_partial_with_has_one_association mascot = Company.find(1).mascot get :render_with_has_one_association diff --git a/actionpack/test/template/render_test.rb b/actionpack/test/template/render_test.rb index 25bbc26..f3c8dbc 100644 --- a/actionpack/test/template/render_test.rb +++ b/actionpack/test/template/render_test.rb @@ -95,6 +95,10 @@ class ViewRenderTest < Test::Unit::TestCase assert_nil @view.render(:partial => "test/customer", :collection => nil) end + def test_render_partial_with_empty_array_should_return_nil + assert_nil @view.render(:partial => []) + end + # TODO: The reason for this test is unclear, improve documentation def test_render_partial_and_fallback_to_layout assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" }) -- 1.5.6.4