padrino-core 0.12.9 → 0.13.0.beta1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -13
- data/bin/padrino +1 -2
- data/lib/padrino-core/application/application_setup.rb +10 -6
- data/lib/padrino-core/application/params_protection.rb +7 -1
- data/lib/padrino-core/application/routing.rb +88 -50
- data/lib/padrino-core/application/show_exceptions.rb +29 -0
- data/lib/padrino-core/application.rb +0 -19
- data/lib/padrino-core/caller.rb +1 -2
- data/lib/padrino-core/cli/base.rb +7 -11
- data/lib/padrino-core/cli/rake_tasks.rb +8 -21
- data/lib/padrino-core/loader.rb +13 -12
- data/lib/padrino-core/logger.rb +4 -32
- data/lib/padrino-core/mounter.rb +62 -21
- data/lib/padrino-core/path_router/compiler.rb +110 -0
- data/lib/padrino-core/path_router/error_handler.rb +8 -0
- data/lib/padrino-core/path_router/matcher.rb +123 -0
- data/lib/padrino-core/path_router/route.rb +169 -0
- data/lib/padrino-core/path_router.rb +119 -0
- data/lib/padrino-core/reloader/rack.rb +1 -4
- data/lib/padrino-core/reloader/storage.rb +3 -31
- data/lib/padrino-core/reloader.rb +12 -17
- data/lib/padrino-core/version.rb +1 -1
- data/lib/padrino-core.rb +0 -2
- data/padrino-core.gemspec +8 -2
- data/test/fixtures/apps/helpers/support.rb +1 -0
- data/test/fixtures/apps/{rack_apps.rb → mountable_apps/rack_apps.rb} +0 -4
- data/test/fixtures/apps/{static.html → mountable_apps/static.html} +0 -0
- data/test/fixtures/apps/precompiled_app.rb +19 -0
- data/test/fixtures/apps/system.rb +0 -2
- data/test/helper.rb +1 -1
- data/test/test_application.rb +18 -6
- data/test/test_csrf_protection.rb +6 -7
- data/test/test_filters.rb +18 -1
- data/test/test_logger.rb +1 -49
- data/test/test_mounter.rb +2 -4
- data/test/test_params_protection.rb +15 -15
- data/test/test_reloader_simple.rb +2 -2
- data/test/test_reloader_system.rb +0 -30
- data/test/test_restful_routing.rb +4 -4
- data/test/test_routing.rb +176 -54
- metadata +109 -49
- data/lib/padrino-core/cli/binstub.rb +0 -27
- data/lib/padrino-core/configuration.rb +0 -40
- data/lib/padrino-core/ext/http_router.rb +0 -201
- data/lib/padrino-core/mounter/application_extension.rb +0 -55
- data/test/fixtures/apps/custom_dependencies/custom_dependencies.rb +0 -11
- data/test/fixtures/apps/custom_dependencies/my_dependencies/my_dependency.rb +0 -0
- data/test/fixtures/apps/stealthy/app.rb +0 -7
- data/test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb +0 -13
- data/test/test_configuration.rb +0 -29
- data/test/test_reloader_storage.rb +0 -51
@@ -80,7 +80,7 @@ describe "SimpleReloader" do
|
|
80
80
|
assert ok?
|
81
81
|
last_body = body
|
82
82
|
assert_equal 1, @app.filters[:before].size
|
83
|
-
assert_equal
|
83
|
+
assert_equal 1, @app.errors.size
|
84
84
|
assert_equal 2, @app.filters[:after].size # app + content-type + padrino-flash
|
85
85
|
assert_equal 0, @app.middleware.size
|
86
86
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" + GET+HEAD of "/rand" = 4
|
@@ -90,7 +90,7 @@ describe "SimpleReloader" do
|
|
90
90
|
get "/rand"
|
91
91
|
refute_equal last_body, body
|
92
92
|
assert_equal 1, @app.filters[:before].size
|
93
|
-
assert_equal
|
93
|
+
assert_equal 1, @app.errors.size
|
94
94
|
assert_equal 2, @app.filters[:after].size
|
95
95
|
assert_equal 0, @app.middleware.size
|
96
96
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" = 2
|
@@ -2,7 +2,6 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
2
2
|
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq')
|
3
3
|
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system')
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/static')
|
5
|
-
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/custom_dependencies')
|
6
5
|
|
7
6
|
describe "SystemReloader" do
|
8
7
|
describe 'for wierd and difficult reload events' do
|
@@ -110,34 +109,5 @@ describe "SystemReloader" do
|
|
110
109
|
FileUtils.rm tmp_file
|
111
110
|
end
|
112
111
|
end
|
113
|
-
|
114
|
-
it 'should not fail with superclass mismatch when reloading descendant classes with no instances' do
|
115
|
-
Padrino.clear!
|
116
|
-
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/app.rb')
|
117
|
-
@app = SystemStealthyClassDemo
|
118
|
-
Padrino.mount(SystemStealthyClassDemo).to("/")
|
119
|
-
get '/'
|
120
|
-
FileUtils.touch File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb')
|
121
|
-
Padrino.reload!
|
122
|
-
end
|
123
|
-
end
|
124
|
-
|
125
|
-
describe 'reloading custom dependencies' do
|
126
|
-
let(:custom_dependency_path) { File.dirname(__FILE__) + '/fixtures/apps/custom_dependencies/my_dependencies' }
|
127
|
-
let(:custom_dependency) { File.join(custom_dependency_path, 'my_dependency.rb') }
|
128
|
-
|
129
|
-
before do
|
130
|
-
@app = CustomDependencies
|
131
|
-
Padrino.clear!
|
132
|
-
Padrino.mount(CustomDependencies).to("/")
|
133
|
-
Padrino.dependency_paths << custom_dependency_path + '/*.rb'
|
134
|
-
Padrino.load!
|
135
|
-
get '/'
|
136
|
-
end
|
137
|
-
|
138
|
-
it 'should discover changed dependencies' do
|
139
|
-
FileUtils.touch(custom_dependency)
|
140
|
-
assert Padrino::Reloader.changed?, 'Change to custom dependency has not been recognised'
|
141
|
-
end
|
142
112
|
end
|
143
113
|
end
|
@@ -4,8 +4,8 @@ describe "Routing" do
|
|
4
4
|
it 'should perform restul routing' do
|
5
5
|
mock_app do
|
6
6
|
controller :parent => :parents do
|
7
|
-
get :index do
|
8
|
-
"#{url_for(:index, params[:parent_id])} get"
|
7
|
+
get :index, :with => :asset_id do
|
8
|
+
"#{url_for(:index, params[:parent_id], :asset_id => params[:asset_id])} get"
|
9
9
|
end
|
10
10
|
|
11
11
|
put :index, :with => :asset_id do
|
@@ -21,8 +21,8 @@ describe "Routing" do
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
end
|
24
|
-
get "/parents/1"
|
25
|
-
assert_equal "/parents/1 get", body
|
24
|
+
get "/parents/1/hi"
|
25
|
+
assert_equal "/parents/1/hi get", body
|
26
26
|
put "/parents/1/hi"
|
27
27
|
assert_equal "/parents/1/hi put", body
|
28
28
|
post "/parents/1/hi"
|
data/test/test_routing.rb
CHANGED
@@ -3,6 +3,30 @@ require File.expand_path(File.dirname(__FILE__) + '/helper')
|
|
3
3
|
|
4
4
|
class FooError < RuntimeError; end
|
5
5
|
|
6
|
+
class RegexpLookAlike
|
7
|
+
# RegexpLookAlike#to_s, RegexpLookAlike#names and MatchData#names must be defined.
|
8
|
+
class MatchData
|
9
|
+
def captures
|
10
|
+
["this", "is", "a", "test"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def names
|
14
|
+
["one", "two", "three", "four"]
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def names
|
19
|
+
["one", "two", "three", "four"]
|
20
|
+
end
|
21
|
+
|
22
|
+
def to_s
|
23
|
+
"/this/is/a/test/"
|
24
|
+
end
|
25
|
+
|
26
|
+
def match(string)
|
27
|
+
::RegexpLookAlike::MatchData.new if string == "/this/is/a/test/"
|
28
|
+
end
|
29
|
+
end
|
6
30
|
|
7
31
|
describe "Routing" do
|
8
32
|
before do
|
@@ -234,6 +258,7 @@ describe "Routing" do
|
|
234
258
|
get(:hash, :with => :id){ url(:hash, :id => 1) }
|
235
259
|
get(:anchor) { url(:anchor, :anchor => 'comments') }
|
236
260
|
get(:fragment) { url(:anchor, :fragment => 'comments') }
|
261
|
+
get(:fragment2) { url(:anchor, :fragment => :comments) }
|
237
262
|
get([:hash, :id]){ url(:hash, :id => 1) }
|
238
263
|
get(:array, :with => :id){ url(:array, 23) }
|
239
264
|
get([:array, :id]){ url(:array, 23) }
|
@@ -248,6 +273,7 @@ describe "Routing" do
|
|
248
273
|
post(:foo, '', :with => :id){ |id| "/#{id}" }
|
249
274
|
delete(:drugs, :with => [:id, 'destroy']){ |id| "/drugs/#{id}/destroy" }
|
250
275
|
delete(:drugs, '', :with => [:id, 'destroy']){ |id| "/#{id}/destroy" }
|
276
|
+
get(:splatter, "/splatter/*/*"){ |a, b| url(:splatter, :splat => ["123", "456"]) }
|
251
277
|
end
|
252
278
|
get "/foo"
|
253
279
|
assert_equal "/foo", body
|
@@ -259,6 +285,8 @@ describe "Routing" do
|
|
259
285
|
assert_equal "/anchor#comments", body
|
260
286
|
get "/fragment"
|
261
287
|
assert_equal "/anchor#comments", body
|
288
|
+
get "/fragment2"
|
289
|
+
assert_equal "/anchor#comments", body
|
262
290
|
get "/array/23"
|
263
291
|
assert_equal "/array/23", body
|
264
292
|
get "/hash_with_extra/1"
|
@@ -279,6 +307,8 @@ describe "Routing" do
|
|
279
307
|
assert_equal "/drugs/123/destroy", body
|
280
308
|
delete "/123/destroy"
|
281
309
|
assert_equal "/123/destroy", body
|
310
|
+
get "/splatter/123/456"
|
311
|
+
assert_equal "/splatter/123/456", body
|
282
312
|
end
|
283
313
|
|
284
314
|
it 'should generate url with format' do
|
@@ -406,16 +436,6 @@ describe "Routing" do
|
|
406
436
|
assert_equal 406, status
|
407
437
|
end
|
408
438
|
|
409
|
-
it 'should provide proper content when :provides is specified and Accept: `*/*` requested' do
|
410
|
-
mock_app do
|
411
|
-
get(:text, :provides => :text) { "text" }
|
412
|
-
end
|
413
|
-
header 'Accept', '*/*'
|
414
|
-
get "/text"
|
415
|
-
assert_equal 200, status
|
416
|
-
assert_equal "text", body
|
417
|
-
end
|
418
|
-
|
419
439
|
it 'should return 404 on file extensions it does not provide and flag is not set' do
|
420
440
|
mock_app do
|
421
441
|
get(:a, :provides => [:html, :js]){ content_type }
|
@@ -461,7 +481,6 @@ describe "Routing" do
|
|
461
481
|
end
|
462
482
|
|
463
483
|
it 'should allow "." in param values' do
|
464
|
-
skip # TODO fix this?
|
465
484
|
mock_app do
|
466
485
|
get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' }
|
467
486
|
end
|
@@ -533,14 +552,14 @@ describe "Routing" do
|
|
533
552
|
it 'should inject the action name into the request' do
|
534
553
|
mock_app do
|
535
554
|
controller :posts do
|
536
|
-
get('/omnomnom(/:id)') { request.action.inspect }
|
555
|
+
get('/omnomnom(/:id)?') { request.action.inspect }
|
537
556
|
controller :mini do
|
538
557
|
get([:a, :b, :c]) { request.action.inspect }
|
539
558
|
end
|
540
559
|
end
|
541
560
|
end
|
542
561
|
get "/posts/omnomnom"
|
543
|
-
assert_equal "\"/omnomnom(/:id)
|
562
|
+
assert_equal "\"/omnomnom(/:id)?\"", body
|
544
563
|
get "/mini/a/b/c"
|
545
564
|
assert_equal ":a", body
|
546
565
|
end
|
@@ -737,27 +756,12 @@ describe "Routing" do
|
|
737
756
|
assert_equal 'application/json', response["Content-Type"]
|
738
757
|
get "/a.foo"
|
739
758
|
assert_equal "foo", body
|
740
|
-
assert_equal 'application/foo', response["Content-Type"]
|
759
|
+
assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
|
741
760
|
get "/a"
|
742
761
|
assert_equal "html", body
|
743
762
|
assert_equal 'text/html;charset=utf-8', response["Content-Type"]
|
744
763
|
end
|
745
764
|
|
746
|
-
it 'should not drop json charset' do
|
747
|
-
mock_app do
|
748
|
-
get '/' do
|
749
|
-
content_type :json, :charset => 'utf-16'
|
750
|
-
end
|
751
|
-
get '/a' do
|
752
|
-
content_type :json, 'charset' => 'utf-16'
|
753
|
-
end
|
754
|
-
end
|
755
|
-
get '/'
|
756
|
-
assert_equal 'application/json;charset=utf-16', response["Content-Type"]
|
757
|
-
get '/a'
|
758
|
-
assert_equal 'application/json;charset=utf-16', response["Content-Type"]
|
759
|
-
end
|
760
|
-
|
761
765
|
it 'should use controllers' do
|
762
766
|
mock_app do
|
763
767
|
controller "/admin" do
|
@@ -996,7 +1000,7 @@ describe "Routing" do
|
|
996
1000
|
|
997
1001
|
it 'should allow optionals' do
|
998
1002
|
mock_app do
|
999
|
-
get(:show, :map => "/stories/:type(/:category)") do
|
1003
|
+
get(:show, :map => "/stories/:type(/:category)?") do
|
1000
1004
|
"#{params[:type]}/#{params[:category]}"
|
1001
1005
|
end
|
1002
1006
|
end
|
@@ -1544,7 +1548,7 @@ describe "Routing" do
|
|
1544
1548
|
|
1545
1549
|
it 'should works with optionals params' do
|
1546
1550
|
mock_app do
|
1547
|
-
get("/foo(/:bar)") { params[:bar] }
|
1551
|
+
get("/foo(/:bar)?") { params[:bar] }
|
1548
1552
|
end
|
1549
1553
|
|
1550
1554
|
get "/foo/bar"
|
@@ -1692,7 +1696,7 @@ describe "Routing" do
|
|
1692
1696
|
|
1693
1697
|
it 'should use optionals params' do
|
1694
1698
|
mock_app do
|
1695
|
-
get(:index, :map => "
|
1699
|
+
get(:index, :map => "/:foo(/:bar)?") { "#{params[:foo]}-#{params[:bar]}" }
|
1696
1700
|
end
|
1697
1701
|
get "/foo"
|
1698
1702
|
assert_equal "foo-", body
|
@@ -2048,7 +2052,7 @@ describe "Routing" do
|
|
2048
2052
|
mock_app do
|
2049
2053
|
get(:index) { "%s %s" % [params[:account][:name], params[:account][:surname]] }
|
2050
2054
|
end
|
2051
|
-
get "/?" +
|
2055
|
+
get "/?" + { :account => { :name => 'foo', :surname => 'bar' } }.to_query
|
2052
2056
|
assert_equal 'foo bar', body
|
2053
2057
|
get @app.url(:index, "account[name]" => "foo", "account[surname]" => "bar")
|
2054
2058
|
assert_equal 'foo bar', body
|
@@ -2106,14 +2110,14 @@ describe "Routing" do
|
|
2106
2110
|
get(:simple, :map => "/simple/:id") { }
|
2107
2111
|
get(:with_format, :with => :id, :provides => :js) { }
|
2108
2112
|
end
|
2109
|
-
assert_equal [:"foo bar", { :id => "fantastic" }], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
|
2110
|
-
assert_equal [:"foo bar", { :id => "18" }], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
|
2111
|
-
assert_equal [:simple, { :id => "bar" }], @app.recognize_path(@app.url(:simple, :id => "bar"))
|
2112
|
-
assert_equal [:simple, { :id => "true" }], @app.recognize_path(@app.url(:simple, :id => true))
|
2113
|
-
assert_equal [:simple, { :id => "9" }], @app.recognize_path(@app.url(:simple, :id => 9))
|
2114
|
-
assert_equal [:with_format, { :id => "bar", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
|
2115
|
-
assert_equal [:with_format, { :id => "true", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
|
2116
|
-
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
2113
|
+
assert_equal [:"foo bar", { :id => "fantastic" }.with_indifferent_access], @app.recognize_path(@app.url(:foo, :bar, :id => :fantastic))
|
2114
|
+
assert_equal [:"foo bar", { :id => "18" }.with_indifferent_access], @app.recognize_path(@app.url(:foo, :bar, :id => 18))
|
2115
|
+
assert_equal [:simple, { :id => "bar" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => "bar"))
|
2116
|
+
assert_equal [:simple, { :id => "true" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => true))
|
2117
|
+
assert_equal [:simple, { :id => "9" }.with_indifferent_access], @app.recognize_path(@app.url(:simple, :id => 9))
|
2118
|
+
assert_equal [:with_format, { :id => "bar", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => "bar", :format => :js))
|
2119
|
+
assert_equal [:with_format, { :id => "true", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => true, :format => "js"))
|
2120
|
+
assert_equal [:with_format, { :id => "9", :format => "js" }.with_indifferent_access], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
2117
2121
|
end
|
2118
2122
|
|
2119
2123
|
it 'should have current_path' do
|
@@ -2165,15 +2169,25 @@ describe "Routing" do
|
|
2165
2169
|
end
|
2166
2170
|
|
2167
2171
|
it "should support splat params" do
|
2168
|
-
# This test will be fixed with the new router
|
2169
|
-
skip
|
2170
2172
|
mock_app do
|
2171
2173
|
get "/say/*/to/*" do
|
2172
2174
|
params[:splat].inspect
|
2173
2175
|
end
|
2174
2176
|
end
|
2175
2177
|
get "/say/hello/to/world"
|
2176
|
-
assert_equal ["hello", "world"], body
|
2178
|
+
assert_equal %Q[["hello", "world"]], body
|
2179
|
+
end
|
2180
|
+
|
2181
|
+
it "should recognize the route containing splat params if path is ended with slash" do
|
2182
|
+
mock_app do
|
2183
|
+
get "/splat/*" do
|
2184
|
+
"slash!"
|
2185
|
+
end
|
2186
|
+
end
|
2187
|
+
get "/splat"
|
2188
|
+
assert_equal 404, status
|
2189
|
+
get "/splat/"
|
2190
|
+
assert_equal "slash!", body
|
2177
2191
|
end
|
2178
2192
|
|
2179
2193
|
it "should match correctly paths even if the free regex route exists" do
|
@@ -2190,17 +2204,125 @@ describe "Routing" do
|
|
2190
2204
|
assert_equal '{"b"=>"x", "c"=>"y"}', body
|
2191
2205
|
end
|
2192
2206
|
|
2193
|
-
it
|
2207
|
+
it "should support named captures like %r{/hello/(?<person>[^/?#]+)} on Ruby >= 1.9" do
|
2208
|
+
next if RUBY_VERSION < '1.9'
|
2194
2209
|
mock_app do
|
2195
|
-
get
|
2196
|
-
|
2210
|
+
get Regexp.new('/hello/(?<person>[^/?#]+)') do
|
2211
|
+
"Hello #{params['person']}"
|
2212
|
+
end
|
2197
2213
|
end
|
2198
|
-
get '/'
|
2199
|
-
assert_equal '
|
2200
|
-
|
2201
|
-
|
2202
|
-
|
2203
|
-
|
2204
|
-
|
2214
|
+
get '/hello/Frank'
|
2215
|
+
assert_equal 'Hello Frank', body
|
2216
|
+
end
|
2217
|
+
|
2218
|
+
it 'supports regular expression look-alike routes' do
|
2219
|
+
mock_app do
|
2220
|
+
get(RegexpLookAlike.new) do
|
2221
|
+
[params[:one], params[:two], params[:three], params[:four]].join(" ")
|
2222
|
+
end
|
2223
|
+
end
|
2224
|
+
|
2225
|
+
get '/this/is/a/test/'
|
2226
|
+
assert ok?
|
2227
|
+
assert_equal 'this is a test', body
|
2228
|
+
end
|
2229
|
+
|
2230
|
+
it "uses optional block passed to pass as route block if no other route is found" do
|
2231
|
+
mock_app do
|
2232
|
+
get "/" do
|
2233
|
+
pass do
|
2234
|
+
"this"
|
2235
|
+
end
|
2236
|
+
"not this"
|
2237
|
+
end
|
2238
|
+
end
|
2239
|
+
|
2240
|
+
get "/"
|
2241
|
+
assert ok?
|
2242
|
+
assert_equal "this", body
|
2243
|
+
end
|
2244
|
+
|
2245
|
+
it "supports mixing multiple splat params like /*/foo/*/* as block parameters" do
|
2246
|
+
mock_app do
|
2247
|
+
get '/*/foo/*/*' do |foo, bar, baz|
|
2248
|
+
"#{foo}, #{bar}, #{baz}"
|
2249
|
+
end
|
2250
|
+
end
|
2251
|
+
|
2252
|
+
get '/bar/foo/bling/baz/boom'
|
2253
|
+
assert ok?
|
2254
|
+
assert_equal 'bar, bling, baz/boom', body
|
2255
|
+
end
|
2256
|
+
|
2257
|
+
it "should be able to use PathRouter#recognize to recognize routes" do
|
2258
|
+
mock_app do
|
2259
|
+
get(:sample){}
|
2260
|
+
end
|
2261
|
+
env = Rack::MockRequest.env_for("/sample")
|
2262
|
+
request = Rack::Request.new(env)
|
2263
|
+
assert_equal :sample, @app.router.recognize(request).first.name
|
2264
|
+
end
|
2265
|
+
|
2266
|
+
it "should be able to use PathRouter#recognize to recognize routes by using Rack::MockRequest" do
|
2267
|
+
mock_app do
|
2268
|
+
get(:mock_sample){}
|
2269
|
+
end
|
2270
|
+
env = Rack::MockRequest.env_for("/mock_sample")
|
2271
|
+
assert_equal :mock_sample, @app.router.recognize(env).first.name
|
2272
|
+
env = Rack::MockRequest.env_for("/invalid")
|
2273
|
+
assert_equal [], @app.router.recognize(env)
|
2274
|
+
end
|
2275
|
+
|
2276
|
+
it "should be able to use params after sending request" do
|
2277
|
+
last_app = mock_app do
|
2278
|
+
get("/foo/:id"){ params.inspect }
|
2279
|
+
end
|
2280
|
+
get "/foo/123"
|
2281
|
+
assert_equal({"id"=>"123"}, Thread.current['padrino.instance'].instance_variable_get(:@params))
|
2282
|
+
end
|
2283
|
+
|
2284
|
+
it "should raise an exception if block arity is not same with captured params size" do
|
2285
|
+
assert_raises(Padrino::Routing::BlockArityError) do
|
2286
|
+
mock_app do
|
2287
|
+
get("/sample/:a/:b") { |a| }
|
2288
|
+
end
|
2289
|
+
end
|
2290
|
+
end
|
2291
|
+
|
2292
|
+
it "should pass format value as a block parameter" do
|
2293
|
+
mock_app do
|
2294
|
+
get "/sample/:a/:b", :provides => :xml do |a, b, format|
|
2295
|
+
"#{a}, #{b}, #{format}"
|
2296
|
+
end
|
2297
|
+
end
|
2298
|
+
get "/sample/foo/bar"
|
2299
|
+
assert_equal "foo, bar, ", body
|
2300
|
+
get "/sample/foo/bar.xml"
|
2301
|
+
assert_equal "foo, bar, xml", body
|
2302
|
+
end
|
2303
|
+
|
2304
|
+
it "should allow negative arity in route block" do
|
2305
|
+
mock_app do
|
2306
|
+
get("/:a/sample/*/*") { |*all| }
|
2307
|
+
end
|
2308
|
+
end
|
2309
|
+
|
2310
|
+
it "should be able to use splat and named captues" do
|
2311
|
+
mock_app do
|
2312
|
+
get("/:a/:b/*/*/*") { |a, b, *splats| "#{a}, #{b}, (#{splats * ","})" }
|
2313
|
+
end
|
2314
|
+
get "/123/456/a/b/c"
|
2315
|
+
assert_equal "123, 456, (a,b,c)", body
|
2316
|
+
end
|
2317
|
+
|
2318
|
+
it "can modify the request" do
|
2319
|
+
mock_app do
|
2320
|
+
get('/foo') { request.path_info = '/bar'; pass }
|
2321
|
+
get('/bar') { 'bar' }
|
2322
|
+
end
|
2323
|
+
|
2324
|
+
get '/foo'
|
2325
|
+
assert ok?
|
2326
|
+
assert_equal 'bar', body
|
2205
2327
|
end
|
2206
2328
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.13.0.beta1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Padrino Team
|
@@ -11,7 +11,7 @@ authors:
|
|
11
11
|
autorequire:
|
12
12
|
bindir: bin
|
13
13
|
cert_chain: []
|
14
|
-
date:
|
14
|
+
date: 2015-02-22 00:00:00.000000000 Z
|
15
15
|
dependencies:
|
16
16
|
- !ruby/object:Gem::Dependency
|
17
17
|
name: padrino-support
|
@@ -19,94 +19,98 @@ dependencies:
|
|
19
19
|
requirements:
|
20
20
|
- - '='
|
21
21
|
- !ruby/object:Gem::Version
|
22
|
-
version: 0.
|
22
|
+
version: 0.13.0.beta1
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
25
|
version_requirements: !ruby/object:Gem::Requirement
|
26
26
|
requirements:
|
27
27
|
- - '='
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: 0.
|
29
|
+
version: 0.13.0.beta1
|
30
30
|
- !ruby/object:Gem::Dependency
|
31
|
-
name:
|
31
|
+
name: rack
|
32
32
|
requirement: !ruby/object:Gem::Requirement
|
33
33
|
requirements:
|
34
|
-
- -
|
34
|
+
- - <
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version:
|
37
|
-
MS40LjY=
|
36
|
+
version: 1.6.0
|
38
37
|
type: :runtime
|
39
38
|
prerelease: false
|
40
39
|
version_requirements: !ruby/object:Gem::Requirement
|
41
40
|
requirements:
|
42
|
-
- -
|
41
|
+
- - <
|
43
42
|
- !ruby/object:Gem::Version
|
44
|
-
version:
|
45
|
-
MS40LjY=
|
43
|
+
version: 1.6.0
|
46
44
|
- !ruby/object:Gem::Dependency
|
47
|
-
name:
|
45
|
+
name: sinatra
|
48
46
|
requirement: !ruby/object:Gem::Requirement
|
49
47
|
requirements:
|
50
48
|
- - ~>
|
51
49
|
- !ruby/object:Gem::Version
|
52
|
-
version:
|
53
|
-
MC4xMS4w
|
50
|
+
version: 1.4.2
|
54
51
|
type: :runtime
|
55
52
|
prerelease: false
|
56
53
|
version_requirements: !ruby/object:Gem::Requirement
|
57
54
|
requirements:
|
58
55
|
- - ~>
|
59
56
|
- !ruby/object:Gem::Version
|
60
|
-
version:
|
61
|
-
|
57
|
+
version: 1.4.2
|
58
|
+
- !ruby/object:Gem::Dependency
|
59
|
+
name: mustermann19
|
60
|
+
requirement: !ruby/object:Gem::Requirement
|
61
|
+
requirements:
|
62
|
+
- - '>='
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
version: '0'
|
65
|
+
type: :runtime
|
66
|
+
prerelease: false
|
67
|
+
version_requirements: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - '>='
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
62
72
|
- !ruby/object:Gem::Dependency
|
63
73
|
name: thor
|
64
74
|
requirement: !ruby/object:Gem::Requirement
|
65
75
|
requirements:
|
66
76
|
- - ~>
|
67
77
|
- !ruby/object:Gem::Version
|
68
|
-
version:
|
69
|
-
MC4xOA==
|
78
|
+
version: '0.18'
|
70
79
|
type: :runtime
|
71
80
|
prerelease: false
|
72
81
|
version_requirements: !ruby/object:Gem::Requirement
|
73
82
|
requirements:
|
74
83
|
- - ~>
|
75
84
|
- !ruby/object:Gem::Version
|
76
|
-
version:
|
77
|
-
MC4xOA==
|
85
|
+
version: '0.18'
|
78
86
|
- !ruby/object:Gem::Dependency
|
79
87
|
name: activesupport
|
80
88
|
requirement: !ruby/object:Gem::Requirement
|
81
89
|
requirements:
|
82
|
-
- -
|
90
|
+
- - '>='
|
83
91
|
- !ruby/object:Gem::Version
|
84
|
-
version:
|
85
|
-
My4x
|
92
|
+
version: '3.1'
|
86
93
|
type: :runtime
|
87
94
|
prerelease: false
|
88
95
|
version_requirements: !ruby/object:Gem::Requirement
|
89
96
|
requirements:
|
90
|
-
- -
|
97
|
+
- - '>='
|
91
98
|
- !ruby/object:Gem::Version
|
92
|
-
version:
|
93
|
-
My4x
|
99
|
+
version: '3.1'
|
94
100
|
- !ruby/object:Gem::Dependency
|
95
101
|
name: rack-protection
|
96
102
|
requirement: !ruby/object:Gem::Requirement
|
97
103
|
requirements:
|
98
|
-
- -
|
104
|
+
- - '>='
|
99
105
|
- !ruby/object:Gem::Version
|
100
|
-
version:
|
101
|
-
MS41LjA=
|
106
|
+
version: 1.5.0
|
102
107
|
type: :runtime
|
103
108
|
prerelease: false
|
104
109
|
version_requirements: !ruby/object:Gem::Requirement
|
105
110
|
requirements:
|
106
|
-
- -
|
111
|
+
- - '>='
|
107
112
|
- !ruby/object:Gem::Version
|
108
|
-
version:
|
109
|
-
MS41LjA=
|
113
|
+
version: 1.5.0
|
110
114
|
description: The Padrino core gem required for use of this framework
|
111
115
|
email: padrinorb@gmail.com
|
112
116
|
executables:
|
@@ -133,14 +137,11 @@ files:
|
|
133
137
|
- lib/padrino-core/caller.rb
|
134
138
|
- lib/padrino-core/cli/adapter.rb
|
135
139
|
- lib/padrino-core/cli/base.rb
|
136
|
-
- lib/padrino-core/cli/binstub.rb
|
137
140
|
- lib/padrino-core/cli/console.rb
|
138
141
|
- lib/padrino-core/cli/launcher.rb
|
139
142
|
- lib/padrino-core/cli/rake.rb
|
140
143
|
- lib/padrino-core/cli/rake_tasks.rb
|
141
144
|
- lib/padrino-core/command.rb
|
142
|
-
- lib/padrino-core/configuration.rb
|
143
|
-
- lib/padrino-core/ext/http_router.rb
|
144
145
|
- lib/padrino-core/ext/sinatra.rb
|
145
146
|
- lib/padrino-core/filter.rb
|
146
147
|
- lib/padrino-core/images/404.png
|
@@ -149,7 +150,11 @@ files:
|
|
149
150
|
- lib/padrino-core/logger.rb
|
150
151
|
- lib/padrino-core/module.rb
|
151
152
|
- lib/padrino-core/mounter.rb
|
152
|
-
- lib/padrino-core/
|
153
|
+
- lib/padrino-core/path_router.rb
|
154
|
+
- lib/padrino-core/path_router/compiler.rb
|
155
|
+
- lib/padrino-core/path_router/error_handler.rb
|
156
|
+
- lib/padrino-core/path_router/matcher.rb
|
157
|
+
- lib/padrino-core/path_router/route.rb
|
153
158
|
- lib/padrino-core/reloader.rb
|
154
159
|
- lib/padrino-core/reloader/rack.rb
|
155
160
|
- lib/padrino-core/reloader/storage.rb
|
@@ -164,8 +169,6 @@ files:
|
|
164
169
|
- test/fixtures/app_gem/lib/app_gem.rb
|
165
170
|
- test/fixtures/app_gem/lib/app_gem/version.rb
|
166
171
|
- test/fixtures/apps/complex.rb
|
167
|
-
- test/fixtures/apps/custom_dependencies/custom_dependencies.rb
|
168
|
-
- test/fixtures/apps/custom_dependencies/my_dependencies/my_dependency.rb
|
169
172
|
- test/fixtures/apps/demo_app.rb
|
170
173
|
- test/fixtures/apps/demo_demo.rb
|
171
174
|
- test/fixtures/apps/demo_project/api/app.rb
|
@@ -175,18 +178,18 @@ files:
|
|
175
178
|
- test/fixtures/apps/external_apps/fake_root.rb
|
176
179
|
- test/fixtures/apps/helpers/class_methods_helpers.rb
|
177
180
|
- test/fixtures/apps/helpers/instance_methods_helpers.rb
|
181
|
+
- test/fixtures/apps/helpers/support.rb
|
178
182
|
- test/fixtures/apps/helpers/system_helpers.rb
|
179
183
|
- test/fixtures/apps/kiq.rb
|
180
184
|
- test/fixtures/apps/lib/myklass.rb
|
181
185
|
- test/fixtures/apps/lib/myklass/mysubklass.rb
|
182
186
|
- test/fixtures/apps/models/child.rb
|
183
187
|
- test/fixtures/apps/models/parent.rb
|
184
|
-
- test/fixtures/apps/rack_apps.rb
|
188
|
+
- test/fixtures/apps/mountable_apps/rack_apps.rb
|
189
|
+
- test/fixtures/apps/mountable_apps/static.html
|
190
|
+
- test/fixtures/apps/precompiled_app.rb
|
185
191
|
- test/fixtures/apps/simple.rb
|
186
|
-
- test/fixtures/apps/static.html
|
187
192
|
- test/fixtures/apps/static.rb
|
188
|
-
- test/fixtures/apps/stealthy/app.rb
|
189
|
-
- test/fixtures/apps/stealthy/helpers/stealthy_class_helpers.rb
|
190
193
|
- test/fixtures/apps/system.rb
|
191
194
|
- test/fixtures/apps/system_class_methods_demo.rb
|
192
195
|
- test/fixtures/apps/system_instance_methods_demo.rb
|
@@ -202,7 +205,6 @@ files:
|
|
202
205
|
- test/fixtures/reloadable_apps/main/app.rb
|
203
206
|
- test/helper.rb
|
204
207
|
- test/test_application.rb
|
205
|
-
- test/test_configuration.rb
|
206
208
|
- test/test_core.rb
|
207
209
|
- test/test_csrf_protection.rb
|
208
210
|
- test/test_dependencies.rb
|
@@ -215,7 +217,6 @@ files:
|
|
215
217
|
- test/test_reloader_complex.rb
|
216
218
|
- test/test_reloader_external.rb
|
217
219
|
- test/test_reloader_simple.rb
|
218
|
-
- test/test_reloader_storage.rb
|
219
220
|
- test/test_reloader_system.rb
|
220
221
|
- test/test_restful_routing.rb
|
221
222
|
- test/test_router.rb
|
@@ -231,18 +232,77 @@ require_paths:
|
|
231
232
|
- lib
|
232
233
|
required_ruby_version: !ruby/object:Gem::Requirement
|
233
234
|
requirements:
|
234
|
-
- -
|
235
|
+
- - '>='
|
235
236
|
- !ruby/object:Gem::Version
|
236
237
|
version: '0'
|
237
238
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
238
239
|
requirements:
|
239
|
-
- -
|
240
|
+
- - '>'
|
240
241
|
- !ruby/object:Gem::Version
|
241
|
-
version: 1.3.
|
242
|
+
version: 1.3.1
|
242
243
|
requirements: []
|
243
244
|
rubyforge_project: padrino-core
|
244
|
-
rubygems_version: 2.6
|
245
|
+
rubygems_version: 2.0.6
|
245
246
|
signing_key:
|
246
247
|
specification_version: 4
|
247
248
|
summary: The required Padrino core gem
|
248
|
-
test_files:
|
249
|
+
test_files:
|
250
|
+
- test/fixtures/app_gem/Gemfile
|
251
|
+
- test/fixtures/app_gem/app/app.rb
|
252
|
+
- test/fixtures/app_gem/app_gem.gemspec
|
253
|
+
- test/fixtures/app_gem/lib/app_gem.rb
|
254
|
+
- test/fixtures/app_gem/lib/app_gem/version.rb
|
255
|
+
- test/fixtures/apps/complex.rb
|
256
|
+
- test/fixtures/apps/demo_app.rb
|
257
|
+
- test/fixtures/apps/demo_demo.rb
|
258
|
+
- test/fixtures/apps/demo_project/api/app.rb
|
259
|
+
- test/fixtures/apps/demo_project/api/lib/api_lib.rb
|
260
|
+
- test/fixtures/apps/demo_project/app.rb
|
261
|
+
- test/fixtures/apps/external_apps/fake_lib.rb
|
262
|
+
- test/fixtures/apps/external_apps/fake_root.rb
|
263
|
+
- test/fixtures/apps/helpers/class_methods_helpers.rb
|
264
|
+
- test/fixtures/apps/helpers/instance_methods_helpers.rb
|
265
|
+
- test/fixtures/apps/helpers/support.rb
|
266
|
+
- test/fixtures/apps/helpers/system_helpers.rb
|
267
|
+
- test/fixtures/apps/kiq.rb
|
268
|
+
- test/fixtures/apps/lib/myklass.rb
|
269
|
+
- test/fixtures/apps/lib/myklass/mysubklass.rb
|
270
|
+
- test/fixtures/apps/models/child.rb
|
271
|
+
- test/fixtures/apps/models/parent.rb
|
272
|
+
- test/fixtures/apps/mountable_apps/rack_apps.rb
|
273
|
+
- test/fixtures/apps/mountable_apps/static.html
|
274
|
+
- test/fixtures/apps/precompiled_app.rb
|
275
|
+
- test/fixtures/apps/simple.rb
|
276
|
+
- test/fixtures/apps/static.rb
|
277
|
+
- test/fixtures/apps/system.rb
|
278
|
+
- test/fixtures/apps/system_class_methods_demo.rb
|
279
|
+
- test/fixtures/apps/system_instance_methods_demo.rb
|
280
|
+
- test/fixtures/dependencies/a.rb
|
281
|
+
- test/fixtures/dependencies/b.rb
|
282
|
+
- test/fixtures/dependencies/c.rb
|
283
|
+
- test/fixtures/dependencies/circular/e.rb
|
284
|
+
- test/fixtures/dependencies/circular/f.rb
|
285
|
+
- test/fixtures/dependencies/circular/g.rb
|
286
|
+
- test/fixtures/dependencies/d.rb
|
287
|
+
- test/fixtures/reloadable_apps/external/app/app.rb
|
288
|
+
- test/fixtures/reloadable_apps/external/app/controllers/base.rb
|
289
|
+
- test/fixtures/reloadable_apps/main/app.rb
|
290
|
+
- test/helper.rb
|
291
|
+
- test/test_application.rb
|
292
|
+
- test/test_core.rb
|
293
|
+
- test/test_csrf_protection.rb
|
294
|
+
- test/test_dependencies.rb
|
295
|
+
- test/test_filters.rb
|
296
|
+
- test/test_flash.rb
|
297
|
+
- test/test_locale.rb
|
298
|
+
- test/test_logger.rb
|
299
|
+
- test/test_mounter.rb
|
300
|
+
- test/test_params_protection.rb
|
301
|
+
- test/test_reloader_complex.rb
|
302
|
+
- test/test_reloader_external.rb
|
303
|
+
- test/test_reloader_simple.rb
|
304
|
+
- test/test_reloader_system.rb
|
305
|
+
- test/test_restful_routing.rb
|
306
|
+
- test/test_router.rb
|
307
|
+
- test/test_routing.rb
|
308
|
+
has_rdoc:
|