Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for #body_params causing undefined method `size' #210

Merged
merged 2 commits into from
Jul 23, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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