aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test
diff options
context:
space:
mode:
authorGregg Pollack <Gregg@RailsEnvy.com>2009-02-27 13:24:52 -0500
committerDavid Heinemeier Hansson <david@loudthinking.com>2009-02-28 10:33:42 +0100
commitf2a32bd0dedf11021027e36cc2c99f97434cae17 (patch)
tree67e2133a00072d4f9e2a9a6718c0f408f5197188 /actionpack/test
parent7058c1366ee33f3095b8737c2b71876702cddea6 (diff)
downloadrails-f2a32bd0dedf11021027e36cc2c99f97434cae17.tar.gz
rails-f2a32bd0dedf11021027e36cc2c99f97434cae17.tar.bz2
rails-f2a32bd0dedf11021027e36cc2c99f97434cae17.zip
Added ability to pass in :public => true to fresh_when, stale?, and expires_in to make the request proxy cachable [#2095 state:committed]
Signed-off-by: David Heinemeier Hansson <david@loudthinking.com>
Diffstat (limited to 'actionpack/test')
-rw-r--r--actionpack/test/controller/render_test.rb72
1 files changed, 72 insertions, 0 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index 70e5e62c93..02ae8ac942 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -36,6 +36,39 @@ class TestController < ActionController::Base
render :action => 'hello_world'
end
end
+
+ def conditional_hello_with_public_header
+ if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
+ render :action => 'hello_world'
+ end
+ end
+
+ def conditional_hello_with_public_header_and_expires_at
+ expires_in 1.minute
+ if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123], :public => true)
+ render :action => 'hello_world'
+ end
+ end
+
+ def conditional_hello_with_expires_in
+ expires_in 1.minute
+ render :action => 'hello_world'
+ end
+
+ def conditional_hello_with_expires_in_with_public
+ expires_in 1.minute, :public => true
+ render :action => 'hello_world'
+ end
+
+ def conditional_hello_with_expires_in_with_public_with_more_keys
+ expires_in 1.minute, :public => true, 'max-stale' => 5.hours
+ render :action => 'hello_world'
+ end
+
+ def conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
+ expires_in 1.minute, :public => true, :private => nil, 'max-stale' => 5.hours
+ render :action => 'hello_world'
+ end
def conditional_hello_with_bangs
render :action => 'hello_world'
@@ -1464,6 +1497,35 @@ class RenderTest < ActionController::TestCase
end
end
+class ExpiresInRenderTest < ActionController::TestCase
+ tests TestController
+
+ def setup
+ @request.host = "www.nextangle.com"
+ end
+
+ def test_expires_in_header
+ get :conditional_hello_with_expires_in
+ assert_equal "max-age=60, private", @response.headers["Cache-Control"]
+ end
+
+ def test_expires_in_header
+ get :conditional_hello_with_expires_in_with_public
+ assert_equal "max-age=60, public", @response.headers["Cache-Control"]
+ end
+
+ def test_expires_in_header_with_additional_headers
+ get :conditional_hello_with_expires_in_with_public_with_more_keys
+ assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
+ end
+
+ def test_expires_in_old_syntax
+ get :conditional_hello_with_expires_in_with_public_with_more_keys_old_syntax
+ assert_equal "max-age=60, public, max-stale=18000", @response.headers["Cache-Control"]
+ end
+end
+
+
class EtagRenderTest < ActionController::TestCase
tests TestController
@@ -1553,6 +1615,16 @@ class EtagRenderTest < ActionController::TestCase
get :conditional_hello_with_bangs
assert_response :not_modified
end
+
+ def test_etag_with_public_true_should_set_header
+ get :conditional_hello_with_public_header
+ assert_equal "public", @response.headers['Cache-Control']
+ end
+
+ def test_etag_with_public_true_should_set_header_and_retain_other_headers
+ get :conditional_hello_with_public_header_and_expires_at
+ assert_equal "max-age=60, public", @response.headers['Cache-Control']
+ end
protected
def etag_for(text)