Permalink
Browse files

Fixing 'pull/22 : HttpCacheResponder returns 304 even when the collec…

…tion has different set of resources'. Last-Modified header will not be set for GET on Collection
  • Loading branch information...
1 parent 9ecde4f commit 4da12a43e33a48feab49e71e9d72dc7a24c68512 @endeepak endeepak committed May 7, 2011
Showing with 7 additions and 8 deletions.
  1. +1 −3 lib/responders/http_cache_responder.rb
  2. +6 −5 test/http_cache_responder_test.rb
@@ -22,9 +22,7 @@ def to_format
protected
def do_http_cache!
- timestamp = resources.flatten.map do |resource|
- resource.updated_at.try(:utc) if resource.respond_to?(:updated_at)
- end.compact.max
+ timestamp = resource.updated_at.try(:utc) if resource.respond_to?(:updated_at)
controller.response.last_modified ||= timestamp if timestamp
@@ -86,10 +86,11 @@ def test_does_not_use_cache_if_http_cache_is_false
assert_equal 200, @response.status
end
- def test_collection_chooses_the_latest_timestamp
+ def test_does_not_set_cache_for_collection
get :collection
- assert_equal Time.utc(2009).httpdate, @response.headers["Last-Modified"]
- assert_match /xml/, @response.body
+
+ assert_nil @response.headers["Last-Modified"]
+ assert_not_nil @response.headers["ETag"]
assert_equal 200, @response.status
end
@@ -113,8 +114,8 @@ def test_work_with_an_empty_array
assert_equal 200, @response.status
end
- def test_it_does_not_set_body_etag
- get :collection
+ def test_it_does_not_set_body_etag_for_single_resource
+ get :single
assert_nil @response.headers["ETag"]
end

0 comments on commit 4da12a4

Please sign in to comment.