Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 5591

Show
Ignore:
Timestamp:
11/20/06 11:03:21 (3 years ago)
Author:
bitsweat
Message:

Ensure render_to_string cleans up after itself when an exception is raised. Closes #6658. Great tests!

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r5587 r5591  
    11*SVN* 
     2 
     3* Ensure render_to_string cleans up after itself when an exception is raised.  #6658 [rsanheim] 
    24 
    35* Extract template_changed_since? from compile_template? so plugins may override its behavior for non-file-based templates.  #6651 [Jeff Barczewski] 
  • trunk/actionpack/lib/action_controller/base.rb

    r5253 r5591  
    764764      # of sending it as the response body to the browser. 
    765765      def render_to_string(options = nil, &block) #:doc: 
    766         result = ActiveSupport::Deprecation.silence { render(options, &block) } 
    767  
     766        ActiveSupport::Deprecation.silence { render(options, &block) } 
     767      ensure 
    768768        erase_render_results 
    769769        forget_variables_added_to_assigns 
    770770        reset_variables_added_to_assigns 
    771  
    772         result 
    773771      end 
    774772 
  • trunk/actionpack/test/controller/new_render_test.rb

    r5466 r5591  
    161161    render :text =>  "How's there? #{render_to_string("test/list")}" 
    162162  end 
     163   
     164  def render_to_string_with_assigns 
     165    @before = "i'm before the render" 
     166    render_to_string :text => "foo" 
     167    @after = "i'm after the render" 
     168    render :action => "test/hello_world" 
     169  end 
     170   
     171  def render_to_string_with_exception 
     172    render_to_string :file => "exception that will not be caught - this will certainly not work", :use_full_path => true 
     173  end 
     174   
     175  def render_to_string_with_caught_exception 
     176    @before = "i'm before the render" 
     177    begin 
     178      render_to_string :file => "exception that will be caught- hope my future instance vars still work!", :use_full_path => true 
     179    rescue 
     180    end 
     181    @after = "i'm after the render" 
     182    render :action => "test/hello_world" 
     183  end 
    163184 
    164185  def accessing_params_in_template 
     
    187208    render :text => "hello" 
    188209    redirect_to :action => "double_render" 
     210  end 
     211   
     212  def render_to_string_and_render 
     213    @stuff = render_to_string :text => "here is some cached stuff" 
     214    render :text => "Hi web users! #{@stuff}" 
    189215  end 
    190216 
     
    524550    assert_equal "How's there? goodbyeHello: davidHello: marygoodbye\n", @response.body 
    525551  end 
     552   
     553  def test_render_to_string_doesnt_break_assigns 
     554    get :render_to_string_with_assigns 
     555    assert_equal "i'm before the render", assigns(:before) 
     556    assert_equal "i'm after the render", assigns(:after) 
     557  end 
     558   
     559  def test_bad_render_to_string_still_throws_exception 
     560    assert_raises(ActionController::MissingTemplate) { get :render_to_string_with_exception } 
     561  end 
     562   
     563  def test_render_to_string_that_throws_caught_exception_doesnt_break_assigns 
     564    assert_nothing_raised { get :render_to_string_with_caught_exception } 
     565    assert_equal "i'm before the render", assigns(:before) 
     566    assert_equal "i'm after the render", assigns(:after) 
     567  end 
    526568 
    527569  def test_nested_rendering 
     
    555597  def test_render_and_redirect 
    556598    assert_raises(ActionController::DoubleRenderError) { get :render_and_redirect } 
     599  end 
     600   
     601  # specify the one exception to double render rule - render_to_string followed by render 
     602  def test_render_to_string_and_render 
     603    get :render_to_string_and_render 
     604    assert_equal("Hi web users! here is some cached stuff", @response.body) 
    557605  end 
    558606