From cbed26fabff04c379882e90247a7d4f31afdf6ab Mon Sep 17 00:00:00 2001 From: Adam Gotterer Date: Sun, 22 Jul 2012 16:44:55 -0400 Subject: [PATCH 1/2] Removed duplicate test --- spec/grape/endpoint_spec.rb | 5 ----- 1 file changed, 5 deletions(-) diff --git a/spec/grape/endpoint_spec.rb b/spec/grape/endpoint_spec.rb index 2c5d9e61af..d6ff1c5e4e 100644 --- a/spec/grape/endpoint_spec.rb +++ b/spec/grape/endpoint_spec.rb @@ -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 == '' From d0a8545f3bb076bd799c9613ef8bdb4a434bc151 Mon Sep 17 00:00:00 2001 From: Adam Gotterer Date: Sun, 22 Jul 2012 16:48:34 -0400 Subject: [PATCH 2/2] Changes how #body_params determines the length of the request --- CHANGELOG.markdown | 1 + lib/grape/endpoint.rb | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 0537ecb1fd..90d3880bac 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -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). diff --git a/lib/grape/endpoint.rb b/lib/grape/endpoint.rb index 063265bd47..eca96166b0 100644 --- a/lib/grape/endpoint.rb +++ b/lib/grape/endpoint.rb @@ -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)