Skip to content

Commit 3959a01

Browse files
ericproulxdblock
authored andcommitted
Fix #1578 and #1572 (#1579)
1 parent 7a56fe9 commit 3959a01

File tree

4 files changed

+41
-10
lines changed

4 files changed

+41
-10
lines changed

.rubocop_todo.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# This configuration was generated by
22
# `rubocop --auto-gen-config`
3-
# on 2017-02-02 01:40:01 +0900 using RuboCop version 0.47.0.
3+
# on 2017-02-19 15:40:46 -0500 using RuboCop version 0.47.1.
44
# The point is for the user to remove these configuration records
55
# one by one as the offenses are removed from the code base.
66
# Note that changes in the inspected code, or installation of new
77
# versions of RuboCop, may require this file to be generated again.
88

9-
# Offense count: 44
9+
# Offense count: 43
1010
Metrics/AbcSize:
1111
Max: 44
1212

13-
# Offense count: 266
13+
# Offense count: 265
1414
# Configuration parameters: CountComments, ExcludedMethods.
1515
Metrics/BlockLength:
1616
Max: 3104
@@ -23,19 +23,19 @@ Metrics/BlockNesting:
2323
# Offense count: 8
2424
# Configuration parameters: CountComments.
2525
Metrics/ClassLength:
26-
Max: 280
26+
Max: 281
2727

28-
# Offense count: 27
28+
# Offense count: 26
2929
Metrics/CyclomaticComplexity:
3030
Max: 14
3131

32-
# Offense count: 983
32+
# Offense count: 993
3333
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
3434
# URISchemes: http, https
3535
Metrics/LineLength:
3636
Max: 215
3737

38-
# Offense count: 55
38+
# Offense count: 56
3939
# Configuration parameters: CountComments.
4040
Metrics/MethodLength:
4141
Max: 33
@@ -45,7 +45,7 @@ Metrics/MethodLength:
4545
Metrics/ModuleLength:
4646
Max: 212
4747

48-
# Offense count: 18
48+
# Offense count: 16
4949
Metrics/PerceivedComplexity:
5050
Max: 14
5151

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#### Fixes
44

55
* [#1570](https://github.com/ruby-grape/grape/pull/1570): Make versioner consider the mount destination path - [@namusyaka](https://github.com/namusyaka).
6+
* [#1579](https://github.com/ruby-grape/grape/pull/1579): Fix delete status with a return value - [@eproulx-petalmd](https://github.com/eproulx-petalmd).
67
* Your contribution here.
78

89
#### Features

lib/grape/endpoint.rb

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -265,8 +265,11 @@ def run
265265
run_filters afters, :after
266266
cookies.write(header)
267267

268-
# The Body commonly is an Array of Strings, the application instance itself, or a File-like object.
269-
response_object = file || [body || response_object]
268+
# status verifies body presence when DELETE
269+
@body ||= response_object
270+
271+
# The Body commonly is an Array of Strings, the application instance itself, or a File-like object
272+
response_object = file || [body]
270273
[status, header, response_object]
271274
end
272275
end

spec/grape/endpoint_spec.rb

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1149,6 +1149,33 @@ def memoized
11491149
end
11501150
end
11511151

1152+
describe 'delete 200, with a return value (no explicit body)' do
1153+
it 'responds to /example delete method' do
1154+
subject.delete(:example) { 'deleted' }
1155+
delete '/example'
1156+
expect(last_response.status).to eql 200
1157+
expect(last_response.body).not_to be_empty
1158+
end
1159+
end
1160+
1161+
describe 'delete 204, with nil has return value (no explicit body)' do
1162+
it 'responds to /example delete method' do
1163+
subject.delete(:example) { nil }
1164+
delete '/example'
1165+
expect(last_response.status).to eql 204
1166+
expect(last_response.body).to be_empty
1167+
end
1168+
end
1169+
1170+
describe 'delete 204, with empty array has return value (no explicit body)' do
1171+
it 'responds to /example delete method' do
1172+
subject.delete(:example) { '' }
1173+
delete '/example'
1174+
expect(last_response.status).to eql 204
1175+
expect(last_response.body).to be_empty
1176+
end
1177+
end
1178+
11521179
describe 'all other' do
11531180
%w(post get head put options patch).each do |verb|
11541181
it "allows for the anchoring option with a #{verb.upcase} method" do

0 commit comments

Comments
 (0)