Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

ActionView::TestCase dies when rendering a layout

#3467

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

Reported by Chris Hapgood · November 6th, 2009 @ 10:18 PM

State: resolved
Milestone: 2.3.6
Assigned to: Eloy Duran Eloy Duran
Importance: none

Activity

  1. Chris Hapgood
    Chris Hapgood

    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): #3468 Some assertions for the testing of ActionView::TestCase are worthless

    November 6th, 2009 @ 10:42 PM

  2. Eloy Duran
    Eloy Duran
    • 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

    November 6th, 2009 @ 11:17 PM

  3. Repository
    Repository
    • State changed from verified to resolved

    November 8th, 2009 @ 10:17 PM

  4. Repository