From 5b95d8ee59fa8843d6645caa6e6d0557799f7d4a Mon Sep 17 00:00:00 2001 From: Cheah Chu Yeow Date: Sun, 27 Feb 2011 22:57:46 +0800 Subject: [PATCH] Fix Action caching bug where an action that has a non-cacheable response always renders a nil response body. It now correctly renders the response body. Note that only GET and HTTP 200 responses can be cached. --- .../lib/action_controller/caching/actions.rb | 8 +++++--- actionpack/test/controller/caching_test.rb | 5 +++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/actionpack/lib/action_controller/caching/actions.rb b/actionpack/lib/action_controller/caching/actions.rb index a4bac3c..a1c5825 100644 --- a/actionpack/lib/action_controller/caching/actions.rb +++ b/actionpack/lib/action_controller/caching/actions.rb @@ -103,12 +103,14 @@ module ActionController #:nodoc: end def _save_fragment(name, options) - return unless caching_allowed? - content = response_body content = content.join if content.is_a?(Array) - write_fragment(name, content, options) + if caching_allowed? + write_fragment(name, content, options) + else + content + end end protected diff --git a/actionpack/test/controller/caching_test.rb b/actionpack/test/controller/caching_test.rb index cc393d3..01f3e8f 100644 --- a/actionpack/test/controller/caching_test.rb +++ b/actionpack/test/controller/caching_test.rb @@ -559,6 +559,11 @@ class ActionCacheTest < ActionController::TestCase assert_response 404 end + def test_four_oh_four_renders_content + get :four_oh_four + assert_equal "404'd!", @response.body + end + def test_simple_runtime_error_returns_500_for_multiple_requests get :simple_runtime_error assert_response 500 -- 1.7.4.1