Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Handle 204 response from resource#delete

Net::HTTP returns a nil body when it receives a 204 response, which
caused the client to raise a method not found on nil for empty?.

FakeWeb doesn't allow nil response bodies, so we had to use more
intrusive stubbing. There is a pull request to fix this bug on FakeWeb
[chrisk/fakeweb#32], so this test should be
updated upon FakeWeb being updated.
  • Loading branch information...
commit 9f6fa2532ac5d4a222e993dd3a6928bb40c546f6 1 parent 0537a15
Alexander Murmann & Ryan Spore authored
Showing with 9 additions and 1 deletion.
  1. +1 −1  lib/twilio-ruby/rest/client.rb
  2. +8 −0 spec/rest/client_spec.rb
View
2  lib/twilio-ruby/rest/client.rb
@@ -218,7 +218,7 @@ def connect_and_send(request) # :doc:
rescue Exception
if retries_left > 0 then retries_left -= 1; retry else raise end
end
- object = MultiJson.load response.body unless response.body.empty?
+ object = MultiJson.load response.body unless response.body.nil? || response.body.empty?
if response.kind_of? Net::HTTPClientError
raise Twilio::REST::RequestError.new object['message'], object['code']
end
View
8 spec/rest/client_spec.rb
@@ -7,6 +7,14 @@
Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
end
+ it 'should not raise an error if the response body is nil' do
+ response = double(:response, body: nil)
+ connection = double(:connection, request: response)
+ twilio = Twilio::REST::Client.new('someSid', 'someToken')
+ twilio.instance_variable_set(:@connection, connection)
+ Twilio::REST::IncomingPhoneNumber.new('/phone_number', twilio).delete
+ end
+
it 'should set up a new client instance with the given sid and token' do
twilio = Twilio::REST::Client.new('someSid', 'someToken')
twilio.account_sid.should == 'someSid'
Please sign in to comment.
Something went wrong with that request. Please try again.