diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index ecd69c98f9..1d7f66c286 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,16 +1,16 @@ # This configuration was generated by # `rubocop --auto-gen-config` -# on 2017-02-02 01:40:01 +0900 using RuboCop version 0.47.0. +# on 2017-02-19 15:40:46 -0500 using RuboCop version 0.47.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 44 +# Offense count: 43 Metrics/AbcSize: Max: 44 -# Offense count: 266 +# Offense count: 265 # Configuration parameters: CountComments, ExcludedMethods. Metrics/BlockLength: Max: 3104 @@ -23,19 +23,19 @@ Metrics/BlockNesting: # Offense count: 8 # Configuration parameters: CountComments. Metrics/ClassLength: - Max: 280 + Max: 281 -# Offense count: 27 +# Offense count: 26 Metrics/CyclomaticComplexity: Max: 14 -# Offense count: 983 +# Offense count: 993 # Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns. # URISchemes: http, https Metrics/LineLength: Max: 215 -# Offense count: 55 +# Offense count: 56 # Configuration parameters: CountComments. Metrics/MethodLength: Max: 33 @@ -45,7 +45,7 @@ Metrics/MethodLength: Metrics/ModuleLength: Max: 212 -# Offense count: 18 +# Offense count: 16 Metrics/PerceivedComplexity: Max: 14 diff --git a/CHANGELOG.md b/CHANGELOG.md index 625929113d..2feefa34c4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,6 +3,7 @@ #### Fixes * [#1570](https://github.com/ruby-grape/grape/pull/1570): Make versioner consider the mount destination path - [@namusyaka](https://github.com/namusyaka). +* [#1579](https://github.com/ruby-grape/grape/pull/1579): Fix delete status with a return value - [@eproulx-petalmd](https://github.com/eproulx-petalmd). * Your contribution here. #### Features diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index 2d7da93b41..9792199edd 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -265,8 +265,11 @@ def run run_filters afters, :after cookies.write(header) - # The Body commonly is an Array of Strings, the application instance itself, or a File-like object. - response_object = file || [body || response_object] + # status verifies body presence when DELETE + @body ||= response_object + + # The Body commonly is an Array of Strings, the application instance itself, or a File-like object + response_object = file || [body] [status, header, response_object] end end diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index da7a398b59..3ce801d482 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -1149,6 +1149,33 @@ def memoized end end + describe 'delete 200, with a return value (no explicit body)' do + it 'responds to /example delete method' do + subject.delete(:example) { 'deleted' } + delete '/example' + expect(last_response.status).to eql 200 + expect(last_response.body).not_to be_empty + end + end + + describe 'delete 204, with nil has return value (no explicit body)' do + it 'responds to /example delete method' do + subject.delete(:example) { nil } + delete '/example' + expect(last_response.status).to eql 204 + expect(last_response.body).to be_empty + end + end + + describe 'delete 204, with empty array has return value (no explicit body)' do + it 'responds to /example delete method' do + subject.delete(:example) { '' } + delete '/example' + expect(last_response.status).to eql 204 + expect(last_response.body).to be_empty + end + end + describe 'all other' do %w(post get head put options patch).each do |verb| it "allows for the anchoring option with a #{verb.upcase} method" do