Skip to content

Commit 4d6cb7a

Browse files
manisha1997Copilot
andauthored
chore: Support all status codes for delete (#766)
* chore: Support all status codes for delete * test: Add comprehensive delete method status code tests (#767) * Initial plan * Add comprehensive tests for delete method with various status codes Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com> * Add vendor/bundle to .gitignore and remove from repository Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com> --------- Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: manisha1997 <28821901+manisha1997@users.noreply.github.com>
1 parent e5e456b commit 4d6cb7a

File tree

3 files changed

+43
-2
lines changed

3 files changed

+43
-2
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ docs/_build
1919

2020

2121
coverage
22+
vendor/bundle

lib/twilio-ruby/framework/rest/version.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,11 @@ def delete(method, uri, params: {}, data: {}, headers: {}, auth: nil, timeout: n
105105
timeout
106106
)
107107

108-
if response.status_code < 200 || response.status_code >= 300
108+
if response.status_code < 200 || response.status_code >= 400
109109
raise exception(response, 'Unable to delete record')
110110
end
111111

112-
response.status_code == 204
112+
response.status_code >= 200 && response.status_code < 400
113113
end
114114

115115
def read_limits(limit = nil, page_size = nil)

spec/framework/version_spec.rb

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,4 +216,44 @@
216216

217217
expect(actual).to_not eq(nil)
218218
end
219+
220+
describe 'delete' do
221+
it 'succeeds with status code 204' do
222+
@holodeck.mock(Twilio::Response.new(204, ''))
223+
actual = @client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
224+
expect(actual).to eq(true)
225+
end
226+
227+
it 'succeeds with status code 200' do
228+
@holodeck.mock(Twilio::Response.new(200, ''))
229+
actual = @client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
230+
expect(actual).to eq(true)
231+
end
232+
233+
it 'succeeds with status code 202' do
234+
@holodeck.mock(Twilio::Response.new(202, ''))
235+
actual = @client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
236+
expect(actual).to eq(true)
237+
end
238+
239+
it 'succeeds with 3xx redirect code (307)' do
240+
@holodeck.mock(Twilio::Response.new(307, ''))
241+
actual = @client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
242+
expect(actual).to eq(true)
243+
end
244+
245+
it 'fails with 4xx error code (404)' do
246+
@holodeck.mock(Twilio::Response.new(404, '{"message": "Not found"}'))
247+
expect {
248+
@client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
249+
}.to raise_error(Twilio::REST::RestError)
250+
end
251+
252+
it 'fails with 5xx error code (500)' do
253+
@holodeck.mock(Twilio::Response.new(500, '{"message": "Internal server error"}'))
254+
expect {
255+
@client.api.v2010.accounts('ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').messages('MMXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX').delete
256+
}.to raise_error(Twilio::REST::RestError)
257+
end
258+
end
219259
end

0 commit comments

Comments
 (0)