Skip to content

Commit 261b40d

Browse files
committed
Merge pull request ruby-grape#210 from adamgotterer/master
Fix for #body_params causing undefined method `size'
2 parents fd65b15 + d0a8545 commit 261b40d

File tree

3 files changed

+2
-6
lines changed

3 files changed

+2
-6
lines changed

CHANGELOG.markdown

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
Next Release
22
============
33

4+
* [#210](https://github.com/intridea/grape/pull/210): Fix: `Endpoint#body_params` causing undefined method 'size' - [@adamgotterer](https://github.com/adamgotterer).
45
* [#201](https://github.com/intridea/grape/pull/201): Rewritten `params` DSL, including support for coercion and validations - [@schmurfy](https://github.com/schmurfy).
56
* [#205](https://github.com/intridea/grape/pull/205): Fix: Corrected parsing of empty JSON body on POST/PUT - [@tim-vandecasteele](https://github.com/tim-vandecasteele).
67
* [#181](https://github.com/intridea/grape/pull/181): Fix: Corrected JSON serialization of nested hashes containing `Grape::Entity` instances - [@benrosenblum](https://github.com/benrosenblum).

lib/grape/endpoint.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ def params
125125

126126
# Pull out request body params if the content type matches and we're on a POST or PUT
127127
def body_params
128-
if ['POST', 'PUT'].include?(request.request_method.to_s.upcase) && request.body.size > 0
128+
if ['POST', 'PUT'].include?(request.request_method.to_s.upcase) && request.content_length.to_i > 0
129129
return case env['CONTENT_TYPE']
130130
when 'application/json'
131131
MultiJson.decode(request.body.read)

spec/grape/endpoint_spec.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -186,11 +186,6 @@ def app; subject end
186186
last_response.body.should == 'Bobby T.'
187187
end
188188

189-
it 'should convert JSON bodies to params' do
190-
put '/request_body', MultiJson.encode(:user => 'Bobby T.'), {'CONTENT_TYPE' => 'application/json'}
191-
last_response.body.should == 'Bobby T.'
192-
end
193-
194189
it 'should not convert empty JSON bodies to params' do
195190
put '/request_body', '', {'CONTENT_TYPE' => 'application/json'}
196191
last_response.body.should == ''

0 commit comments

Comments
 (0)