Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1 from michiels/add-caching-allowed

Adds caching_allowed? method that has been removed from Rails core
  • Loading branch information...
commit 2881d6396bd3bf50a80a656c86df08ef2ac7ece7 2 parents 6b976a6 + 730674f
Francesco Rodríguez authored
Showing with 16 additions and 0 deletions.
  1. +4 −0 lib/action_controller/caching/actions.rb
  2. +12 −0 test/caching_test.rb
View
4 lib/action_controller/caching/actions.rb
@@ -115,6 +115,10 @@ def _save_fragment(name, options)
end
end
+ def caching_allowed?
+ (request.get? || request.head?) && response.status == 200
+ end
+
protected
def expire_action(options = {})
return unless cache_configured?
View
12 test/caching_test.rb
@@ -153,6 +153,18 @@ def teardown
FileUtils.rm_rf(File.dirname(FILE_STORE_PATH))
end
+ def test_simple_action_cache_with_http_head
+ head :index
+ assert_response :success
+ cached_time = content_to_cache
+ assert_equal cached_time, @response.body
+ assert fragment_exist?('hostname.com/action_caching_test')
+
+ head :index
+ assert_response :success
+ assert_equal cached_time, @response.body
+ end
+
def test_simple_action_cache
get :index
assert_response :success
Please sign in to comment.
Something went wrong with that request. Please try again.