This project is archived and is in readonly mode.
ActionView::TestCase dies when rendering a layout
Reported by Chris Hapgood | November 6th, 2009 @ 10:18 PM | in 2.3.6
ActionView::TestCase creates a view with a nil output buffer -probably assuming that all rendering simply returns a string. However, rendering a layout does not return a string -instead #_render_with_layout concatenates the result of rendering the layout as a partial onto the view's output buffer. Because the view's output buffer is nil, an exception is raised for invoking append (<<) on nil.
A simple work-around is to provide the view with an output buffer.
This behavior is observed in 2-3-stable.
Which component is breaking the rules? Is is the TestCase, which neglects to provide an output buffer for the view? Or is it ActionView::Base#render_with_layout that doesn't follow convention and simply return a string? Fixing TestCase is easy. Fixing render_with_layout will be (much) harder.
Other (indirect) references to this problem:
*
http://groups.google.com/group/haml/browse_thread/thread/c108c393a5...
To be pragmatic, I've created a one-line patch that links the test case's output buffer to the view's output buffer.
It applies cleanly to 2-3-stable.
It includes a failing test.
All action pack tests pass with the patch.
A simple monkey patch to get around the problem in the short term:
module ActionView
class TestCase
# When rendering a layout, the ActionView::TestCase creates a view with a nil
# output buffer -probably assuming that all rendering simply returns a string. Sadly,
# rendering a layout does not return a string -instead #_render_with_layout concat-
# enates the result of rendering the layout as a partial onto the view's output buffer. A simple
# work-around is to provide the view with an output buffer.
def _view
view = ActionView::Base.new(ActionController::Base.view_paths, _assigns, @controller)
view.helpers.include master_helper_module
view.output_buffer = self.output_buffer
view
end
end
end
Comments and changes to this ticket
-
Chris Hapgood November 6th, 2009 @ 10:42 PM
If you're looking at the patch for this ticket, consider this ticket as well (it's simple and pertains to the same test file): https://rails.lighthouseapp.com/projects/8994/tickets/3468-some-ass...
-
Eloy Duran November 6th, 2009 @ 11:17 PM
- State changed from new to verified
- Milestone set to 2.3.6
- Assigned user set to Eloy Duran
Applied in our repo, should be applied in a short while. http://github.com/Fingertips/rails/commit/d36f8a2bf2329b23eb4c7f3d1...
Thanks
-
Repository November 8th, 2009 @ 10:17 PM
- State changed from verified to resolved
(from [d36f8a2bf2329b23eb4c7f3d1f782ddb9ca9cd58]) Share ActionView::TestCase's output_buffer with view for concat support.
[#3467 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/d36f8a2bf2329b23eb4c7f3d1f782d... -
Repository November 8th, 2009 @ 10:17 PM
(from [c2cfb201984f8dff2b3534163b6145fe2560eb80]) Share ActionView::TestCase's output_buffer with view for concat support.
[#3467 state:resolved]
Signed-off-by: Eloy Duran eloy.de.enige@gmail.com
http://github.com/rails/rails/commit/c2cfb201984f8dff2b3534163b6145...
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile »
<h2 style="font-size: 14px">Tickets have moved to Github</h2>
The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>
People watching this ticket
Attachments
Referenced by
- 3467 ActionView::TestCase dies when rendering a layout [#3467 state:resolved]
- 3467 ActionView::TestCase dies when rendering a layout [#3467 state:resolved]