padrino-core 0.9.15 → 0.9.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/lib/padrino-core/application/routing.rb +130 -23
- data/lib/padrino-core/version.rb +2 -2
- data/padrino-core.gemspec +3 -9
- data/test/test_routing.rb +163 -2
- data/test/tmp/cache/%2Ffoo +2 -0
- metadata +26 -11
data/.gitignore
CHANGED
@@ -15,19 +15,30 @@ module Padrino
|
|
15
15
|
class ::HttpRouter #:nodoc:
|
16
16
|
attr_accessor :runner
|
17
17
|
class Route #:nodoc:
|
18
|
-
|
18
|
+
attr_reader :before_filters, :after_filters
|
19
|
+
attr_accessor :custom_conditions, :use_layout, :controller, :cache
|
19
20
|
|
20
|
-
def
|
21
|
-
|
21
|
+
def add_before_filter(filter)
|
22
|
+
@before_filters ||= []
|
23
|
+
@before_filters << filter
|
24
|
+
arbitrary { |env| catch(:pass) { router.runner.instance_eval(&filter); true } == true }
|
22
25
|
end
|
23
26
|
|
24
|
-
def
|
25
|
-
|
26
|
-
@
|
27
|
+
def add_after_filter(filter)
|
28
|
+
@after_filters ||= []
|
29
|
+
@after_filters << filter
|
30
|
+
end
|
31
|
+
|
32
|
+
def before_filters=(filters)
|
33
|
+
filters.each { |filter| add_before_filter(filter) } if filters
|
34
|
+
end
|
35
|
+
|
36
|
+
def after_filters=(filters)
|
37
|
+
filters.each { |filter| add_after_filter(filter) } if filters
|
27
38
|
end
|
28
39
|
|
29
40
|
def custom_conditions=(custom_conditions)
|
30
|
-
|
41
|
+
custom_conditions.each { |blk| arbitrary { |env| router.runner.instance_eval(&blk) != false } } if custom_conditions
|
31
42
|
@custom_conditions = custom_conditions
|
32
43
|
end
|
33
44
|
end
|
@@ -49,7 +60,25 @@ module Padrino
|
|
49
60
|
|
50
61
|
class UnrecognizedException < RuntimeError #:nodoc:
|
51
62
|
end
|
52
|
-
|
63
|
+
|
64
|
+
##
|
65
|
+
# Keeps information about parent scope.
|
66
|
+
#
|
67
|
+
class Parent < String
|
68
|
+
attr_reader :map
|
69
|
+
attr_reader :optional
|
70
|
+
attr_reader :options
|
71
|
+
|
72
|
+
alias_method :optional?, :optional
|
73
|
+
|
74
|
+
def initialize(value, options={})
|
75
|
+
super(value.to_s)
|
76
|
+
@map = options.delete(:map)
|
77
|
+
@optional = options.delete(:optional)
|
78
|
+
@options = options
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
53
82
|
##
|
54
83
|
# Main class that register this extension
|
55
84
|
#
|
@@ -131,6 +160,8 @@ module Padrino
|
|
131
160
|
@_controller, original_controller = args, @_controller
|
132
161
|
@_parents, original_parent = options.delete(:parent), @_parents
|
133
162
|
@_provides, original_provides = options.delete(:provides), @_provides
|
163
|
+
@_cache, original_cache = options.delete(:cache), @_cache
|
164
|
+
@_map, original_map = options.delete(:map), @_map
|
134
165
|
@_defaults, original_defaults = options, @_defaults
|
135
166
|
|
136
167
|
# Application defaults
|
@@ -146,14 +177,40 @@ module Padrino
|
|
146
177
|
@layout = original_layout
|
147
178
|
|
148
179
|
# Controller defaults
|
149
|
-
@_controller, @_parents = original_controller, original_parent
|
150
|
-
@_defaults, @_provides = original_defaults, original_provides
|
180
|
+
@_controller, @_parents, @_cache = original_controller, original_parent, original_cache
|
181
|
+
@_defaults, @_provides, @_map = original_defaults, original_provides, original_map
|
151
182
|
else
|
152
183
|
include(*args) if extensions.any?
|
153
184
|
end
|
154
185
|
end
|
155
186
|
alias :controllers :controller
|
156
187
|
|
188
|
+
##
|
189
|
+
# Provides many parents with shallowing.
|
190
|
+
#
|
191
|
+
# ==== Examples
|
192
|
+
#
|
193
|
+
# controllers :product do
|
194
|
+
# parent :shop, :optional => true, :map => "/my/stand"
|
195
|
+
# parent :category, :optional => true
|
196
|
+
# get :show, :with => :id do
|
197
|
+
# # generated urls:
|
198
|
+
# # "/product/show/#{params[:id]}"
|
199
|
+
# # "/my/stand/#{params[:shop_id]}/product/show/#{params[:id]}"
|
200
|
+
# # "/my/stand/#{params[:shop_id]}/category/#{params[:category_id]}/product/show/#{params[:id]}"
|
201
|
+
# # url_for(:product, :show, :id => 10) => "/product/show/10"
|
202
|
+
# # url_for(:product, :show, :shop_id => 5, :id => 10) => "/my/stand/5/product/show/10"
|
203
|
+
# # url_for(:product, :show, :shop_id => 5, :category_id => 1, :id => 10) => "/my/stand/5/category/1/product/show/10"
|
204
|
+
# end
|
205
|
+
# end
|
206
|
+
#
|
207
|
+
def parent(name, options={})
|
208
|
+
defaults = { :optional => false, :map => name.to_s }
|
209
|
+
options = defaults.merge(options)
|
210
|
+
@_parents = Array(@_parents) unless @_parents.is_a?(Array)
|
211
|
+
@_parents << Parent.new(name, options)
|
212
|
+
end
|
213
|
+
|
157
214
|
##
|
158
215
|
# Using HTTPRouter, for features and configurations see: http://github.com/joshbuddy/http_router
|
159
216
|
#
|
@@ -201,6 +258,19 @@ module Padrino
|
|
201
258
|
end
|
202
259
|
alias :url_for :url
|
203
260
|
|
261
|
+
def get(path, *args, &block)
|
262
|
+
conditions = @conditions.dup
|
263
|
+
route('GET', path, *args, &block)
|
264
|
+
|
265
|
+
@conditions = conditions
|
266
|
+
route('HEAD', path, *args, &block)
|
267
|
+
end
|
268
|
+
|
269
|
+
def put(path, *args, &bk); route 'PUT', path, *args, &bk end
|
270
|
+
def post(path, *args, &bk); route 'POST', path, *args, &bk end
|
271
|
+
def delete(path, *args, &bk); route 'DELETE', path, *args, &bk end
|
272
|
+
def head(path, *args, &bk); route 'HEAD', path, *args, &bk end
|
273
|
+
|
204
274
|
private
|
205
275
|
|
206
276
|
# Add prefix slash if its not present and remove trailing slashes.
|
@@ -214,22 +284,43 @@ module Padrino
|
|
214
284
|
# ==== Examples
|
215
285
|
#
|
216
286
|
# get :index # => "/"
|
287
|
+
# get :index, "/" # => "/"
|
217
288
|
# get :index, :map => "/" # => "/"
|
289
|
+
# get :show, "/show-me" # => "/show-me"
|
218
290
|
# get :show, :map => "/show-me" # => "/show-me"
|
219
291
|
# get "/foo/bar" # => "/show"
|
220
292
|
# get :index, :parent => :user # => "/user/:user_id/index"
|
221
293
|
# get :show, :with => :id, :parent => :user # => "/user/:user_id/show/:id"
|
222
294
|
# get :show, :with => :id # => "/show/:id"
|
295
|
+
# get [:show, :id] # => "/show/:id"
|
223
296
|
# get :show, :with => [:id, :name] # => "/show/:id/:name"
|
297
|
+
# get [:show, :id, :name] # => "/show/:id/:name"
|
224
298
|
# get :list, :provides => :js # => "/list.{:format,js)"
|
225
299
|
# get :list, :provides => :any # => "/list(.:format)"
|
226
300
|
# get :list, :provides => [:js, :json] # => "/list.{!format,js|json}"
|
227
301
|
# get :list, :provides => [:html, :js, :json] # => "/list(.{!format,js|json})"
|
228
302
|
#
|
229
|
-
def route(verb, path,
|
303
|
+
def route(verb, path, *args, &block)
|
304
|
+
options = case args.size
|
305
|
+
when 2
|
306
|
+
args.last.merge(:map => args.first)
|
307
|
+
when 1
|
308
|
+
map = args.shift if args.first.is_a?(String)
|
309
|
+
if args.first.is_a?(Hash)
|
310
|
+
map ? args.first.merge(:map => map) : args.first
|
311
|
+
else
|
312
|
+
{:map => map || args.first}
|
313
|
+
end
|
314
|
+
when 0
|
315
|
+
{}
|
316
|
+
else
|
317
|
+
raise
|
318
|
+
end
|
319
|
+
|
230
320
|
# Do padrino parsing. We dup options so we can build HEAD request correctly
|
231
321
|
route_options = options.dup
|
232
322
|
route_options[:provides] = @_provides if @_provides
|
323
|
+
path, *route_options[:with] = path if path.is_a?(Array)
|
233
324
|
path, name, options = *parse_route(path, route_options, verb)
|
234
325
|
|
235
326
|
# Sinatra defaults
|
@@ -245,23 +336,30 @@ module Padrino
|
|
245
336
|
|
246
337
|
# HTTPRouter route construction
|
247
338
|
route = case path
|
248
|
-
when Regexp
|
249
|
-
|
250
|
-
else
|
251
|
-
router.add(path)
|
339
|
+
when Regexp then router.add('/?*').match_path(path)
|
340
|
+
else router.add(path)
|
252
341
|
end
|
253
342
|
|
254
343
|
route.name(name) if name
|
344
|
+
route.cache = options.key?(:cache) ? options.delete(:cache) : @_cache
|
255
345
|
route.send(verb.downcase.to_sym)
|
256
346
|
route.host(options.delete(:host)) if options.key?(:host)
|
257
347
|
route.condition(:user_agent => options.delete(:agent)) if options.key?(:agent)
|
258
348
|
route.default_values = options.delete(:default_values)
|
349
|
+
options.delete_if do |option, args|
|
350
|
+
if route.send(:significant_variable_names).include?(option)
|
351
|
+
route.matching(option => Array(args).first)
|
352
|
+
true
|
353
|
+
end
|
354
|
+
end
|
259
355
|
|
260
356
|
# Add Sinatra conditions
|
261
357
|
options.each { |option, args| send(option, *args) }
|
262
358
|
conditions, @conditions = @conditions, []
|
263
359
|
route.custom_conditions = conditions
|
264
360
|
|
361
|
+
invoke_hook(:padrino_route_added, route, verb, path, args, options, block)
|
362
|
+
|
265
363
|
# Add Application defaults
|
266
364
|
if @_controller
|
267
365
|
route.before_filters = @before_filters
|
@@ -274,7 +372,6 @@ module Padrino
|
|
274
372
|
end
|
275
373
|
|
276
374
|
route.to(block)
|
277
|
-
|
278
375
|
route
|
279
376
|
end
|
280
377
|
|
@@ -336,10 +433,14 @@ module Padrino
|
|
336
433
|
path = process_path_for_parent_params(path, parent_params)
|
337
434
|
end
|
338
435
|
|
436
|
+
# Add any controller level map to the front of the path
|
437
|
+
path = "#{@_map}/#{path}".squeeze('/') unless @_map.blank?
|
438
|
+
|
339
439
|
# Small reformats
|
340
440
|
path.gsub!(%r{/?index/?}, '') # Remove index path
|
341
|
-
path[0,0] = "/"
|
342
|
-
path.sub!(%r{
|
441
|
+
path[0,0] = "/" unless path =~ %r{^\(?/} # Paths must start with a /
|
442
|
+
path.sub!(%r{/(\))?$}, '\\1') if path != "/" # Remove latest trailing delimiter
|
443
|
+
path.gsub!(/\/(\(\.|$)/, '\\1') # Remove trailing slashes
|
343
444
|
end
|
344
445
|
|
345
446
|
# Merge in option defaults
|
@@ -361,8 +462,13 @@ module Padrino
|
|
361
462
|
# Used for calculating path in route method
|
362
463
|
#
|
363
464
|
def process_path_for_parent_params(path, parent_params)
|
364
|
-
parent_prefix = parent_params.flatten.uniq.collect
|
365
|
-
|
465
|
+
parent_prefix = parent_params.flatten.compact.uniq.collect do |param|
|
466
|
+
map = (param.respond_to?(:map) && param.map ? param.map : param.to_s)
|
467
|
+
part = "#{map}/:#{param}_id/"
|
468
|
+
part = "(#{part})" if param.respond_to?(:optional) && param.optional?
|
469
|
+
part
|
470
|
+
end
|
471
|
+
[parent_prefix, path].flatten.join("")
|
366
472
|
end
|
367
473
|
|
368
474
|
##
|
@@ -485,10 +591,11 @@ module Padrino
|
|
485
591
|
# Now we can eval route, but because we have "throw halt" we need to be
|
486
592
|
# (en)sure to reset old layout and run controller after filters.
|
487
593
|
begin
|
488
|
-
route_eval(&match.destination)
|
594
|
+
@_response_buffer = catch(:halt) { route_eval(&match.destination) }
|
595
|
+
throw :halt, @_response_buffer
|
489
596
|
ensure
|
490
597
|
base.instance_variable_set(:@layout, parent_layout) if match.path.route.use_layout
|
491
|
-
match.path.route.after_filters.each { |aft| throw :pass if instance_eval(&aft) == false }
|
598
|
+
match.path.route.after_filters.each { |aft| throw :pass if instance_eval(&aft) == false } if match.path.route.after_filters
|
492
599
|
end
|
493
600
|
end
|
494
601
|
end
|
@@ -506,4 +613,4 @@ module Padrino
|
|
506
613
|
end
|
507
614
|
end # InstanceMethods
|
508
615
|
end # Routing
|
509
|
-
end # Padrino
|
616
|
+
end # Padrino
|
data/lib/padrino-core/version.rb
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
# without include full padrino core.
|
6
6
|
#
|
7
7
|
module Padrino
|
8
|
-
VERSION = '0.9.
|
8
|
+
VERSION = '0.9.16' unless defined?(Padrino::VERSION)
|
9
9
|
##
|
10
10
|
# Return the current Padrino version
|
11
11
|
#
|
12
12
|
def self.version
|
13
13
|
VERSION
|
14
14
|
end
|
15
|
-
end # Padrino
|
15
|
+
end # Padrino
|
data/padrino-core.gemspec
CHANGED
@@ -18,14 +18,8 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.rdoc_options = ["--charset=UTF-8"]
|
19
19
|
s.require_path = "lib"
|
20
20
|
s.add_dependency("sinatra", ">= 1.0.0")
|
21
|
-
s.add_dependency("http_router", ">= 0.3.
|
21
|
+
s.add_dependency("http_router", ">= 0.3.16")
|
22
22
|
s.add_dependency("thor", ">= 0.13.0")
|
23
|
-
|
24
|
-
|
25
|
-
if ENV['AS'] == "edge"
|
26
|
-
s.add_dependency("activesupport", ">= 3.0.0.beta4")
|
27
|
-
s.add_dependency("tzinfo")
|
28
|
-
else
|
29
|
-
s.add_dependency("activesupport", ">= 2.3.8")
|
30
|
-
end
|
23
|
+
s.add_dependency("activesupport", ">= 3.0.0")
|
24
|
+
s.add_dependency("tzinfo")
|
31
25
|
end
|
data/test/test_routing.rb
CHANGED
@@ -77,6 +77,16 @@ class TestRouting < Test::Unit::TestCase
|
|
77
77
|
assert_equal "hello IE", body
|
78
78
|
end
|
79
79
|
|
80
|
+
should "use regex for parts of a route" do
|
81
|
+
app = mock_app do
|
82
|
+
get("/main/:id", :id => /\d+/){ "hello #{params[:id]}" }
|
83
|
+
end
|
84
|
+
get "/main/123"
|
85
|
+
assert_equal "hello 123", body
|
86
|
+
get "/main/asd"
|
87
|
+
assert_equal 404, status
|
88
|
+
end
|
89
|
+
|
80
90
|
should "not generate overlapping head urls" do
|
81
91
|
app = mock_app do
|
82
92
|
get("/main"){ "hello" }
|
@@ -92,10 +102,15 @@ class TestRouting < Test::Unit::TestCase
|
|
92
102
|
mock_app do
|
93
103
|
get(:foo){ "/foo" }
|
94
104
|
get(:foo, :with => :id){ |id| "/foo/#{id}" }
|
105
|
+
get([:foo, :id]){ |id| "/foo/#{id}" }
|
95
106
|
get(:hash, :with => :id){ url(:hash, :id => 1) }
|
107
|
+
get([:hash, :id]){ url(:hash, :id => 1) }
|
96
108
|
get(:array, :with => :id){ url(:array, 23) }
|
109
|
+
get([:array, :id]){ url(:array, 23) }
|
97
110
|
get(:hash_with_extra, :with => :id){ url(:hash_with_extra, :id => 1, :query => 'string') }
|
111
|
+
get([:hash_with_extra, :id]){ url(:hash_with_extra, :id => 1, :query => 'string') }
|
98
112
|
get(:array_with_extra, :with => :id){ url(:array_with_extra, 23, :query => 'string') }
|
113
|
+
get([:array_with_extra, :id]){ url(:array_with_extra, 23, :query => 'string') }
|
99
114
|
get("/old-bar/:id"){ params[:id] }
|
100
115
|
post(:mix, :map => "/mix-bar/:id"){ params[:id] }
|
101
116
|
get(:mix, :map => "/mix-bar/:id"){ params[:id] }
|
@@ -240,7 +255,7 @@ class TestRouting < Test::Unit::TestCase
|
|
240
255
|
assert_equal "bar", body
|
241
256
|
assert_equal "/bar", @app.url(:bar)
|
242
257
|
end
|
243
|
-
|
258
|
+
|
244
259
|
should 'remove index from path' do
|
245
260
|
mock_app do
|
246
261
|
get(:index){ "index" }
|
@@ -481,6 +496,7 @@ class TestRouting < Test::Unit::TestCase
|
|
481
496
|
get(:index, :map => "/"){ "index" }
|
482
497
|
get(:show, :with => :id, :map => "/show"){ "show #{params[:id]}" }
|
483
498
|
get(:edit, :map => "/edit/:id/product"){ "edit #{params[:id]}" }
|
499
|
+
get(:wacky, :map => "/wacky-:id-:product_id"){ "wacky #{params[:id]}-#{params[:product_id]}" }
|
484
500
|
end
|
485
501
|
end
|
486
502
|
get "/"
|
@@ -489,6 +505,18 @@ class TestRouting < Test::Unit::TestCase
|
|
489
505
|
assert_equal "show 1", body
|
490
506
|
get "/edit/1/product"
|
491
507
|
assert_equal "edit 1", body
|
508
|
+
get "/wacky-1-2"
|
509
|
+
assert_equal "wacky 1-2", body
|
510
|
+
end
|
511
|
+
|
512
|
+
should 'apply maps when given path is kind of hash' do
|
513
|
+
mock_app do
|
514
|
+
controllers :admin do
|
515
|
+
get(:foobar, "/foo/bar"){ "foobar" }
|
516
|
+
end
|
517
|
+
end
|
518
|
+
get "/foo/bar"
|
519
|
+
assert_equal "foobar", body
|
492
520
|
end
|
493
521
|
|
494
522
|
should "apply parent to route" do
|
@@ -534,6 +562,62 @@ class TestRouting < Test::Unit::TestCase
|
|
534
562
|
assert_equal "show 3 1 2", body
|
535
563
|
assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3)
|
536
564
|
end
|
565
|
+
|
566
|
+
should "apply parent with shallowing to controller" do
|
567
|
+
mock_app do
|
568
|
+
controller :project do
|
569
|
+
parent :user
|
570
|
+
parent :shop, :optional => true
|
571
|
+
get(:index) { "index #{params[:user_id]} #{params[:shop_id]}" }
|
572
|
+
get(:edit, :with => :id) { "edit #{params[:id]} #{params[:user_id]} #{params[:shop_id]}" }
|
573
|
+
get(:show, :with => :id, :parent => :product) { "show #{params[:id]} #{params[:user_id]} #{params[:product_id]} #{params[:shop_id]}" }
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
577
|
+
user_project_url = "/user/1/project"
|
578
|
+
get user_project_url
|
579
|
+
assert_equal "index 1 ", body
|
580
|
+
assert_equal user_project_url, @app.url(:project, :index, :user_id => 1)
|
581
|
+
|
582
|
+
user_project_edit_url = "/user/1/project/edit/2"
|
583
|
+
get user_project_edit_url
|
584
|
+
assert_equal "edit 2 1 ", body
|
585
|
+
assert_equal user_project_edit_url, @app.url(:project, :edit, :user_id => 1, :id => 2)
|
586
|
+
|
587
|
+
user_product_project_url = "/user/1/product/2/project/show/3"
|
588
|
+
get user_product_project_url
|
589
|
+
assert_equal "show 3 1 2 ", body
|
590
|
+
assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3)
|
591
|
+
|
592
|
+
user_project_url = "/user/1/shop/1/project"
|
593
|
+
get user_project_url
|
594
|
+
assert_equal "index 1 1", body
|
595
|
+
assert_equal user_project_url, @app.url(:project, :index, :user_id => 1, :shop_id => 1)
|
596
|
+
|
597
|
+
user_project_edit_url = "/user/1/shop/1/project/edit/2"
|
598
|
+
get user_project_edit_url
|
599
|
+
assert_equal "edit 2 1 1", body
|
600
|
+
assert_equal user_project_edit_url, @app.url(:project, :edit, :user_id => 1, :id => 2, :shop_id => 1)
|
601
|
+
|
602
|
+
user_product_project_url = "/user/1/shop/1/product/2/project/show/3"
|
603
|
+
get user_product_project_url
|
604
|
+
assert_equal "show 3 1 2 1", body
|
605
|
+
assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3, :shop_id => 1)
|
606
|
+
end
|
607
|
+
|
608
|
+
should "respect map in parents with shallowing" do
|
609
|
+
mock_app do
|
610
|
+
controller :project do
|
611
|
+
parent :shop, :map => "/foo/bar"
|
612
|
+
get(:index) { "index #{params[:shop_id]}" }
|
613
|
+
end
|
614
|
+
end
|
615
|
+
|
616
|
+
shop_project_url = "/foo/bar/1/project"
|
617
|
+
get shop_project_url
|
618
|
+
assert_equal "index 1", body
|
619
|
+
assert_equal shop_project_url, @app.url(:project, :index, :shop_id => 1)
|
620
|
+
end
|
537
621
|
|
538
622
|
should "use default values" do
|
539
623
|
mock_app do
|
@@ -703,6 +787,52 @@ class TestRouting < Test::Unit::TestCase
|
|
703
787
|
assert_equal "hey", body
|
704
788
|
end
|
705
789
|
|
790
|
+
should "allow concise routing" do
|
791
|
+
mock_app do
|
792
|
+
get :index, ":id" do
|
793
|
+
params[:id]
|
794
|
+
end
|
795
|
+
|
796
|
+
get :map, "route/:id" do
|
797
|
+
params[:id]
|
798
|
+
end
|
799
|
+
end
|
800
|
+
|
801
|
+
get "/123"
|
802
|
+
assert_equal "123", body
|
803
|
+
|
804
|
+
get "/route/123"
|
805
|
+
assert_equal "123", body
|
806
|
+
end
|
807
|
+
|
808
|
+
should "allow passing & halting in before filters" do
|
809
|
+
mock_app do
|
810
|
+
controller do
|
811
|
+
before { env['QUERY_STRING'] == 'secret' or pass }
|
812
|
+
get :index do
|
813
|
+
"secret index"
|
814
|
+
end
|
815
|
+
end
|
816
|
+
|
817
|
+
controller do
|
818
|
+
before { env['QUERY_STRING'] == 'halt' and halt 401, 'go away!' }
|
819
|
+
get :index do
|
820
|
+
"index"
|
821
|
+
end
|
822
|
+
end
|
823
|
+
end
|
824
|
+
|
825
|
+
get "/?secret"
|
826
|
+
assert_equal "secret index", body
|
827
|
+
|
828
|
+
get "/?halt"
|
829
|
+
assert_equal "go away!", body
|
830
|
+
assert_equal 401, status
|
831
|
+
|
832
|
+
get "/"
|
833
|
+
assert_equal "index", body
|
834
|
+
end
|
835
|
+
|
706
836
|
should 'scope filters in the given controller' do
|
707
837
|
mock_app do
|
708
838
|
before { @global = 'global' }
|
@@ -821,6 +951,26 @@ class TestRouting < Test::Unit::TestCase
|
|
821
951
|
assert_equal 404, status
|
822
952
|
end
|
823
953
|
|
954
|
+
should "allow controller level mapping" do
|
955
|
+
mock_app do
|
956
|
+
controller :map => "controller-:id" do
|
957
|
+
get(:url3) { "#{params[:id]}" }
|
958
|
+
get(:url4, :map => 'test-:id2') { "#{params[:id]}, #{params[:id2]}" }
|
959
|
+
end
|
960
|
+
end
|
961
|
+
|
962
|
+
url = @app.url(:url3, :id => 1)
|
963
|
+
assert_equal "/controller-1/url3", url
|
964
|
+
get url
|
965
|
+
assert_equal "1", body
|
966
|
+
|
967
|
+
url = @app.url(:url4, 1, 2)
|
968
|
+
assert_equal "/controller-1/test-2", url
|
969
|
+
get url
|
970
|
+
assert_equal "1, 2", body
|
971
|
+
end
|
972
|
+
|
973
|
+
|
824
974
|
should "work with params and parent options" do
|
825
975
|
mock_app do
|
826
976
|
controller :test2, :parent => :parent1, :parent1_id => 1 do
|
@@ -871,13 +1021,24 @@ class TestRouting < Test::Unit::TestCase
|
|
871
1021
|
end
|
872
1022
|
get "/foo"
|
873
1023
|
assert_equal "this is foo", body
|
874
|
-
# TODO fix this in http_router, should pass
|
875
1024
|
get "/foo/"
|
876
1025
|
assert_equal "this is foo", body
|
877
1026
|
get '/foo/5/10'
|
878
1027
|
assert_equal "/foo/5/10", body
|
879
1028
|
end
|
880
1029
|
|
1030
|
+
should "index routes should be optional when nested" do
|
1031
|
+
mock_app do
|
1032
|
+
controller '/users', :provides => [:json] do
|
1033
|
+
get '/' do
|
1034
|
+
"foo"
|
1035
|
+
end
|
1036
|
+
end
|
1037
|
+
end
|
1038
|
+
get "/users.json"
|
1039
|
+
assert_equal "foo", body
|
1040
|
+
end
|
1041
|
+
|
881
1042
|
should "parse params with class level provides" do
|
882
1043
|
mock_app do
|
883
1044
|
controllers :posts, :provides => [:html, :js] do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: padrino-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 27
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 9
|
9
|
-
-
|
10
|
-
version: 0.9.
|
9
|
+
- 16
|
10
|
+
version: 0.9.16
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Padrino Team
|
@@ -18,7 +18,7 @@ autorequire:
|
|
18
18
|
bindir: bin
|
19
19
|
cert_chain: []
|
20
20
|
|
21
|
-
date: 2010-
|
21
|
+
date: 2010-09-24 00:00:00 +02:00
|
22
22
|
default_executable: padrino
|
23
23
|
dependencies:
|
24
24
|
- !ruby/object:Gem::Dependency
|
@@ -45,12 +45,12 @@ dependencies:
|
|
45
45
|
requirements:
|
46
46
|
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
|
-
hash:
|
48
|
+
hash: 51
|
49
49
|
segments:
|
50
50
|
- 0
|
51
51
|
- 3
|
52
|
-
-
|
53
|
-
version: 0.3.
|
52
|
+
- 16
|
53
|
+
version: 0.3.16
|
54
54
|
type: :runtime
|
55
55
|
version_requirements: *id002
|
56
56
|
- !ruby/object:Gem::Dependency
|
@@ -77,14 +77,28 @@ dependencies:
|
|
77
77
|
requirements:
|
78
78
|
- - ">="
|
79
79
|
- !ruby/object:Gem::Version
|
80
|
-
hash:
|
80
|
+
hash: 7
|
81
81
|
segments:
|
82
|
-
- 2
|
83
82
|
- 3
|
84
|
-
-
|
85
|
-
|
83
|
+
- 0
|
84
|
+
- 0
|
85
|
+
version: 3.0.0
|
86
86
|
type: :runtime
|
87
87
|
version_requirements: *id004
|
88
|
+
- !ruby/object:Gem::Dependency
|
89
|
+
name: tzinfo
|
90
|
+
prerelease: false
|
91
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
92
|
+
none: false
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
hash: 3
|
97
|
+
segments:
|
98
|
+
- 0
|
99
|
+
version: "0"
|
100
|
+
type: :runtime
|
101
|
+
version_requirements: *id005
|
88
102
|
description: The Padrino core gem required for use of this framework
|
89
103
|
email: padrinorb@gmail.com
|
90
104
|
executables:
|
@@ -154,6 +168,7 @@ files:
|
|
154
168
|
- test/test_router.rb
|
155
169
|
- test/test_routing.rb
|
156
170
|
- test/test_server.rb
|
171
|
+
- test/tmp/cache/%2Ffoo
|
157
172
|
has_rdoc: true
|
158
173
|
homepage: http://www.padrinorb.com
|
159
174
|
licenses: []
|