sinatra-rest-addons 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.3
1
+ 0.1.4
@@ -98,11 +98,15 @@ module Sinatra
98
98
  when /^application\/x-www-form-urlencoded/i
99
99
  request.env['sinatra.decoded_input'] = request.env['rack.request.form_hash']
100
100
  else
101
- if not size_range.include?(request.env['rack.input'].size)
101
+ content = ""
102
+ request.env['rack.input'].each do |block|
103
+ content.concat(block)
104
+ break if content.length > size_range.end
105
+ end
106
+ if not size_range.include?(content.length)
102
107
  content_type :txt
103
108
  halt 400, "Input data size must be between #{size_range.begin} and #{size_range.end} bytes."
104
109
  else
105
- content = request.env['rack.input'].read
106
110
  request.env['sinatra.decoded_input'] = parsing_proc.call(mime_type, content)
107
111
  end
108
112
  end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sinatra-rest-addons}
8
- s.version = "0.1.3"
8
+ s.version = "0.1.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Cyril Rohr"]
12
- s.date = %q{2009-11-16}
12
+ s.date = %q{2009-11-23}
13
13
  s.description = %q{A set of helpers and extensions for sinatra apps that expose REST resources.}
14
14
  s.email = %q{cyril.rohr@gmail.com}
15
15
  s.extra_rdoc_files = [
@@ -161,6 +161,21 @@ class RoutesTest < Test::Unit::TestCase
161
161
  assert_equal JSON.dump(input), last_response.body
162
162
  assert_equal 'application/json', last_response.headers['Content-Type']
163
163
  end
164
+ test "should work" do
165
+ input = "{\"walltime\":3600,\"resources\":\"/nodes=1\",\"at\":1258552306,\"on_launch\":{\"in\":\"/home/crohr\",\"do\":\"id\"}}"
166
+ mock_app {
167
+ register Sinatra::REST::Routes
168
+ post '/', :decode => [PARSING_PROC, 2...3000] do
169
+ content_type 'application/json'
170
+ JSON.dump request.env['sinatra.decoded_input']
171
+ end
172
+ }
173
+ post '/', input, {'CONTENT_TYPE' => "application/json"}
174
+ p last_response.body
175
+ assert_equal 200, last_response.status
176
+ assert_equal JSON.parse(input), JSON.parse(last_response.body)
177
+ assert_equal 'application/json', last_response.headers['Content-Type']
178
+ end
164
179
  test "should set the decoded input to the params hash already decoded by Sinatra, if the request's content type is application/x-www-form-urlencoded" do
165
180
  input = {"key1" => ["value1", "value2"]}
166
181
  mock_app {
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-rest-addons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cyril Rohr
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-16 00:00:00 +01:00
12
+ date: 2009-11-23 00:00:00 +01:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency