diff options
author | Arthur Neves <arthurnn@gmail.com> | 2015-01-07 21:23:55 -0500 |
---|---|---|
committer | Arthur Neves <arthurnn@gmail.com> | 2015-02-15 11:36:36 -0500 |
commit | 2ed39424dbecf1d040b15d1450f0265b35b78022 (patch) | |
tree | 1e0c42ea20762de430409ec589fa9e6d2a45ae92 /actionpack/test/controller | |
parent | 62133326df3c7edff67a2e57ae32c95bf6e8a818 (diff) | |
download | rails-2ed39424dbecf1d040b15d1450f0265b35b78022.tar.gz rails-2ed39424dbecf1d040b15d1450f0265b35b78022.tar.bz2 rails-2ed39424dbecf1d040b15d1450f0265b35b78022.zip |
Implement http_cache_forever to ActionController
Add http_cache_forever to ActionController, so we can cache results
forever.
Things like static pages are a good candidate for this type of caching.
This cache only controls caching headers, so it is up to the browser to
cache those requests.
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/render_test.rb | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 8d6b62f2bf..488585c7a4 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -561,3 +561,56 @@ class HeadRenderTest < ActionController::TestCase assert_response :forbidden end end + +class HttpCacheForeverTest < ActionController::TestCase + class HttpCacheForeverController < ActionController::Base + def cache_me_forever + http_cache_forever(public: params[:public], version: params[:version] || 'v1') do + render text: 'hello' + end + end + end + + tests HttpCacheForeverController + + def test_cache_with_public + get :cache_me_forever, params: {public: true} + assert_equal "max-age=#{100.years.to_i}, public", @response.headers["Cache-Control"] + assert_not_nil @response.etag + end + + def test_cache_with_private + get :cache_me_forever + assert_equal "max-age=#{100.years.to_i}, private", @response.headers["Cache-Control"] + assert_not_nil @response.etag + assert_response :success + end + + def test_cache_response_code_with_if_modified_since + get :cache_me_forever + assert_response :success + @request.if_modified_since = @response.headers['Last-Modified'] + get :cache_me_forever + assert_response :not_modified + end + + def test_cache_response_code_with_etag + get :cache_me_forever + assert_response :success + @request.if_modified_since = @response.headers['Last-Modified'] + @request.if_none_match = @response.etag + + get :cache_me_forever + assert_response :not_modified + @request.if_modified_since = @response.headers['Last-Modified'] + @request.if_none_match = @response.etag + + get :cache_me_forever, params: {version: 'v2'} + assert_response :success + @request.if_modified_since = @response.headers['Last-Modified'] + @request.if_none_match = @response.etag + + get :cache_me_forever, params: {version: 'v2'} + assert_response :not_modified + end +end |