Skip to content

Commit

Permalink
Merge pull request #210 from adamgotterer/master
Browse files Browse the repository at this point in the history
Fix for #body_params causing undefined method `size'
  • Loading branch information
dblock committed Jul 23, 2012
2 parents fd65b15 + d0a8545 commit 261b40d
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 6 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Next Release
============

* [#210](https://github.com/intridea/grape/pull/210): Fix: `Endpoint#body_params` causing undefined method 'size' - [@adamgotterer](https://github.com/adamgotterer).
* [#201](https://github.com/intridea/grape/pull/201): Rewritten `params` DSL, including support for coercion and validations - [@schmurfy](https://github.com/schmurfy).
* [#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).
* [#181](https://github.com/intridea/grape/pull/181): Fix: Corrected JSON serialization of nested hashes containing `Grape::Entity` instances - [@benrosenblum](https://github.com/benrosenblum).
Expand Down
2 changes: 1 addition & 1 deletion lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def params

# Pull out request body params if the content type matches and we're on a POST or PUT
def body_params
if ['POST', 'PUT'].include?(request.request_method.to_s.upcase) && request.body.size > 0
if ['POST', 'PUT'].include?(request.request_method.to_s.upcase) && request.content_length.to_i > 0
return case env['CONTENT_TYPE']
when 'application/json'
MultiJson.decode(request.body.read)
Expand Down
5 changes: 0 additions & 5 deletions spec/grape/endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,6 @@ def app; subject end
last_response.body.should == 'Bobby T.'
end

it 'should convert JSON bodies to params' do
put '/request_body', MultiJson.encode(:user => 'Bobby T.'), {'CONTENT_TYPE' => 'application/json'}
last_response.body.should == 'Bobby T.'
end

it 'should not convert empty JSON bodies to params' do
put '/request_body', '', {'CONTENT_TYPE' => 'application/json'}
last_response.body.should == ''
Expand Down

0 comments on commit 261b40d

Please sign in to comment.