Skip to content

Commit

Permalink
Fixing 'pull/22 : HttpCacheResponder returns 304 even when the collec…
Browse files Browse the repository at this point in the history
…tion has different set of resources'. Last-Modified header will not be set for GET on Collection
  • Loading branch information
endeepak committed May 7, 2011
1 parent 9ecde4f commit 4da12a4
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
4 changes: 1 addition & 3 deletions lib/responders/http_cache_responder.rb
Expand Up @@ -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

Expand Down
11 changes: 6 additions & 5 deletions test/http_cache_responder_test.rb
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit 4da12a4

Please sign in to comment.