Skip to content

Commit 9a5ffaa

Browse files
ryanblifo
authored andcommitted
Ensure :partial => @collection and :collection => @collection behaves same. [#884 state:resolved]
Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
1 parent 4e4277b commit 9a5ffaa

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

actionpack/lib/action_view/partials.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ def render_partial(options = {}) #:nodoc:
156156
local_assigns.merge!(builder_partial_path.to_sym => partial_path)
157157
render_partial(:partial => builder_partial_path, :object => options[:object], :locals => local_assigns)
158158
when Array, ActiveRecord::Associations::AssociationCollection, ActiveRecord::NamedScope::Scope
159-
partial_path.any? ? render_partial(:collection => partial_path, :locals => local_assigns) : ""
159+
render_partial_collection(options.except(:partial).merge(:collection => partial_path))
160160
else
161161
object = partial_path
162162
render_partial(

actionpack/test/activerecord/render_partial_with_record_identification_test.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,11 @@ def render_with_record_collection
3939
@developers = Developer.find(:all)
4040
render :partial => @developers
4141
end
42+
43+
def render_with_record_collection_and_spacer_template
44+
@developer = Developer.find(1)
45+
render :partial => @developer.projects, :spacer_template => 'test/partial_only'
46+
end
4247
end
4348

4449
class RenderPartialWithRecordIdentificationTest < ActiveRecordTestCase
@@ -81,6 +86,11 @@ def test_render_with_record_collection
8186
assert_equal 'DavidJamisfixture_3fixture_4fixture_5fixture_6fixture_7fixture_8fixture_9fixture_10Jamis', @response.body
8287
end
8388

89+
def test_render_with_record_collection_and_spacer_template
90+
get :render_with_record_collection_and_spacer_template
91+
assert_equal 'Active Recordonly partialActive Controller', @response.body
92+
end
93+
8494
def test_rendering_partial_with_has_one_association
8595
mascot = Company.find(1).mascot
8696
get :render_with_has_one_association

actionpack/test/template/render_test.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,10 @@ def test_render_partial_with_nil_collection_should_return_nil
9595
assert_nil @view.render(:partial => "test/customer", :collection => nil)
9696
end
9797

98+
def test_render_partial_with_empty_array_should_return_nil
99+
assert_nil @view.render(:partial => [])
100+
end
101+
98102
# TODO: The reason for this test is unclear, improve documentation
99103
def test_render_partial_and_fallback_to_layout
100104
assert_equal "Before (Josh)\n\nAfter", @view.render(:partial => "test/layout_for_partial", :locals => { :name => "Josh" })

0 commit comments

Comments
 (0)