diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-21 02:30:13 +0200 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2008-10-21 02:30:13 +0200 |
commit | 9acb88e666269204821b78bec7b72d3d16597096 (patch) | |
tree | 7ccdbde942b6cd97fe2c522dd6c9ccb60279393b /actionpack/test | |
parent | c79f1d281f1932d4203c7b5b5c793e370ed63838 (diff) | |
download | rails-9acb88e666269204821b78bec7b72d3d16597096.tar.gz rails-9acb88e666269204821b78bec7b72d3d16597096.tar.bz2 rails-9acb88e666269204821b78bec7b72d3d16597096.zip |
Added stale?/fresh? and fresh_when methods to provide a layer of abstraction above request.fresh? and friends [DHH]
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/controller/render_test.rb | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb index 7b8bb6856b..98d4cb3ffe 100644 --- a/actionpack/test/controller/render_test.rb +++ b/actionpack/test/controller/render_test.rb @@ -30,24 +30,20 @@ class TestController < ActionController::Base end def conditional_hello - response.last_modified = Time.now.utc.beginning_of_day - response.etag = [:foo, 123] - - if request.fresh?(response) - head :not_modified - else + if stale?(:last_modified => Time.now.utc.beginning_of_day, :etag => [:foo, 123]) render :action => 'hello_world' end end - + def conditional_hello_with_bangs render :action => 'hello_world' end before_filter :handle_last_modified_and_etags, :only=>:conditional_hello_with_bangs def handle_last_modified_and_etags - last_modified! Time.now.utc.beginning_of_day - etag! [:foo, 123] + if fresh?(:last_modified => Time.now.utc.beginning_of_day, :etag => [ :foo, 123 ]) + head :not_modified + end end def render_hello_world @@ -248,7 +244,7 @@ class TestController < ActionController::Base if @alternate_default_render @alternate_default_render.call else - render + super end end @@ -1422,6 +1418,13 @@ class LastModifiedRenderTest < Test::Unit::TestCase assert_equal @last_modified, @response.headers['Last-Modified'] end + def test_request_not_modified_but_etag_differs + @request.if_modified_since = @last_modified + @request.if_none_match = "234" + get :conditional_hello + assert_response :success + end + def test_request_modified @request.if_modified_since = 'Thu, 16 Jul 2008 00:00:00 GMT' get :conditional_hello @@ -1445,7 +1448,7 @@ class LastModifiedRenderTest < Test::Unit::TestCase def test_last_modified_works_with_less_than_too @request.if_modified_since = 5.years.ago.httpdate get :conditional_hello_with_bangs - assert_response :not_modified + assert_response :success end end |