padrino-core 0.9.9 → 0.9.10
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +16 -16
- data/Rakefile +3 -13
- data/bin/padrino +11 -4
- data/lib/padrino-core/application/mounter.rb +29 -13
- data/lib/padrino-core/application/rendering.rb +60 -16
- data/lib/padrino-core/application/routing.rb +178 -74
- data/lib/padrino-core/application.rb +18 -17
- data/lib/padrino-core/cli/rake.rb +27 -1
- data/lib/padrino-core/loader.rb +1 -0
- data/lib/padrino-core/locale/da.yml +30 -0
- data/lib/padrino-core/locale/fr.yml +30 -0
- data/lib/padrino-core/locale/pt_br.yml +37 -0
- data/lib/padrino-core/locale/ru.yml +30 -0
- data/lib/padrino-core/logger.rb +49 -4
- data/lib/padrino-core/router.rb +77 -0
- data/lib/padrino-core/support_lite.rb +32 -2
- data/lib/padrino-core/version.rb +3 -2
- data/lib/padrino-core.rb +4 -4
- data/padrino-core.gemspec +8 -3
- data/test/fixtures/apps/simple.rb +1 -1
- data/test/test_application.rb +1 -1
- data/test/test_core.rb +0 -1
- data/test/test_reloader_simple.rb +4 -2
- data/test/test_rendering.rb +36 -11
- data/test/test_router.rb +144 -0
- data/test/test_routing.rb +163 -19
- metadata +9 -4
- data/VERSION +0 -1
data/test/test_routing.rb
CHANGED
@@ -71,10 +71,10 @@ class TestRouting < Test::Unit::TestCase
|
|
71
71
|
|
72
72
|
should 'generate url with format' do
|
73
73
|
mock_app do
|
74
|
-
get(:a, :
|
75
|
-
get(:b, :
|
76
|
-
get(:c, :
|
77
|
-
get(:d, :
|
74
|
+
get(:a, :provides => :any){ url(:a, :format => :json) }
|
75
|
+
get(:b, :provides => :js){ url(:b, :format => :js) }
|
76
|
+
get(:c, :provides => [:js, :json]){ url(:c, :format => :json) }
|
77
|
+
get(:d, :provides => [:html, :js]){ url(:d, :format => :js, :foo => :bar) }
|
78
78
|
end
|
79
79
|
get "/a.js"
|
80
80
|
assert_equal "/a.json", body
|
@@ -98,7 +98,7 @@ class TestRouting < Test::Unit::TestCase
|
|
98
98
|
|
99
99
|
should "generate routes for format simple" do
|
100
100
|
mock_app do
|
101
|
-
get(:foo, :
|
101
|
+
get(:foo, :provides => [:html, :rss]) { render :haml, "Test" }
|
102
102
|
end
|
103
103
|
get "/foo"
|
104
104
|
assert_equal "Test\n", body
|
@@ -109,8 +109,8 @@ class TestRouting < Test::Unit::TestCase
|
|
109
109
|
should "generate routes for format with controller" do
|
110
110
|
mock_app do
|
111
111
|
controller :posts do
|
112
|
-
get(:index, :
|
113
|
-
get(:show, :with => :id, :
|
112
|
+
get(:index, :provides => [:html, :rss, :atom, :js]) { render :haml, "Index.#{content_type}" }
|
113
|
+
get(:show, :with => :id, :provides => [:html, :rss, :atom]) { render :haml, "Show.#{content_type}" }
|
114
114
|
end
|
115
115
|
end
|
116
116
|
get "/posts"
|
@@ -150,6 +150,15 @@ class TestRouting < Test::Unit::TestCase
|
|
150
150
|
assert_equal "accounts", body
|
151
151
|
end
|
152
152
|
|
153
|
+
should 'remove index from path with params' do
|
154
|
+
mock_app do
|
155
|
+
get(:index, :with => :name){ "index with #{params[:name]}" }
|
156
|
+
end
|
157
|
+
get "/bobby"
|
158
|
+
assert_equal "index with bobby", body
|
159
|
+
assert_equal "/john", @app.url(:index, :name => "john")
|
160
|
+
end
|
161
|
+
|
153
162
|
should 'parse named params' do
|
154
163
|
mock_app do
|
155
164
|
get(:print, :with => :id){ "Im #{params[:id]}" }
|
@@ -161,10 +170,10 @@ class TestRouting < Test::Unit::TestCase
|
|
161
170
|
|
162
171
|
should 'respond to' do
|
163
172
|
mock_app do
|
164
|
-
get(:a, :
|
165
|
-
get(:b, :
|
166
|
-
get(:c, :
|
167
|
-
get(:d, :
|
173
|
+
get(:a, :provides => :js){ "js" }
|
174
|
+
get(:b, :provides => :any){ "any" }
|
175
|
+
get(:c, :provides => [:js, :json]){ "js,json" }
|
176
|
+
get(:d, :provides => [:html, :js]){ "html,js"}
|
168
177
|
end
|
169
178
|
get "/a"
|
170
179
|
assert_equal 404, status
|
@@ -172,27 +181,23 @@ class TestRouting < Test::Unit::TestCase
|
|
172
181
|
assert_equal "js", body
|
173
182
|
get "/b"
|
174
183
|
assert_equal "any", body
|
175
|
-
get "/b.foo"
|
176
|
-
assert_equal "any", body
|
184
|
+
assert_raise(RuntimeError) { get "/b.foo" }
|
177
185
|
get "/c"
|
178
186
|
assert_equal 404, status
|
179
|
-
get "/c.fo"
|
180
|
-
assert_equal 404, status
|
181
187
|
get "/c.js"
|
182
188
|
assert_equal "js,json", body
|
183
189
|
get "/c.json"
|
184
190
|
assert_equal "js,json", body
|
185
191
|
get "/d"
|
186
192
|
assert_equal "html,js", body
|
187
|
-
get "/d.fo"
|
188
|
-
assert_equal 404, status
|
189
193
|
get "/d.js"
|
190
194
|
assert_equal "html,js", body
|
191
195
|
end
|
192
196
|
|
193
197
|
should 'respond_to and set content_type' do
|
198
|
+
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
194
199
|
mock_app do
|
195
|
-
get :a, :
|
200
|
+
get :a, :provides => :any do
|
196
201
|
case content_type
|
197
202
|
when :js then "js"
|
198
203
|
when :json then "json"
|
@@ -209,7 +214,7 @@ class TestRouting < Test::Unit::TestCase
|
|
209
214
|
assert_equal 'application/json;charset=utf-8', response["Content-Type"]
|
210
215
|
get "/a.foo"
|
211
216
|
assert_equal "foo", body
|
212
|
-
assert_equal 'application/
|
217
|
+
assert_equal 'application/foo;charset=utf-8', response["Content-Type"]
|
213
218
|
get "/a"
|
214
219
|
assert_equal "html", body
|
215
220
|
assert_equal 'text/html;charset=utf-8', response["Content-Type"]
|
@@ -326,4 +331,143 @@ class TestRouting < Test::Unit::TestCase
|
|
326
331
|
assert_equal "show 3 1 2", body
|
327
332
|
end
|
328
333
|
|
334
|
+
should "use default values" do
|
335
|
+
mock_app do
|
336
|
+
controller :lang => :it do
|
337
|
+
get(:index, :map => "/:lang") { "lang is #{params[:lang]}" }
|
338
|
+
end
|
339
|
+
assert_equal "/it", url(:index)
|
340
|
+
# This is only for be sure that default values
|
341
|
+
# work only for the given controller
|
342
|
+
get(:foo, :map => "/foo") {}
|
343
|
+
assert_equal "/foo", url(:foo)
|
344
|
+
end
|
345
|
+
get "/en"
|
346
|
+
assert_equal "lang is en", body
|
347
|
+
end
|
348
|
+
|
349
|
+
should "transitions to the next matching route on pass" do
|
350
|
+
mock_app do
|
351
|
+
get '/:foo' do
|
352
|
+
pass
|
353
|
+
'Hello Foo'
|
354
|
+
end
|
355
|
+
get '/:bar' do
|
356
|
+
'Hello World'
|
357
|
+
end
|
358
|
+
end
|
359
|
+
|
360
|
+
get '/za'
|
361
|
+
assert_equal 'Hello World', body
|
362
|
+
end
|
363
|
+
|
364
|
+
should "filters by accept header" do
|
365
|
+
mock_app do
|
366
|
+
get '/foo', :provides => [:xml, :js] do
|
367
|
+
request.env['HTTP_ACCEPT']
|
368
|
+
end
|
369
|
+
end
|
370
|
+
|
371
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
372
|
+
assert ok?
|
373
|
+
assert_equal 'application/xml', body
|
374
|
+
assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']
|
375
|
+
|
376
|
+
get '/foo.xml'
|
377
|
+
assert ok?
|
378
|
+
assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']
|
379
|
+
|
380
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/javascript' }
|
381
|
+
assert ok?
|
382
|
+
assert_equal 'application/javascript', body
|
383
|
+
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
|
384
|
+
|
385
|
+
get '/foo.js'
|
386
|
+
assert ok?
|
387
|
+
assert_equal 'application/javascript;charset=utf-8', response.headers['Content-Type']
|
388
|
+
|
389
|
+
get '/foo', {}, { :accept => 'text/html' }
|
390
|
+
assert not_found?
|
391
|
+
end
|
392
|
+
|
393
|
+
should "works allow global provides" do
|
394
|
+
mock_app do
|
395
|
+
provides :xml
|
396
|
+
|
397
|
+
get("/foo"){ "Foo in #{content_type}" }
|
398
|
+
get("/bar"){ "Bar in #{content_type}" }
|
399
|
+
end
|
400
|
+
|
401
|
+
get '/foo', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
402
|
+
assert_equal 'Foo in xml', body
|
403
|
+
get '/foo'
|
404
|
+
assert not_found?
|
405
|
+
|
406
|
+
get '/bar', {}, { 'HTTP_ACCEPT' => 'application/xml' }
|
407
|
+
assert_equal 'Bar in html', body
|
408
|
+
end
|
409
|
+
|
410
|
+
should 'allows custom route-conditions to be set via route options' do
|
411
|
+
protector = Module.new {
|
412
|
+
def protect(*args)
|
413
|
+
condition {
|
414
|
+
unless authorize(params["user"], params["password"])
|
415
|
+
halt 403, "go away"
|
416
|
+
end
|
417
|
+
}
|
418
|
+
end
|
419
|
+
}
|
420
|
+
|
421
|
+
mock_app do
|
422
|
+
register protector
|
423
|
+
|
424
|
+
helpers do
|
425
|
+
def authorize(username, password)
|
426
|
+
username == "foo" && password == "bar"
|
427
|
+
end
|
428
|
+
end
|
429
|
+
|
430
|
+
get "/", :protect => true do
|
431
|
+
"hey"
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
435
|
+
get "/"
|
436
|
+
assert forbidden?
|
437
|
+
assert_equal "go away", body
|
438
|
+
|
439
|
+
get "/", :user => "foo", :password => "bar"
|
440
|
+
assert ok?
|
441
|
+
assert_equal "hey", body
|
442
|
+
end
|
443
|
+
|
444
|
+
should 'scope filters in the given controller' do
|
445
|
+
mock_app do
|
446
|
+
before { @global = 'global' }
|
447
|
+
after { @global = nil }
|
448
|
+
|
449
|
+
controller :foo do
|
450
|
+
before { @foo = :foo }
|
451
|
+
after { @foo = nil }
|
452
|
+
get("/") { [@foo, @bar, @global].compact.join(" ") }
|
453
|
+
end
|
454
|
+
|
455
|
+
get("/") { [@foo, @bar, @global].compact.join(" ") }
|
456
|
+
|
457
|
+
controller :bar do
|
458
|
+
before { @bar = :bar }
|
459
|
+
after { @bar = nil }
|
460
|
+
get("/") { [@foo, @bar, @global].compact.join(" ") }
|
461
|
+
end
|
462
|
+
end
|
463
|
+
|
464
|
+
get "/bar"
|
465
|
+
assert_equal "bar global", body
|
466
|
+
|
467
|
+
get "/foo"
|
468
|
+
assert_equal "foo global", body
|
469
|
+
|
470
|
+
get "/"
|
471
|
+
assert_equal "global", body
|
472
|
+
end
|
329
473
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 9
|
8
|
-
-
|
9
|
-
version: 0.9.
|
8
|
+
- 10
|
9
|
+
version: 0.9.10
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Padrino Team
|
@@ -17,7 +17,7 @@ autorequire:
|
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
19
|
|
20
|
-
date: 2010-
|
20
|
+
date: 2010-04-22 00:00:00 +02:00
|
21
21
|
default_executable: padrino
|
22
22
|
dependencies:
|
23
23
|
- !ruby/object:Gem::Dependency
|
@@ -188,7 +188,6 @@ files:
|
|
188
188
|
- LICENSE
|
189
189
|
- README.rdoc
|
190
190
|
- Rakefile
|
191
|
-
- VERSION
|
192
191
|
- bin/padrino
|
193
192
|
- lib/padrino-core.rb
|
194
193
|
- lib/padrino-core/application.rb
|
@@ -204,11 +203,16 @@ files:
|
|
204
203
|
- lib/padrino-core/images/404.png
|
205
204
|
- lib/padrino-core/images/500.png
|
206
205
|
- lib/padrino-core/loader.rb
|
206
|
+
- lib/padrino-core/locale/da.yml
|
207
207
|
- lib/padrino-core/locale/de.yml
|
208
208
|
- lib/padrino-core/locale/en.yml
|
209
|
+
- lib/padrino-core/locale/fr.yml
|
209
210
|
- lib/padrino-core/locale/it.yml
|
211
|
+
- lib/padrino-core/locale/pt_br.yml
|
212
|
+
- lib/padrino-core/locale/ru.yml
|
210
213
|
- lib/padrino-core/logger.rb
|
211
214
|
- lib/padrino-core/reloader.rb
|
215
|
+
- lib/padrino-core/router.rb
|
212
216
|
- lib/padrino-core/server.rb
|
213
217
|
- lib/padrino-core/support_lite.rb
|
214
218
|
- lib/padrino-core/tasks.rb
|
@@ -230,6 +234,7 @@ files:
|
|
230
234
|
- test/test_reloader_complex.rb
|
231
235
|
- test/test_reloader_simple.rb
|
232
236
|
- test/test_rendering.rb
|
237
|
+
- test/test_router.rb
|
233
238
|
- test/test_routing.rb
|
234
239
|
- test/test_server.rb
|
235
240
|
has_rdoc: true
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.9.9
|