Skip to content

Commit

Permalink
Ensure :partial => @collection and :collection => @collection behaves…
Browse files Browse the repository at this point in the history
… same. [#884 state:resolved]

Signed-off-by: Pratik Naik <pratiknaik@gmail.com>
  • Loading branch information
ryanb authored and lifo committed Aug 22, 2008
1 parent 4e4277b commit 9a5ffaa
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion actionpack/lib/action_view/partials.rb
Expand Up @@ -156,7 +156,7 @@ def render_partial(options = {}) #:nodoc:
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(
Expand Down
Expand Up @@ -39,6 +39,11 @@ def render_with_record_collection
@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
Expand Down Expand Up @@ -81,6 +86,11 @@ def test_render_with_record_collection
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
Expand Down
4 changes: 4 additions & 0 deletions actionpack/test/template/render_test.rb
Expand Up @@ -95,6 +95,10 @@ def test_render_partial_with_nil_collection_should_return_nil
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" })
Expand Down

0 comments on commit 9a5ffaa

Please sign in to comment.