sinatra-sinatra 0.8.9 → 0.8.10
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +11 -0
- data/README.rdoc +2 -1
- data/lib/sinatra/base.rb +26 -5
- data/lib/sinatra/test.rb +5 -0
- data/sinatra.gemspec +4 -3
- data/test/filter_test.rb +2 -2
- data/test/helper.rb +5 -0
- data/test/helpers_test.rb +1 -1
- data/test/mapped_error_test.rb +2 -2
- data/test/request_test.rb +9 -0
- data/test/routing_test.rb +69 -12
- metadata +4 -4
data/CHANGES
CHANGED
@@ -8,6 +8,10 @@
|
|
8
8
|
Documentation on using these features is forth-coming; the following
|
9
9
|
provides the basic gist: http://gist.github.com/38605
|
10
10
|
|
11
|
+
* Parameters with subscripts are now parsed into a nested/recursive
|
12
|
+
Hash structure. e.g., "post[title]=Hello&post[body]=World" yields
|
13
|
+
params: {'post' => {'title' => 'Hello', 'body' => 'World'}}.
|
14
|
+
|
11
15
|
* Regular expressions may now be used in route pattens; captures are
|
12
16
|
available at "params[:captures]".
|
13
17
|
|
@@ -41,6 +45,13 @@
|
|
41
45
|
has the status code specified. It's also possible to register an error
|
42
46
|
page for a range of status codes: "error(500..599)".
|
43
47
|
|
48
|
+
* Sinatra's testing support is no longer dependent on Test::Unit. Requiring
|
49
|
+
'sinatra/test' adds the Sinatra::Test module and Sinatra::TestHarness
|
50
|
+
class, which can be used with any test framework. The 'sinatra/test/unit',
|
51
|
+
'sinatra/test/spec', 'sinatra/test/rspec', or 'sinatra/test/bacon' files
|
52
|
+
can be required to setup a framework-specific testing environment. See the
|
53
|
+
README for more information.
|
54
|
+
|
44
55
|
* Added support for Bacon (test framework). The 'sinatra/test/bacon' file
|
45
56
|
can be required to setup Sinatra test helpers on Bacon::Context.
|
46
57
|
|
data/README.rdoc
CHANGED
@@ -464,13 +464,14 @@ friends.
|
|
464
464
|
|
465
465
|
Sinatra applications can be run directly:
|
466
466
|
|
467
|
-
ruby myapp.rb [-h] [-x] [-p PORT] [-
|
467
|
+
ruby myapp.rb [-h] [-x] [-e ENVIRONMENT] [-p PORT] [-s HANDLER]
|
468
468
|
|
469
469
|
Options are:
|
470
470
|
|
471
471
|
-h # help
|
472
472
|
-p # set the port (default is 4567)
|
473
473
|
-e # set the environment (default is development)
|
474
|
+
-s # specify rack server/handler (default is thin)
|
474
475
|
-x # turn on the mutex lock (default is off)
|
475
476
|
|
476
477
|
== Contributing
|
data/lib/sinatra/base.rb
CHANGED
@@ -4,7 +4,7 @@ require 'rack'
|
|
4
4
|
require 'rack/builder'
|
5
5
|
|
6
6
|
module Sinatra
|
7
|
-
VERSION = '0.8.
|
7
|
+
VERSION = '0.8.10'
|
8
8
|
|
9
9
|
class Request < Rack::Request
|
10
10
|
def user_agent
|
@@ -14,6 +14,13 @@ module Sinatra
|
|
14
14
|
def accept
|
15
15
|
@env['HTTP_ACCEPT'].split(',').map { |a| a.strip }
|
16
16
|
end
|
17
|
+
|
18
|
+
# Override Rack 0.9.x's #params implementation (see #72 in lighthouse)
|
19
|
+
def params
|
20
|
+
self.GET.update(self.POST)
|
21
|
+
rescue EOFError => boom
|
22
|
+
self.GET
|
23
|
+
end
|
17
24
|
end
|
18
25
|
|
19
26
|
class Response < Rack::Response
|
@@ -324,8 +331,7 @@ module Sinatra
|
|
324
331
|
self.class.filters.each {|block| instance_eval(&block)}
|
325
332
|
if routes = self.class.routes[@request.request_method]
|
326
333
|
path = @request.path_info
|
327
|
-
original_params =
|
328
|
-
original_params.merge! @request.params
|
334
|
+
original_params = nested_params(@request.params)
|
329
335
|
|
330
336
|
routes.each do |pattern, keys, conditions, method_name|
|
331
337
|
if pattern =~ path
|
@@ -345,8 +351,7 @@ module Sinatra
|
|
345
351
|
else
|
346
352
|
{}
|
347
353
|
end
|
348
|
-
@params = original_params.
|
349
|
-
@params.merge!(params)
|
354
|
+
@params = original_params.merge(params)
|
350
355
|
|
351
356
|
catch(:pass) {
|
352
357
|
conditions.each { |cond|
|
@@ -359,6 +364,22 @@ module Sinatra
|
|
359
364
|
raise NotFound
|
360
365
|
end
|
361
366
|
|
367
|
+
def nested_params(params)
|
368
|
+
return indifferent_hash.merge(params) if !params.keys.join.include?('[')
|
369
|
+
params.inject indifferent_hash do |res, (key,val)|
|
370
|
+
if key =~ /\[.*\]/
|
371
|
+
splat = key.scan(/(^[^\[]+)|\[([^\]]+)\]/).flatten.compact
|
372
|
+
head, last = splat[0..-2], splat[-1]
|
373
|
+
head.inject(res){ |s,v| s[v] ||= indifferent_hash }[last] = val
|
374
|
+
end
|
375
|
+
res
|
376
|
+
end
|
377
|
+
end
|
378
|
+
|
379
|
+
def indifferent_hash
|
380
|
+
Hash.new {|hash,key| hash[key.to_s] if Symbol === key }
|
381
|
+
end
|
382
|
+
|
362
383
|
def invoke(handler)
|
363
384
|
res = catch(:halt) {
|
364
385
|
if handler.respond_to?(:call)
|
data/lib/sinatra/test.rb
CHANGED
@@ -60,6 +60,11 @@ module Sinatra
|
|
60
60
|
end
|
61
61
|
end
|
62
62
|
|
63
|
+
# Also check @response since we delegate there.
|
64
|
+
def respond_to?(symbol, include_private=false)
|
65
|
+
super || (@response && @response.respond_to?(symbol, include_private))
|
66
|
+
end
|
67
|
+
|
63
68
|
RACK_OPT_NAMES = {
|
64
69
|
:accept => "HTTP_ACCEPT",
|
65
70
|
:agent => "HTTP_USER_AGENT",
|
data/sinatra.gemspec
CHANGED
@@ -3,13 +3,14 @@ Gem::Specification.new do |s|
|
|
3
3
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
4
4
|
|
5
5
|
s.name = 'sinatra'
|
6
|
-
s.version = '0.8.
|
7
|
-
s.date = '2009-01-
|
6
|
+
s.version = '0.8.10'
|
7
|
+
s.date = '2009-01-16'
|
8
8
|
|
9
9
|
s.description = "Classy web-development dressed in a DSL"
|
10
10
|
s.summary = "Classy web-development dressed in a DSL"
|
11
11
|
|
12
12
|
s.authors = ["Blake Mizerany"]
|
13
|
+
s.email = "sinatrarb@googlegroups.com"
|
13
14
|
|
14
15
|
# = MANIFEST =
|
15
16
|
s.files = %w[
|
@@ -98,7 +99,7 @@ Gem::Specification.new do |s|
|
|
98
99
|
s.test_files = s.files.select {|path| path =~ /^test\/.*_test.rb/}
|
99
100
|
|
100
101
|
s.extra_rdoc_files = %w[README.rdoc LICENSE]
|
101
|
-
s.add_dependency 'rack', '>= 0.9.
|
102
|
+
s.add_dependency 'rack', '>= 0.9.1'
|
102
103
|
|
103
104
|
s.has_rdoc = true
|
104
105
|
s.homepage = "http://sinatra.rubyforge.org"
|
data/test/filter_test.rb
CHANGED
data/test/helper.rb
CHANGED
data/test/helpers_test.rb
CHANGED
data/test/mapped_error_test.rb
CHANGED
@@ -34,8 +34,8 @@ describe 'Exception Mappings' do
|
|
34
34
|
mock_app {
|
35
35
|
set :raise_errors, false
|
36
36
|
error(FooError) {
|
37
|
-
|
38
|
-
|
37
|
+
assert env.include?('sinatra.error')
|
38
|
+
assert env['sinatra.error'].kind_of?(FooError)
|
39
39
|
'looks good'
|
40
40
|
}
|
41
41
|
get '/' do
|
data/test/request_test.rb
CHANGED
@@ -6,4 +6,13 @@ describe 'Sinatra::Request' do
|
|
6
6
|
assert request.respond_to?(:user_agent)
|
7
7
|
assert_equal 'Test', request.user_agent
|
8
8
|
end
|
9
|
+
|
10
|
+
it 'parses POST params when Content-Type is form-dataish' do
|
11
|
+
request = Sinatra::Request.new(
|
12
|
+
'REQUEST_METHOD' => 'PUT',
|
13
|
+
'CONTENT_TYPE' => 'application/x-www-form-urlencoded',
|
14
|
+
'rack.input' => StringIO.new('foo=bar')
|
15
|
+
)
|
16
|
+
assert_equal 'bar', request.params['foo']
|
17
|
+
end
|
9
18
|
end
|
data/test/routing_test.rb
CHANGED
@@ -27,8 +27,8 @@ describe "Routing" do
|
|
27
27
|
it "exposes params with indifferent hash" do
|
28
28
|
mock_app {
|
29
29
|
get '/:foo' do
|
30
|
-
|
31
|
-
|
30
|
+
assert_equal 'bar', params['foo']
|
31
|
+
assert_equal 'bar', params[:foo]
|
32
32
|
'well, alright'
|
33
33
|
end
|
34
34
|
}
|
@@ -39,8 +39,8 @@ describe "Routing" do
|
|
39
39
|
it "merges named params and query string params in params" do
|
40
40
|
mock_app {
|
41
41
|
get '/:foo' do
|
42
|
-
|
43
|
-
|
42
|
+
assert_equal 'bar', params['foo']
|
43
|
+
assert_equal 'biz', params['baz']
|
44
44
|
end
|
45
45
|
}
|
46
46
|
get '/bar?baz=biz'
|
@@ -80,7 +80,7 @@ describe "Routing" do
|
|
80
80
|
it "supports single splat params like /*" do
|
81
81
|
mock_app {
|
82
82
|
get '/*' do
|
83
|
-
|
83
|
+
assert params['splat'].kind_of?(Array)
|
84
84
|
params['splat'].join "\n"
|
85
85
|
end
|
86
86
|
}
|
@@ -95,7 +95,7 @@ describe "Routing" do
|
|
95
95
|
it "supports mixing multiple splat params like /*/foo/*/*" do
|
96
96
|
mock_app {
|
97
97
|
get '/*/foo/*/*' do
|
98
|
-
|
98
|
+
assert params['splat'].kind_of?(Array)
|
99
99
|
params['splat'].join "\n"
|
100
100
|
end
|
101
101
|
}
|
@@ -110,8 +110,8 @@ describe "Routing" do
|
|
110
110
|
it "supports mixing named and splat params like /:foo/*" do
|
111
111
|
mock_app {
|
112
112
|
get '/:foo/*' do
|
113
|
-
|
114
|
-
|
113
|
+
assert_equal 'foo', params['foo']
|
114
|
+
assert_equal ['bar/baz'], params['splat']
|
115
115
|
end
|
116
116
|
}
|
117
117
|
|
@@ -119,6 +119,63 @@ describe "Routing" do
|
|
119
119
|
assert ok?
|
120
120
|
end
|
121
121
|
|
122
|
+
it "supports basic nested params" do
|
123
|
+
mock_app {
|
124
|
+
get '/hi' do
|
125
|
+
params["person"]["name"]
|
126
|
+
end
|
127
|
+
}
|
128
|
+
|
129
|
+
get "/hi?person[name]=John+Doe"
|
130
|
+
assert ok?
|
131
|
+
assert_equal "John Doe", body
|
132
|
+
end
|
133
|
+
|
134
|
+
it "exposes nested params with indifferent hash" do
|
135
|
+
mock_app {
|
136
|
+
get '/testme' do
|
137
|
+
assert_equal 'baz', params['bar']['foo']
|
138
|
+
assert_equal 'baz', params['bar'][:foo]
|
139
|
+
'well, alright'
|
140
|
+
end
|
141
|
+
}
|
142
|
+
get '/testme?bar[foo]=baz'
|
143
|
+
assert_equal 'well, alright', body
|
144
|
+
end
|
145
|
+
|
146
|
+
it "supports deeply nested params" do
|
147
|
+
input = {
|
148
|
+
'browser[chrome][engine][name]' => 'V8',
|
149
|
+
'browser[chrome][engine][version]' => '1.0',
|
150
|
+
'browser[firefox][engine][name]' => 'spidermonkey',
|
151
|
+
'browser[firefox][engine][version]' => '1.7.0',
|
152
|
+
'emacs[map][goto-line]' => 'M-g g',
|
153
|
+
'emacs[version]' => '22.3.1',
|
154
|
+
'paste[name]' => 'hello world',
|
155
|
+
'paste[syntax]' => 'ruby'
|
156
|
+
}
|
157
|
+
expected = {
|
158
|
+
"emacs" => {
|
159
|
+
"map" => { "goto-line" => "M-g g" },
|
160
|
+
"version" => "22.3.1"
|
161
|
+
},
|
162
|
+
"browser" => {
|
163
|
+
"firefox" => {"engine" => {"name"=>"spidermonkey", "version"=>"1.7.0"}},
|
164
|
+
"chrome" => {"engine" => {"name"=>"V8", "version"=>"1.0"}}
|
165
|
+
},
|
166
|
+
"paste" => {"name"=>"hello world", "syntax"=>"ruby"}
|
167
|
+
}
|
168
|
+
mock_app {
|
169
|
+
get '/foo' do
|
170
|
+
assert_equal expected, params
|
171
|
+
'looks good'
|
172
|
+
end
|
173
|
+
}
|
174
|
+
get "/foo?#{param_string(input)}"
|
175
|
+
assert ok?
|
176
|
+
assert_equal 'looks good', body
|
177
|
+
end
|
178
|
+
|
122
179
|
it "supports paths that include spaces" do
|
123
180
|
mock_app {
|
124
181
|
get '/path with spaces' do
|
@@ -134,8 +191,8 @@ describe "Routing" do
|
|
134
191
|
it "URL decodes named parameters and splats" do
|
135
192
|
mock_app {
|
136
193
|
get '/:foo/*' do
|
137
|
-
|
138
|
-
|
194
|
+
assert_equal 'hello world', params['foo']
|
195
|
+
assert_equal ['how are you'], params['splat']
|
139
196
|
nil
|
140
197
|
end
|
141
198
|
}
|
@@ -159,7 +216,7 @@ describe "Routing" do
|
|
159
216
|
it 'makes regular expression captures available in params[:captures]' do
|
160
217
|
mock_app {
|
161
218
|
get(/^\/fo(.*)\/ba(.*)/) do
|
162
|
-
|
219
|
+
assert_equal ['orooomma', 'f'], params[:captures]
|
163
220
|
'right on'
|
164
221
|
end
|
165
222
|
}
|
@@ -190,7 +247,7 @@ describe "Routing" do
|
|
190
247
|
end
|
191
248
|
|
192
249
|
get '/*' do
|
193
|
-
|
250
|
+
assert !params.include?('foo')
|
194
251
|
'Hello World'
|
195
252
|
end
|
196
253
|
}
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sinatra-sinatra
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.8.
|
4
|
+
version: 0.8.10
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Blake Mizerany
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-01-
|
12
|
+
date: 2009-01-16 00:00:00 -08:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -19,10 +19,10 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - ">="
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.9.
|
22
|
+
version: 0.9.1
|
23
23
|
version:
|
24
24
|
description: Classy web-development dressed in a DSL
|
25
|
-
email:
|
25
|
+
email: sinatrarb@googlegroups.com
|
26
26
|
executables: []
|
27
27
|
|
28
28
|
extensions: []
|