diff --git a/actionpack/lib/action_controller/base.rb b/actionpack/lib/action_controller/base.rb
index 457b9e85bce3d45e622e91f8c2347a2909f936d5..0e8d3efca462d8d7014d58779f2eaf1ce010b2f2 100644
--- a/actionpack/lib/action_controller/base.rb
+++ b/actionpack/lib/action_controller/base.rb
@@ -967,13 +967,15 @@ def head(*args)
# Sets the Last-Modified response header. Returns 304 Not Modified if the
# If-Modified-Since request header is <= last modified.
def last_modified!(utc_time)
- head(:not_modified) if response.last_modified!(utc_time)
+ response.last_modified= utc_time
+ head(:not_modified) if response.last_modified == request.if_modified_since
end
# Sets the ETag response header. Returns 304 Not Modified if the
# If-None-Match request header matches.
def etag!(etag)
- head(:not_modified) if response.etag!(etag)
+ response.etag = etag
+ head(:not_modified) if response.etag == request.if_none_match
end
# Clears the rendered results, allowing for another render to be performed.
diff --git a/actionpack/test/controller/render_test.rb b/actionpack/test/controller/render_test.rb
index af7b5dde6284d7bcb3d749faf8bbd138a09a3422..5a6ca98b2ed8e5069ab3dedc5babde6c07b55492 100644
--- a/actionpack/test/controller/render_test.rb
+++ b/actionpack/test/controller/render_test.rb
@@ -39,6 +39,16 @@ def conditional_hello
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 @@ def setup
@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 @@ def test_etag_should_govern_renders_with_layouts_too
assert_equal "\n\n Hello
\nThis is grand!
\n\n\n", @response.body
assert_equal etag_for("\n\n Hello
\nThis is grand!
\n\n\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 @@ def test_request_modified
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