diff --git a/lib/responders/http_cache_responder.rb b/lib/responders/http_cache_responder.rb index 1285baf..3599db2 100644 --- a/lib/responders/http_cache_responder.rb +++ b/lib/responders/http_cache_responder.rb @@ -20,8 +20,7 @@ def to_format resource.updated_at.utc if resource.respond_to?(:updated_at) end.compact.max - controller.response.last_modified = timestamp - + controller.response.last_modified = timestamp if timestamp if request.fresh?(controller.response) head :not_modified return diff --git a/test/http_cache_responder_test.rb b/test/http_cache_responder_test.rb index d34381e..d3c55ee 100644 --- a/test/http_cache_responder_test.rb +++ b/test/http_cache_responder_test.rb @@ -16,6 +16,10 @@ def single def collection respond_with [Model.new(Time.utc(2009)), Model.new(Time.utc(2008))] end + + def empty + respond_with [] + end end class HttpCacheResponderTest < ActionController::TestCase @@ -90,4 +94,11 @@ def test_collection_chooses_the_latest_timestamp assert_match /xml/, @response.body assert_equal 200, @response.status end + + def test_work_with_an_empty_array + get :empty + assert_nil @response.headers["Last-Modified"] + assert_match /xml/, @response.body + assert_equal 200, @response.status + end end \ No newline at end of file