Permalink
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...
Francesco Rodríguez
Francesco Rodríguez committed Jan 28, 2013
2 parents 6b976a6 + 730674f commit 2881d6396bd3bf50a80a656c86df08ef2ac7ece7
Showing with 16 additions and 0 deletions.
  1. +4 −0 lib/action_controller/caching/actions.rb
  2. +12 −0 test/caching_test.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
@@ -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

0 comments on commit 2881d63

Please sign in to comment.