From a15635ce38bfba63db9c31c56da5da5ea0d83144 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Greg=20Kar=C3=A9kinian?= Date: Tue, 3 Mar 2015 21:56:19 +0100 Subject: [PATCH] Fix a bug when a document has an empty body Add check on content length for an empty file --- lib/remote_storage/riak.rb | 5 ++++- spec/riak_spec.rb | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/remote_storage/riak.rb b/lib/remote_storage/riak.rb index 1add990..9b3c2c2 100644 --- a/lib/remote_storage/riak.rb +++ b/lib/remote_storage/riak.rb @@ -68,7 +68,10 @@ module RemoteStorage when "application/json" return object.data.to_json else - return serializer_for(object.content_type) ? object.data : object.raw_data + data = serializer_for(object.content_type) ? object.data : object.raw_data + + # Never return nil, always turn data into a string + return data.nil? ? '' : data end rescue ::Riak::HTTPFailedRequest server.halt 404 diff --git a/spec/riak_spec.rb b/spec/riak_spec.rb index d5e2183..4865e38 100644 --- a/spec/riak_spec.rb +++ b/spec/riak_spec.rb @@ -76,6 +76,7 @@ describe "App with Riak backend" do it "returns an empty body" do last_response.status.must_equal 200 last_response.body.must_equal "" + last_response.headers["Content-Length"].must_equal '0' end end end