Permalink
Browse files

Fix issue with rendering partials and then yielding inside a render l…

…ayout call

The given block was never being executed when another render :partial call
existed before the yield call, due to the block being overriden.

This commit also adds some more tests to render with :layout option.
  • Loading branch information...
carlosantoniodasilva authored and josevalim committed Nov 11, 2010
1 parent 920660b commit 50c7aab996baafdfee4b1e4b2ca4673ee76bb19a
@@ -0,0 +1,2 @@
+<%= render :partial => 'test/partial' %>
+<%= yield %>
@@ -0,0 +1 @@
+<%= yield %>
@@ -0,0 +1 @@
+<%= yield 'Yield!' %>
@@ -0,0 +1,2 @@
+<%= render :partial => 'test/partial' %>
+<%= yield %>
@@ -247,6 +247,26 @@ def test_render_with_layout_which_has_render_inline
@view.render(:file => "test/hello_world.erb", :layout => "layouts/yield_with_render_inline_inside")
end
+ def test_render_with_layout_which_renders_another_partial
+ assert_equal %(partial html\nHello world!\n),
+ @view.render(:file => "test/hello_world.erb", :layout => "layouts/yield_with_render_partial_inside")
+ end
+
+ def test_render_layout_with_block_and_yield
+ assert_equal %(Content from block!\n),
+ @view.render(:layout => "layouts/yield_only") { "Content from block!" }
+ end
+
+ def test_render_layout_with_block_and_yield_with_params
+ assert_equal %(Yield! Content from block!\n),
+ @view.render(:layout => "layouts/yield_with_params") { |param| "#{param} Content from block!" }
+ end
+
+ def test_render_layout_with_block_which_renders_another_partial_and_yields
+ assert_equal %(partial html\nContent from block!\n),
+ @view.render(:layout => "layouts/partial_and_yield") { "Content from block!" }
+ end
+
def test_render_with_nested_layout
assert_equal %(<title>title</title>\n\n<div id="column">column</div>\n<div id="content">content</div>\n),
@view.render(:file => "test/nested_layout.erb", :layout => "layouts/yield")

4 comments on commit 50c7aab

@iain

This comment has been minimized.

Show comment
Hide comment
@iain

iain Nov 11, 2010

Contributor

I see two commits for this, both adding only tests. Are you sure this is correct?

The other one I found is: 7846fb7

Contributor

iain replied Nov 11, 2010

I see two commits for this, both adding only tests. Are you sure this is correct?

The other one I found is: 7846fb7

@carlosantoniodasilva

This comment has been minimized.

Show comment
Hide comment
@carlosantoniodasilva

carlosantoniodasilva Nov 11, 2010

Member

They are ok, this was already fixed on master. Both commits addressed issues on 3.0 branch, 3e86e4b and d5fd83f. José cherry picked the tests to master.

They are ok, this was already fixed on master. Both commits addressed issues on 3.0 branch, 3e86e4b and d5fd83f. José cherry picked the tests to master.

@josevalim

This comment has been minimized.

Show comment
Hide comment
@josevalim

josevalim Nov 11, 2010

Contributor

Exactly! The code was accidentally fixed when I was refactoring this piece of the code about one month ago.

Contributor

josevalim replied Nov 11, 2010

Exactly! The code was accidentally fixed when I was refactoring this piece of the code about one month ago.

@iain

This comment has been minimized.

Show comment
Hide comment
@iain

iain Nov 11, 2010

Contributor

I've heard that code ninjas can fix bugs without even knowing it ;)
Great work!

Contributor

iain replied Nov 11, 2010

I've heard that code ninjas can fix bugs without even knowing it ;)
Great work!

Please sign in to comment.