From e4d01c7688abbde405098824959ef24397938fbb Mon Sep 17 00:00:00 2001 From: El Draper Date: Wed, 7 Oct 2009 19:22:58 +0100 Subject: [PATCH] a test and fix for 204 No Content responses, to ensure that the response object (and all important headers) are still returned --- lib/restclient/request.rb | 2 +- spec/request_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/restclient/request.rb b/lib/restclient/request.rb index dbe25d1..1110b5a 100644 --- a/lib/restclient/request.rb +++ b/lib/restclient/request.rb @@ -144,7 +144,7 @@ module RestClient elsif @raw_response RawResponse.new(@tf, res) else - nil + Response.new(nil, res) end end rescue EOFError diff --git a/spec/request_spec.rb b/spec/request_spec.rb index 00b799f..27b5cc2 100644 --- a/spec/request_spec.rb +++ b/spec/request_spec.rb @@ -481,4 +481,18 @@ describe RestClient::Request do @request.stub!(:response_log) @request.transmit(@uri, 'req', 'payload') end + + it "should still return a response object for 204 No Content responses" do + @request = RestClient::Request.new( + :method => :put, + :url => 'https://some/resource', + :payload => 'payload' + ) + net_http_res = Net::HTTPNoContent.new("", "204", "No Content") + net_http_res.stub(:read_body).and_return(nil) + @http.should_receive(:request).and_return(@request.fetch_body(net_http_res)) + response = @request.transmit(@uri, 'req', 'payload') + response.should_not be_nil + response.code.should equal(204) + end end