Permalink
Browse files

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

Add caching_allowed? that was removed from Rails 4 core
  • Loading branch information...
2 parents bd3e4f7 + 26b1636 commit c69dc22d0b0ba975ac9e6277db1ea9df4b800257 Francesco Rodríguez committed Jan 28, 2013
Showing with 10 additions and 0 deletions.
  1. +4 −0 lib/action_controller/caching/pages.rb
  2. +6 −0 test/caching_test.rb
View
4 lib/action_controller/caching/pages.rb
@@ -185,6 +185,10 @@ def cache_page(content = nil, options = nil, gzip = Zlib::BEST_COMPRESSION)
self.class.cache_page(content || response.body, path, extension, gzip)
end
+
+ def caching_allowed?
+ (request.get? || request.head?) && response.status == 200
+ end
end
end
end
View
6 test/caching_test.rb
@@ -148,6 +148,12 @@ def test_page_caching_resources_saves_to_correct_path_with_extension_even_if_def
end
end
+ def test_should_cache_head_with_ok_status
+ head :ok
+ assert_response :ok
+ assert_page_cached :ok, 'head with ok status should have been cached'
+ end
+
def test_should_cache_get_with_ok_status
get :ok
assert_response :ok

0 comments on commit c69dc22

Please sign in to comment.