aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/controller
diff options
context:
space:
mode:
authorMichael Koziarski <michael@koziarski.com>2008-09-30 17:00:38 +0200
committerMichael Koziarski <michael@koziarski.com>2008-09-30 17:00:38 +0200
commit0eefa7058a47772978aef550f7d85235a5529874 (patch)
treef4cfe7d365a6baa23a67e8d3deeabd8ea08f45ec /actionpack/test/controller
parent0b465032540ef92353e67eabd05eaf5867bfcc31 (diff)
downloadrails-0eefa7058a47772978aef550f7d85235a5529874.tar.gz
rails-0eefa7058a47772978aef550f7d85235a5529874.tar.bz2
rails-0eefa7058a47772978aef550f7d85235a5529874.zip
Fix etag! and last_modified! to work as advertised.
Add tests too.
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r--actionpack/test/controller/render_test.rb41
1 files changed, 40 insertions, 1 deletions
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index af7b5dde62..5a6ca98b2e 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -39,6 +39,16 @@ class TestController < ActionController::Base
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]
+ end
def render_hello_world
render :template => "test/hello_world"
@@ -1306,6 +1316,7 @@ class EtagRenderTest < Test::Unit::TestCase
@controller = TestController.new
@request.host = "www.nextangle.com"
+ @expected_bang_etag = etag_for(expand_key([:foo, 123]))
end
def test_render_200_should_set_etag
@@ -1365,11 +1376,27 @@ class EtagRenderTest < Test::Unit::TestCase
assert_equal "<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n", @response.body
assert_equal etag_for("<wrapper>\n<html>\n <p>Hello </p>\n<p>This is grand!</p>\n</html>\n</wrapper>\n"), @response.headers['ETag']
end
-
+
+ def test_etag_with_bang_should_set_etag
+ get :conditional_hello_with_bangs
+ assert_equal @expected_bang_etag, @response.headers["ETag"]
+ assert_response :success
+ end
+
+ def test_etag_with_bang_should_obey_if_none_match
+ @request.if_none_match = @expected_bang_etag
+ get :conditional_hello_with_bangs
+ assert_response :not_modified
+ end
+
protected
def etag_for(text)
%("#{Digest::MD5.hexdigest(text)}")
end
+
+ def expand_key(args)
+ ActiveSupport::Cache.expand_cache_key(args)
+ end
end
class LastModifiedRenderTest < Test::Unit::TestCase
@@ -1402,6 +1429,18 @@ class LastModifiedRenderTest < Test::Unit::TestCase
assert !@response.body.blank?
assert_equal @last_modified, @response.headers['Last-Modified']
end
+
+ def test_request_with_bang_gets_last_modified
+ get :conditional_hello_with_bangs
+ assert_equal @last_modified, @response.headers['Last-Modified']
+ assert_response :success
+ end
+
+ def test_request_with_bang_obeys_last_modified
+ @request.if_modified_since = @last_modified
+ get :conditional_hello_with_bangs
+ assert_response :not_modified
+ end
end
class RenderingLoggingTest < Test::Unit::TestCase