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

Ticket #3335: action_caching_for_non_success_status_codes.diff

File action_caching_for_non_success_status_codes.diff, 2.0 kB (added by halfbyte, 2 years ago)

Combined Patch for caching.rb and for caching_test.rb

  • actionpack/test/controller/caching_test.rb

    old new  
    9494end 
    9595 
    9696class ActionCachingTestController < ActionController::Base 
    97   caches_action :index 
     97  caches_action :index, :redirected, :forbidden 
    9898 
    9999  def index 
    100100    @cache_this = Time.now.to_f.to_s 
    101101    render :text => @cache_this 
    102102  end 
    103103 
     104  def redirected 
     105    redirect_to :action => 'index' 
     106  end 
     107 
     108  def forbidden 
     109    render :text => "..." 
     110    headers["Status"] = "403 Forbidden" 
     111  end 
     112 
    104113  def expire 
    105114    expire_action :controller => 'action_caching_test', :action => 'index' 
    106115    render :nothing => true 
     
    192201    assert_equal david_cache, @response.body 
    193202  end 
    194203 
     204  def test_redirect_not_cached 
     205    get :redirected 
     206    assert_response :redirect 
     207    reset! 
     208     
     209    get :redirected 
     210    assert_response :redirect 
     211  end 
     212 
     213  def test_forbidden_not_cached 
     214    get :forbidden 
     215    assert_response :forbidden 
     216    reset! 
     217 
     218    get :forbidden 
     219    assert_response :forbidden 
     220  end     
     221 
    195222  def test_xml_version_of_resource_is_treated_as_different_cache 
    196223    @mock_controller.mock_url_for = 'http://example.org/posts/' 
    197224    @mock_controller.mock_path    = '/posts/index.xml' 
  • actionpack/lib/action_controller/caching.rb

    old new  
    202202        end 
    203203 
    204204        def after(controller) 
    205           return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache 
     205          return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache || 
     206          controller.response.headers['Status'] != "200 OK" 
    206207          controller.write_fragment(ActionCachePath.path_for(controller), controller.response.body) 
    207208        end 
    208209