Ticket #3335: action_caching_for_non_success_status_codes.2.diff
| File action_caching_for_non_success_status_codes.2.diff, 2.8 kB (added by josh, 1 year ago) |
|---|
-
actionpack/test/controller/caching_test.rb
old new 121 121 122 122 123 123 class ActionCachingTestController < ActionController::Base 124 caches_action :index 124 caches_action :index, :redirected, :forbidden 125 125 caches_action :show, :cache_path => 'http://test.host/custom/show' 126 126 caches_action :edit, :cache_path => Proc.new { |c| c.params[:id] ? "http://test.host/#{c.params[:id]};edit" : "http://test.host/edit" } 127 127 … … 129 129 @cache_this = Time.now.to_f.to_s 130 130 render :text => @cache_this 131 131 end 132 132 133 def redirected 134 redirect_to :action => 'index' 135 end 136 137 def forbidden 138 render :text => "Forbidden" 139 headers["Status"] = "403 Forbidden" 140 end 141 133 142 alias_method :show, :index 134 143 alias_method :edit, :index 135 144 … … 245 254 assert_equal david_cache, @response.body 246 255 end 247 256 257 def test_redirect_is_not_cached 258 get :redirected 259 assert_response :redirect 260 reset! 261 262 get :redirected 263 assert_response :redirect 264 end 265 266 def test_forbidden_is_not_cached 267 get :forbidden 268 assert_response :forbidden 269 reset! 270 271 get :forbidden 272 assert_response :forbidden 273 end 274 248 275 def test_xml_version_of_resource_is_treated_as_different_cache 249 276 @mock_controller.mock_url_for = 'http://example.org/posts/' 250 277 @mock_controller.mock_path = '/posts/index.xml' -
actionpack/lib/action_controller/caching.rb
old new 240 240 end 241 241 242 242 def after(controller) 243 return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache 243 return if !@actions.include?(controller.action_name.intern) || controller.rendered_action_cache || !caching_allowed(controller) 244 244 controller.write_fragment(controller.action_cache_path.path, controller.response.body) 245 245 end 246 246 247 247 private 248 249 248 def set_content_type!(controller, extension) 250 249 controller.response.content_type = Mime::EXTENSION_LOOKUP[extension].to_s if extension 251 250 end 252 251 253 252 def path_options_for(controller, options) 254 253 ((path_options = options[:cache_path]).respond_to?(:call) ? path_options.call(controller) : path_options) || {} 255 254 end 256 255 256 def caching_allowed(controller) 257 controller.request.get? && controller.response.headers['Status'].to_i == 200 258 end 257 259 end 258 260 259 261 class ActionCachePath