padrino-core 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/padrino-core.rb +4 -4
- data/lib/padrino-core/application.rb +6 -195
- data/lib/padrino-core/application/application_setup.rb +199 -0
- data/lib/padrino-core/application/routing.rb +66 -25
- data/lib/padrino-core/cli/base.rb +8 -5
- data/lib/padrino-core/cli/rake.rb +12 -9
- data/lib/padrino-core/loader.rb +1 -1
- data/lib/padrino-core/logger.rb +25 -0
- data/lib/padrino-core/mounter.rb +8 -3
- data/lib/padrino-core/reloader.rb +2 -2
- data/lib/padrino-core/server.rb +50 -17
- data/lib/padrino-core/version.rb +1 -1
- data/padrino-core.gemspec +2 -10
- data/test/fixtures/apps/demo_app.rb +7 -0
- data/test/fixtures/apps/demo_demo.rb +7 -0
- data/test/helper.rb +6 -37
- data/test/test_application.rb +12 -13
- data/test/test_core.rb +12 -13
- data/test/test_csrf_protection.rb +49 -23
- data/test/test_dependencies.rb +7 -7
- data/test/test_filters.rb +41 -17
- data/test/test_flash.rb +24 -24
- data/test/test_locale.rb +1 -1
- data/test/test_logger.rb +39 -27
- data/test/test_mounter.rb +34 -20
- data/test/test_reloader_complex.rb +5 -6
- data/test/test_reloader_simple.rb +23 -20
- data/test/test_reloader_system.rb +10 -7
- data/test/test_restful_routing.rb +1 -1
- data/test/test_router.rb +7 -7
- data/test/test_routing.rb +177 -141
- metadata +14 -53
- data/lib/padrino-core/application/rendering.rb +0 -325
- data/lib/padrino-core/application/rendering/extensions/erubis.rb +0 -68
- data/lib/padrino-core/application/rendering/extensions/haml.rb +0 -29
- data/lib/padrino-core/application/rendering/extensions/slim.rb +0 -21
- data/lib/padrino-core/locale/cs.yml +0 -33
- data/lib/padrino-core/locale/da.yml +0 -33
- data/lib/padrino-core/locale/de.yml +0 -33
- data/lib/padrino-core/locale/en.yml +0 -33
- data/lib/padrino-core/locale/es.yml +0 -33
- data/lib/padrino-core/locale/fr.yml +0 -33
- data/lib/padrino-core/locale/hu.yml +0 -33
- data/lib/padrino-core/locale/it.yml +0 -39
- data/lib/padrino-core/locale/ja.yml +0 -33
- data/lib/padrino-core/locale/lv.yml +0 -33
- data/lib/padrino-core/locale/nl.yml +0 -33
- data/lib/padrino-core/locale/no.yml +0 -33
- data/lib/padrino-core/locale/pl.yml +0 -33
- data/lib/padrino-core/locale/pt_br.yml +0 -39
- data/lib/padrino-core/locale/ro.yml +0 -33
- data/lib/padrino-core/locale/ru.yml +0 -34
- data/lib/padrino-core/locale/sv.yml +0 -33
- data/lib/padrino-core/locale/tr.yml +0 -33
- data/lib/padrino-core/locale/uk.yml +0 -33
- data/lib/padrino-core/locale/zh_cn.yml +0 -33
- data/lib/padrino-core/locale/zh_tw.yml +0 -33
- data/lib/padrino-core/support_lite.rb +0 -259
- data/test/fixtures/apps/.components +0 -6
- data/test/fixtures/apps/.gitignore +0 -7
- data/test/fixtures/apps/render.rb +0 -13
- data/test/fixtures/apps/views/blog/post.erb +0 -1
- data/test/fixtures/layouts/layout.erb +0 -1
- data/test/mini_shoulda.rb +0 -45
- data/test/test_rendering.rb +0 -606
- data/test/test_rendering_extensions.rb +0 -14
- data/test/test_support_lite.rb +0 -56
data/test/test_mounter.rb
CHANGED
@@ -12,8 +12,8 @@ describe "Mounter" do
|
|
12
12
|
$VERBOSE = @_verbose_was
|
13
13
|
end
|
14
14
|
|
15
|
-
|
16
|
-
should
|
15
|
+
describe 'for mounter functionality' do
|
16
|
+
it 'should check methods' do
|
17
17
|
mounter = Padrino::Mounter.new("test_app", :app_file => "/path/to/test.rb")
|
18
18
|
mounter.to("/test_app")
|
19
19
|
assert_kind_of Padrino::Mounter, mounter
|
@@ -27,14 +27,14 @@ describe "Mounter" do
|
|
27
27
|
assert_equal Padrino.root, mounter.app_root
|
28
28
|
end
|
29
29
|
|
30
|
-
should
|
30
|
+
it 'should use app.root if available' do
|
31
31
|
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/kiq')
|
32
32
|
mounter = Padrino::Mounter.new("kiq", :app_class => "Kiq")
|
33
33
|
mounter.to("/test_app")
|
34
34
|
assert_equal '/weird', mounter.app_root
|
35
35
|
end
|
36
36
|
|
37
|
-
should
|
37
|
+
it 'should check locate_app_file with __FILE__' do
|
38
38
|
mounter = Padrino::Mounter.new("test_app", :app_file => __FILE__)
|
39
39
|
mounter.to("/test_app")
|
40
40
|
assert_equal "test_app", mounter.name
|
@@ -44,14 +44,14 @@ describe "Mounter" do
|
|
44
44
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
45
45
|
end
|
46
46
|
|
47
|
-
should
|
47
|
+
it 'should mount an app' do
|
48
48
|
class ::AnApp < Padrino::Application; end
|
49
49
|
Padrino.mount("an_app").to("/")
|
50
50
|
assert_equal AnApp, Padrino.mounted_apps.first.app_obj
|
51
51
|
assert_equal ["an_app"], Padrino.mounted_apps.map(&:name)
|
52
52
|
end
|
53
53
|
|
54
|
-
should
|
54
|
+
it 'should correctly mount an app in a namespace' do
|
55
55
|
module ::SomeNamespace
|
56
56
|
class AnApp < Padrino::Application; end
|
57
57
|
end
|
@@ -60,7 +60,7 @@ describe "Mounter" do
|
|
60
60
|
assert_equal ["some_namespace/an_app"], Padrino.mounted_apps.map(&:name)
|
61
61
|
end
|
62
62
|
|
63
|
-
should
|
63
|
+
it 'should correctly set a name of a namespaced app' do
|
64
64
|
module ::SomeNamespace2
|
65
65
|
class AnApp < Padrino::Application
|
66
66
|
get(:index) { settings.app_name }
|
@@ -71,7 +71,7 @@ describe "Mounter" do
|
|
71
71
|
assert_equal "some_namespace2/an_app", res.body
|
72
72
|
end
|
73
73
|
|
74
|
-
should
|
74
|
+
it 'should mount a primary app to root uri' do
|
75
75
|
mounter = Padrino.mount("test_app", :app_file => __FILE__).to("/")
|
76
76
|
assert_equal "test_app", mounter.name
|
77
77
|
assert_equal "TestApp", mounter.app_class
|
@@ -81,7 +81,7 @@ describe "Mounter" do
|
|
81
81
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
82
82
|
end
|
83
83
|
|
84
|
-
should
|
84
|
+
it 'should mount a primary app to sub_uri' do
|
85
85
|
mounter = Padrino.mount("test_app", :app_file => __FILE__).to('/me')
|
86
86
|
assert_equal "test_app", mounter.name
|
87
87
|
assert_equal "TestApp", mounter.app_class
|
@@ -91,18 +91,18 @@ describe "Mounter" do
|
|
91
91
|
assert_equal File.dirname(mounter.app_file), mounter.app_root
|
92
92
|
end
|
93
93
|
|
94
|
-
should
|
94
|
+
it 'should raise error when app has no located file' do
|
95
95
|
# TODO enabling this screws minitest
|
96
96
|
# assert_raises(Padrino::Mounter::MounterException) { Padrino.mount("tester_app").to('/test') }
|
97
97
|
assert_equal 0, Padrino.mounted_apps.size
|
98
98
|
end
|
99
99
|
|
100
|
-
should
|
100
|
+
it 'should raise error when app has no located object' do
|
101
101
|
assert_raises(Padrino::Mounter::MounterException) { Padrino.mount("tester_app", :app_file => "/path/to/file.rb").to('/test') }
|
102
102
|
assert_equal 0, Padrino.mounted_apps.size
|
103
103
|
end
|
104
104
|
|
105
|
-
should
|
105
|
+
it 'should mount multiple apps' do
|
106
106
|
class ::OneApp < Padrino::Application; end
|
107
107
|
class ::TwoApp < Padrino::Application; end
|
108
108
|
|
@@ -118,7 +118,16 @@ describe "Mounter" do
|
|
118
118
|
assert_equal ["one_app", "two_app"], Padrino.mounted_apps.map(&:name)
|
119
119
|
end
|
120
120
|
|
121
|
-
|
121
|
+
it 'should mount app with the same name as the module' do
|
122
|
+
Padrino.mount("Demo::App", :app_file => File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_app.rb')).to("/app")
|
123
|
+
Padrino.mount("Demo::Demo", :app_file => File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/demo_demo.rb')).to("/")
|
124
|
+
|
125
|
+
Padrino.mounted_apps.each do |app|
|
126
|
+
assert_equal app.app_obj.setup_application!, true
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should change mounted_root' do
|
122
131
|
Padrino.mounted_root = "fixtures"
|
123
132
|
assert_equal Padrino.root("fixtures", "test", "app.rb"), Padrino.mounted_root("test", "app.rb")
|
124
133
|
Padrino.mounted_root = "apps"
|
@@ -127,7 +136,7 @@ describe "Mounter" do
|
|
127
136
|
assert_equal Padrino.root("test", "app.rb"), Padrino.mounted_root("test", "app.rb")
|
128
137
|
end
|
129
138
|
|
130
|
-
should
|
139
|
+
it 'should be able to access routes data for mounted apps' do
|
131
140
|
class ::OneApp < Padrino::Application
|
132
141
|
get("/test") { "test" }
|
133
142
|
get(:index, :provides => [:js, :json]) { "index" }
|
@@ -155,15 +164,18 @@ describe "Mounter" do
|
|
155
164
|
put(:update) { "foo bar update" }
|
156
165
|
delete(:destroy) { "foo bar delete" }
|
157
166
|
end
|
167
|
+
controllers :test, :nested do
|
168
|
+
get(:test1){ "test1" }
|
169
|
+
end
|
158
170
|
end
|
159
171
|
|
160
172
|
Padrino.mount("one_app").to("/")
|
161
173
|
Padrino.mount("two_app").to("/two_app")
|
162
174
|
|
163
175
|
assert_equal 15, Padrino.mounted_apps[0].routes.size
|
164
|
-
assert_equal
|
176
|
+
assert_equal 16, Padrino.mounted_apps[1].routes.size
|
165
177
|
assert_equal 6, Padrino.mounted_apps[0].named_routes.size
|
166
|
-
assert_equal
|
178
|
+
assert_equal 11, Padrino.mounted_apps[1].named_routes.size
|
167
179
|
|
168
180
|
first_route = Padrino.mounted_apps[0].named_routes[3]
|
169
181
|
assert_equal "posts show", first_route.identifier.to_s
|
@@ -181,9 +193,11 @@ describe "Mounter" do
|
|
181
193
|
assert_equal "/\\/foo|\\/baz/", regexp_route.path
|
182
194
|
foo_bar_route = Padrino.mounted_apps[1].named_routes[5]
|
183
195
|
assert_equal "(:foo_bar, :index)", foo_bar_route.name
|
196
|
+
nested_route = Padrino.mounted_apps[1].named_routes[10]
|
197
|
+
assert_equal "(:test_nested, :test1)", nested_route.name
|
184
198
|
end
|
185
199
|
|
186
|
-
should
|
200
|
+
it 'should configure cascade apps' do
|
187
201
|
class ::App1 < Padrino::Application
|
188
202
|
get(:index) { halt 404, 'index1' }
|
189
203
|
end
|
@@ -200,7 +214,7 @@ describe "Mounter" do
|
|
200
214
|
assert_equal 'index2', res.body
|
201
215
|
end
|
202
216
|
|
203
|
-
should
|
217
|
+
it 'should correctly instantiate a new padrino application' do
|
204
218
|
mock_app do
|
205
219
|
get("/demo_1"){ "Im Demo 1" }
|
206
220
|
get("/demo_2"){ "Im Demo 2" }
|
@@ -212,7 +226,7 @@ describe "Mounter" do
|
|
212
226
|
assert_equal "Im Demo 2", response.body
|
213
227
|
end
|
214
228
|
|
215
|
-
should
|
229
|
+
it 'should not clobber the public setting when mounting an app' do
|
216
230
|
class ::PublicApp < Padrino::Application
|
217
231
|
set :root, "/root"
|
218
232
|
set :public_folder, File.expand_path(File.dirname(__FILE__))
|
@@ -224,7 +238,7 @@ describe "Mounter" do
|
|
224
238
|
assert_equal File.read(__FILE__), res.body
|
225
239
|
end
|
226
240
|
|
227
|
-
should
|
241
|
+
it 'should load apps from gems' do
|
228
242
|
spec_file = Padrino.root("fixtures", "app_gem", "app_gem.gemspec")
|
229
243
|
spec = Gem::Specification.load(spec_file)
|
230
244
|
spec.activate
|
@@ -3,14 +3,14 @@ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/complex')
|
|
3
3
|
|
4
4
|
describe "ComplexReloader" do
|
5
5
|
|
6
|
-
|
7
|
-
|
6
|
+
describe 'for complex reload functionality' do
|
7
|
+
before do
|
8
8
|
Padrino.clear!
|
9
9
|
Padrino.mount("complex_1_demo").to("/complex_1_demo")
|
10
10
|
Padrino.mount("complex_2_demo").to("/complex_2_demo")
|
11
11
|
end
|
12
12
|
|
13
|
-
should
|
13
|
+
it 'should correctly instantiate Complex(1-2)Demo fixture' do
|
14
14
|
assert_equal ["/complex_1_demo", "/complex_2_demo"], Padrino.mounted_apps.map(&:uri_root)
|
15
15
|
assert_equal ["complex_1_demo", "complex_2_demo"], Padrino.mounted_apps.map(&:name)
|
16
16
|
assert Complex1Demo.reload?
|
@@ -19,7 +19,7 @@ describe "ComplexReloader" do
|
|
19
19
|
assert_match %r{fixtures/apps/complex.rb}, Complex2Demo.app_file
|
20
20
|
end
|
21
21
|
|
22
|
-
should
|
22
|
+
it 'should correctly reload Complex(1-2)Demo fixture' do
|
23
23
|
assert_match %r{fixtures/apps/complex.rb}, Complex1Demo.app_file
|
24
24
|
@app = Padrino.application
|
25
25
|
|
@@ -47,8 +47,7 @@ describe "ComplexReloader" do
|
|
47
47
|
new_buffer.gsub!(/get\(:destroy\)/, 'get(:destroy, :with => :id)')
|
48
48
|
begin
|
49
49
|
File.open(Complex1Demo.app_file, "w") { |f| f.write(new_buffer) }
|
50
|
-
|
51
|
-
get "/complex_2_demo"
|
50
|
+
Time.stub(:now, Time.now + 2) { get "/complex_2_demo" }
|
52
51
|
assert_equal new_phrase, body
|
53
52
|
|
54
53
|
# Re-Check that we didn't forget any route
|
@@ -3,9 +3,9 @@ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/simple')
|
|
3
3
|
|
4
4
|
describe "SimpleReloader" do
|
5
5
|
|
6
|
-
|
6
|
+
describe 'for simple reset functionality' do
|
7
7
|
|
8
|
-
should
|
8
|
+
it 'should reset routes' do
|
9
9
|
mock_app do
|
10
10
|
(1..10).each do |i|
|
11
11
|
get("/#{i}") { "Foo #{i}" }
|
@@ -22,7 +22,7 @@ describe "SimpleReloader" do
|
|
22
22
|
end
|
23
23
|
end
|
24
24
|
|
25
|
-
should
|
25
|
+
it 'should keep sinatra routes on development' do
|
26
26
|
mock_app do
|
27
27
|
set :environment, :development
|
28
28
|
get("/"){ "ok" }
|
@@ -42,36 +42,39 @@ describe "SimpleReloader" do
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
|
46
|
-
|
47
|
-
should 'correctly instantiate SimpleDemo fixture' do
|
45
|
+
describe 'for simple reload functionality' do
|
46
|
+
before do
|
48
47
|
Padrino.clear!
|
49
48
|
Padrino.mount("simple_demo").to("/")
|
49
|
+
Padrino.reload!
|
50
|
+
end
|
51
|
+
|
52
|
+
it 'should correctly instantiate SimpleDemo fixture' do
|
50
53
|
assert_equal ["simple_demo"], Padrino.mounted_apps.map(&:name)
|
51
54
|
assert SimpleDemo.reload?
|
52
55
|
assert_match %r{fixtures/apps/simple.rb}, SimpleDemo.app_file
|
53
56
|
end
|
54
57
|
|
55
|
-
|
56
|
-
# TODO fix this test
|
58
|
+
it 'should correctly reload SimpleDemo fixture' do
|
57
59
|
@app = SimpleDemo
|
58
60
|
get "/"
|
59
61
|
assert ok?
|
60
62
|
new_phrase = "The magick number is: #{rand(2**255)}!"
|
61
63
|
buffer = File.read(SimpleDemo.app_file)
|
62
64
|
new_buffer = buffer.gsub(/The magick number is: \d+!/, new_phrase)
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
begin
|
66
|
+
File.open(SimpleDemo.app_file, "w") { |f| f.write(new_buffer) }
|
67
|
+
Time.stub(:now, Time.now + 2) { get "/" }
|
68
|
+
assert_equal new_phrase, body
|
69
|
+
ensure
|
70
|
+
File.open(SimpleDemo.app_file, "w") { |f| f.write(buffer) }
|
71
|
+
Padrino.reload!
|
72
|
+
end
|
71
73
|
end
|
72
74
|
|
73
|
-
should
|
75
|
+
it 'should correctly reset SimpleDemo fixture' do
|
74
76
|
@app = SimpleDemo
|
77
|
+
get "/"
|
75
78
|
@app.reload!
|
76
79
|
get "/rand"
|
77
80
|
assert ok?
|
@@ -81,17 +84,17 @@ describe "SimpleReloader" do
|
|
81
84
|
assert_equal 2, @app.filters[:after].size # app + content-type + padrino-flash
|
82
85
|
assert_equal 0, @app.middleware.size
|
83
86
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" + GET+HEAD of "/rand" = 4
|
84
|
-
assert_equal 3, @app.extensions.size # [Padrino::
|
87
|
+
assert_equal 3, @app.extensions.size # [Padrino::ApplicationSetup, Padrino::Routing, Padrino::Flash]
|
85
88
|
assert_equal 0, @app.templates.size
|
86
89
|
@app.reload!
|
87
90
|
get "/rand"
|
88
|
-
|
91
|
+
refute_equal last_body, body
|
89
92
|
assert_equal 2, @app.filters[:before].size # one is ours the other is default_filter for content type
|
90
93
|
assert_equal 1, @app.errors.size
|
91
94
|
assert_equal 2, @app.filters[:after].size
|
92
95
|
assert_equal 0, @app.middleware.size
|
93
96
|
assert_equal 4, @app.routes.size # GET+HEAD of "/" = 2
|
94
|
-
assert_equal 3, @app.extensions.size # [Padrino::
|
97
|
+
assert_equal 3, @app.extensions.size # [Padrino::ApplicationSetup, Padrino::Routing, Padrino::Flash]
|
95
98
|
assert_equal 0, @app.templates.size
|
96
99
|
end
|
97
100
|
end
|
@@ -4,16 +4,19 @@ require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/system')
|
|
4
4
|
require File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/static')
|
5
5
|
|
6
6
|
describe "SystemReloader" do
|
7
|
-
|
8
|
-
|
7
|
+
describe 'for wierd and difficult reload events' do
|
8
|
+
before do
|
9
9
|
@app = SystemDemo
|
10
|
+
get '/'
|
11
|
+
end
|
12
|
+
|
13
|
+
it 'should reload system features if they were required only in helper' do
|
10
14
|
@app.reload!
|
11
15
|
get '/'
|
12
16
|
assert_equal 'Resolv', body
|
13
17
|
end
|
14
18
|
|
15
|
-
should
|
16
|
-
@app = SystemDemo
|
19
|
+
it 'should reload children on parent change' do
|
17
20
|
assert_equal Child.new.family, 'Danes'
|
18
21
|
parent_file = File.expand_path(File.dirname(__FILE__) + '/fixtures/apps/models/parent.rb')
|
19
22
|
new_class = <<-DOC
|
@@ -42,7 +45,7 @@ describe "SystemReloader" do
|
|
42
45
|
end
|
43
46
|
end
|
44
47
|
|
45
|
-
should
|
48
|
+
it 'should tamper with LOAD_PATH' do
|
46
49
|
SystemDemo.load_paths.each do |lib_dir|
|
47
50
|
assert_includes $LOAD_PATH, lib_dir
|
48
51
|
end
|
@@ -51,12 +54,12 @@ describe "SystemReloader" do
|
|
51
54
|
end
|
52
55
|
end
|
53
56
|
|
54
|
-
should
|
57
|
+
it 'should not fail horribly on reload event with non-padrino apps' do
|
55
58
|
Padrino.mount("kiq").to("/")
|
56
59
|
Padrino.reload!
|
57
60
|
end
|
58
61
|
|
59
|
-
should
|
62
|
+
it 'should not reload apps with disabled reload' do
|
60
63
|
Padrino.mount(StaticDemo).to("/")
|
61
64
|
Padrino.reload!
|
62
65
|
end
|
data/test/test_router.rb
CHANGED
@@ -7,7 +7,7 @@ describe "Router" do
|
|
7
7
|
Padrino.clear!
|
8
8
|
end
|
9
9
|
|
10
|
-
should
|
10
|
+
it 'should dispatch paths correctly' do
|
11
11
|
app = lambda { |env|
|
12
12
|
[200, {
|
13
13
|
'X-ScriptName' => env['SCRIPT_NAME'],
|
@@ -69,7 +69,7 @@ describe "Router" do
|
|
69
69
|
assert_equal "/", res["X-PathInfo"]
|
70
70
|
end
|
71
71
|
|
72
|
-
should
|
72
|
+
it 'should dispatch requests to cascade mounted apps' do
|
73
73
|
app = lambda { |env|
|
74
74
|
scary = !!env['PATH_INFO'].match(/scary/)
|
75
75
|
[scary ? 404 : 200, {
|
@@ -120,7 +120,7 @@ describe "Router" do
|
|
120
120
|
assert_equal "/scary", res["X-PathInfo"]
|
121
121
|
end
|
122
122
|
|
123
|
-
should
|
123
|
+
it 'should dispatch requests to cascade mounted apps and not cascade ok statuses' do
|
124
124
|
|
125
125
|
api = mock_app do
|
126
126
|
get 'scary' do
|
@@ -158,7 +158,7 @@ describe "Router" do
|
|
158
158
|
|
159
159
|
end
|
160
160
|
|
161
|
-
should
|
161
|
+
it 'should dispatch requests to cascade mounted apps until it sees a cascade == false or []g' do
|
162
162
|
app = mock_app do
|
163
163
|
get 'scary' do
|
164
164
|
""
|
@@ -188,7 +188,7 @@ describe "Router" do
|
|
188
188
|
assert request_case.call.ok?
|
189
189
|
end
|
190
190
|
|
191
|
-
should
|
191
|
+
it 'should dispatches hosts correctly' do
|
192
192
|
map = Padrino::Router.new(
|
193
193
|
{ :host => "foo.org", :to => lambda { |env|
|
194
194
|
[200,
|
@@ -226,7 +226,7 @@ describe "Router" do
|
|
226
226
|
assert_equal "subdomain.foo.org", res["X-Position"]
|
227
227
|
end
|
228
228
|
|
229
|
-
should
|
229
|
+
it 'should works with padrino core applications' do
|
230
230
|
Padrino.mount("simple_demo").host("padrino.org")
|
231
231
|
assert_equal ["simple_demo"], Padrino.mounted_apps.map(&:name)
|
232
232
|
assert_equal ["padrino.org"], Padrino.mounted_apps.map(&:app_host)
|
@@ -241,7 +241,7 @@ describe "Router" do
|
|
241
241
|
assert res.ok?
|
242
242
|
end
|
243
243
|
|
244
|
-
should
|
244
|
+
it 'should works with padrino applications' do
|
245
245
|
Padrino.mount("simple_demo").to("/foo").host(/.*\.padrino.org/)
|
246
246
|
|
247
247
|
res = Rack::MockRequest.new(Padrino.application).get("/")
|
data/test/test_routing.rb
CHANGED
@@ -5,12 +5,11 @@ class FooError < RuntimeError; end
|
|
5
5
|
|
6
6
|
|
7
7
|
describe "Routing" do
|
8
|
-
|
9
|
-
Padrino
|
10
|
-
Padrino::Rendering::DEFAULT_RENDERING_OPTIONS[:strict_format] = false
|
8
|
+
before do
|
9
|
+
Padrino.clear!
|
11
10
|
end
|
12
11
|
|
13
|
-
should
|
12
|
+
it 'should serve static files with simple cache control' do
|
14
13
|
mock_app do
|
15
14
|
set :static_cache_control, :public
|
16
15
|
set :public_folder, File.dirname(__FILE__)
|
@@ -20,7 +19,7 @@ describe "Routing" do
|
|
20
19
|
assert_equal headers['Cache-Control'], 'public'
|
21
20
|
end # static simple
|
22
21
|
|
23
|
-
should
|
22
|
+
it 'should serve static files with cache control and max_age' do
|
24
23
|
mock_app do
|
25
24
|
set :static_cache_control, [:public, :must_revalidate, {:max_age => 300}]
|
26
25
|
set :public_folder, File.dirname(__FILE__)
|
@@ -30,7 +29,7 @@ describe "Routing" do
|
|
30
29
|
assert_equal headers['Cache-Control'], 'public, must-revalidate, max-age=300'
|
31
30
|
end # static max_age
|
32
31
|
|
33
|
-
should
|
32
|
+
it 'should ignore trailing delimiters for basic route' do
|
34
33
|
mock_app do
|
35
34
|
get("/foo"){ "okey" }
|
36
35
|
get(:test) { "tester" }
|
@@ -45,7 +44,7 @@ describe "Routing" do
|
|
45
44
|
assert_equal "tester", body
|
46
45
|
end
|
47
46
|
|
48
|
-
should
|
47
|
+
it 'should fail with unrecognized route exception when not found' do
|
49
48
|
mock_app do
|
50
49
|
get(:index){ "okey" }
|
51
50
|
end
|
@@ -56,7 +55,7 @@ describe "Routing" do
|
|
56
55
|
}
|
57
56
|
end
|
58
57
|
|
59
|
-
should
|
58
|
+
it 'should fail with unrecognized route exception when namespace is invalid' do
|
60
59
|
mock_app do
|
61
60
|
controller :foo_bar do
|
62
61
|
get(:index){ "okey" }
|
@@ -82,7 +81,7 @@ describe "Routing" do
|
|
82
81
|
}
|
83
82
|
end
|
84
83
|
|
85
|
-
should
|
84
|
+
it 'should accept regexp routes' do
|
86
85
|
mock_app do
|
87
86
|
get(%r./fob|/baz.) { "regexp" }
|
88
87
|
get("/foo") { "str" }
|
@@ -105,14 +104,14 @@ describe "Routing" do
|
|
105
104
|
assert_equal "My lucky number: 99 99", body
|
106
105
|
end
|
107
106
|
|
108
|
-
should
|
107
|
+
it 'should accept regexp routes with generate with :generate_with' do
|
109
108
|
mock_app do
|
110
109
|
get(%r{/fob|/baz}, :name => :foo, :generate_with => '/fob') { "regexp" }
|
111
110
|
end
|
112
111
|
assert_equal "/fob", @app.url(:foo)
|
113
112
|
end
|
114
113
|
|
115
|
-
should
|
114
|
+
it 'should parse routes with question marks' do
|
116
115
|
mock_app do
|
117
116
|
get("/foo/?"){ "okey" }
|
118
117
|
post('/unauthenticated/?') { "no access" }
|
@@ -127,7 +126,7 @@ describe "Routing" do
|
|
127
126
|
assert_equal "no access", body
|
128
127
|
end
|
129
128
|
|
130
|
-
should
|
129
|
+
it 'should parse routes that are encoded' do
|
131
130
|
mock_app do
|
132
131
|
get('/щч') { 'success!' }
|
133
132
|
end
|
@@ -135,7 +134,7 @@ describe "Routing" do
|
|
135
134
|
assert_equal 'success!', body
|
136
135
|
end
|
137
136
|
|
138
|
-
should
|
137
|
+
it 'should parse routes that include encoded slash' do
|
139
138
|
mock_app do
|
140
139
|
get('/:drive_alias/:path', :path => /.*/){
|
141
140
|
"Show #{params[:drive_alias]} and #{params[:path]}"
|
@@ -145,7 +144,7 @@ describe "Routing" do
|
|
145
144
|
assert_equal "Show drive/foo and some/path", body
|
146
145
|
end
|
147
146
|
|
148
|
-
should
|
147
|
+
it 'should encode params using UTF-8' do
|
149
148
|
mock_app do
|
150
149
|
get('/:foo') { params[:foo].encoding.name }
|
151
150
|
end
|
@@ -153,7 +152,7 @@ describe "Routing" do
|
|
153
152
|
assert_equal 'UTF-8', body
|
154
153
|
end
|
155
154
|
|
156
|
-
should
|
155
|
+
it 'should match correctly similar paths' do
|
157
156
|
mock_app do
|
158
157
|
get("/my/:foo_id"){ params[:foo_id] }
|
159
158
|
get("/my/:bar_id/bar"){ params[:bar_id] }
|
@@ -164,7 +163,7 @@ describe "Routing" do
|
|
164
163
|
assert_equal "2", body
|
165
164
|
end
|
166
165
|
|
167
|
-
should
|
166
|
+
it 'should match user agents' do
|
168
167
|
app = mock_app do
|
169
168
|
get("/main", :agent => /IE/){ "hello IE" }
|
170
169
|
get("/main"){ "hello" }
|
@@ -175,7 +174,7 @@ describe "Routing" do
|
|
175
174
|
assert_equal "hello IE", body
|
176
175
|
end
|
177
176
|
|
178
|
-
should
|
177
|
+
it 'should use regex for parts of a route' do
|
179
178
|
app = mock_app do
|
180
179
|
get("/main/:id", :id => /\d+/){ "hello #{params[:id]}" }
|
181
180
|
end
|
@@ -185,7 +184,7 @@ describe "Routing" do
|
|
185
184
|
assert_equal 404, status
|
186
185
|
end
|
187
186
|
|
188
|
-
should
|
187
|
+
it 'should parse params when use regex for parts of a route' do
|
189
188
|
mock_app do
|
190
189
|
post :index, :with => [:foo, :bar], :bar => /.+/ do
|
191
190
|
"show #{params[:foo]}"
|
@@ -199,7 +198,7 @@ describe "Routing" do
|
|
199
198
|
assert_equal "show 5 and 2", body
|
200
199
|
end
|
201
200
|
|
202
|
-
should
|
201
|
+
it 'should not generate overlapping head urls' do
|
203
202
|
app = mock_app do
|
204
203
|
get("/main"){ "hello" }
|
205
204
|
post("/main"){ "hello" }
|
@@ -210,7 +209,7 @@ describe "Routing" do
|
|
210
209
|
assert_equal "POST", app.routes[2].request_methods.first
|
211
210
|
end
|
212
211
|
|
213
|
-
should
|
212
|
+
it 'should generate basic urls' do
|
214
213
|
mock_app do
|
215
214
|
get(:foo){ "/foo" }
|
216
215
|
get(:foo, :with => :id){ |id| "/foo/#{id}" }
|
@@ -247,7 +246,7 @@ describe "Routing" do
|
|
247
246
|
assert_equal "4", body
|
248
247
|
end
|
249
248
|
|
250
|
-
should
|
249
|
+
it 'should generate url with format' do
|
251
250
|
mock_app do
|
252
251
|
get(:a, :provides => :any){ url(:a, :format => :json) }
|
253
252
|
get(:b, :provides => :js){ url(:b, :format => :js) }
|
@@ -274,7 +273,7 @@ describe "Routing" do
|
|
274
273
|
assert_equal 404, status
|
275
274
|
end
|
276
275
|
|
277
|
-
should
|
276
|
+
it 'should generate absolute urls' do
|
278
277
|
mock_app do
|
279
278
|
get(:hash, :with => :id){ absolute_url(:hash, :id => 1) }
|
280
279
|
end
|
@@ -284,7 +283,7 @@ describe "Routing" do
|
|
284
283
|
assert_equal "https://example.org/hash/1", body
|
285
284
|
end
|
286
285
|
|
287
|
-
should
|
286
|
+
it 'should generate absolute urls from stringified keys' do
|
288
287
|
mock_app do
|
289
288
|
get(:hash, with: :id) { absolute_url(:hash, "id" => 1) }
|
290
289
|
end
|
@@ -292,7 +291,7 @@ describe "Routing" do
|
|
292
291
|
assert_equal "http://example.org/hash/1", body
|
293
292
|
end
|
294
293
|
|
295
|
-
should
|
294
|
+
it 'should generate proper absolute urls for mounted apps' do
|
296
295
|
class Test < Padrino::Application
|
297
296
|
get :foo do
|
298
297
|
absolute_url(:foo, :id => 1)
|
@@ -304,7 +303,7 @@ describe "Routing" do
|
|
304
303
|
assert_equal 'http://example.org/test/foo?id=1', body
|
305
304
|
end
|
306
305
|
|
307
|
-
should
|
306
|
+
it 'should rebase simple string urls to app uri_root' do
|
308
307
|
mock_app do
|
309
308
|
set :uri_root, '/app'
|
310
309
|
get(:a){ url('/foo') }
|
@@ -322,7 +321,7 @@ describe "Routing" do
|
|
322
321
|
assert_equal "http://example.org/app/d/e/bar", body
|
323
322
|
end
|
324
323
|
|
325
|
-
should
|
324
|
+
it 'should allow regex url with format' do
|
326
325
|
mock_app do
|
327
326
|
get(/.*/, :provides => :any) { "regexp" }
|
328
327
|
end
|
@@ -330,14 +329,14 @@ describe "Routing" do
|
|
330
329
|
assert_equal "regexp", body
|
331
330
|
end
|
332
331
|
|
333
|
-
should
|
332
|
+
it 'should use padrino url method' do
|
334
333
|
mock_app do
|
335
334
|
end
|
336
335
|
|
337
336
|
assert_equal @app.method(:url).owner, Padrino::Routing::ClassMethods
|
338
337
|
end
|
339
338
|
|
340
|
-
should
|
339
|
+
it 'should work correctly with sinatra redirects' do
|
341
340
|
mock_app do
|
342
341
|
get(:index) { redirect url(:index) }
|
343
342
|
get(:google) { redirect "http://google.com" }
|
@@ -353,7 +352,7 @@ describe "Routing" do
|
|
353
352
|
assert_equal "http://example.org/bar", headers['Location']
|
354
353
|
end
|
355
354
|
|
356
|
-
should
|
355
|
+
it 'should return 406 on Accept-Headers it does not provide' do
|
357
356
|
mock_app do
|
358
357
|
get(:a, :provides => [:html, :js]){ content_type }
|
359
358
|
end
|
@@ -362,7 +361,7 @@ describe "Routing" do
|
|
362
361
|
assert_equal 406, status
|
363
362
|
end
|
364
363
|
|
365
|
-
should
|
364
|
+
it 'should return 406 on file extensions it does not provide and flag is set' do
|
366
365
|
mock_app do
|
367
366
|
enable :treat_format_as_accept
|
368
367
|
get(:a, :provides => [:html, :js]){ content_type }
|
@@ -372,7 +371,7 @@ describe "Routing" do
|
|
372
371
|
assert_equal 406, status
|
373
372
|
end
|
374
373
|
|
375
|
-
should
|
374
|
+
it 'should return 404 on file extensions it does not provide and flag is not set' do
|
376
375
|
mock_app do
|
377
376
|
get(:a, :provides => [:html, :js]){ content_type }
|
378
377
|
end
|
@@ -381,7 +380,7 @@ describe "Routing" do
|
|
381
380
|
assert_equal 404, status
|
382
381
|
end
|
383
382
|
|
384
|
-
should
|
383
|
+
it 'should not set content_type to :html if Accept */* and html not in provides' do
|
385
384
|
mock_app do
|
386
385
|
get("/foo", :provides => [:json, :xml]) { content_type.to_s }
|
387
386
|
end
|
@@ -390,7 +389,7 @@ describe "Routing" do
|
|
390
389
|
assert_equal 'json', body
|
391
390
|
end
|
392
391
|
|
393
|
-
should
|
392
|
+
it 'should set content_type to :json if Accept contains */*' do
|
394
393
|
mock_app do
|
395
394
|
get("/foo", :provides => [:json]) { content_type.to_s }
|
396
395
|
end
|
@@ -399,7 +398,7 @@ describe "Routing" do
|
|
399
398
|
assert_equal 'json', body
|
400
399
|
end
|
401
400
|
|
402
|
-
should
|
401
|
+
it 'should set and get content_type' do
|
403
402
|
mock_app do
|
404
403
|
get("/foo"){ content_type(:json); content_type.to_s }
|
405
404
|
end
|
@@ -408,7 +407,7 @@ describe "Routing" do
|
|
408
407
|
assert_equal 'json', body
|
409
408
|
end
|
410
409
|
|
411
|
-
should
|
410
|
+
it 'should send the appropriate number of params' do
|
412
411
|
mock_app do
|
413
412
|
get('/id/:user_id', :provides => [:json]) { |user_id, format| user_id}
|
414
413
|
end
|
@@ -416,7 +415,7 @@ describe "Routing" do
|
|
416
415
|
assert_equal '5', body
|
417
416
|
end
|
418
417
|
|
419
|
-
should
|
418
|
+
it 'should allow "." in param values' do
|
420
419
|
skip # TODO fix this?
|
421
420
|
mock_app do
|
422
421
|
get('/id/:email', :provides => [:json]) { |email, format| [email, format] * '/' }
|
@@ -425,7 +424,7 @@ describe "Routing" do
|
|
425
424
|
assert_equal 'foo@bar.com/json', body
|
426
425
|
end
|
427
426
|
|
428
|
-
should
|
427
|
+
it 'should set correct content_type for Accept not equal to */* even if */* also provided' do
|
429
428
|
mock_app do
|
430
429
|
get("/foo", :provides => [:html, :js, :xml]) { content_type.to_s }
|
431
430
|
end
|
@@ -434,7 +433,7 @@ describe "Routing" do
|
|
434
433
|
assert_equal 'js', body
|
435
434
|
end
|
436
435
|
|
437
|
-
should
|
436
|
+
it 'should return the first content type in provides if accept header is empty' do
|
438
437
|
mock_app do
|
439
438
|
get(:a, :provides => [:js]){ content_type.to_s }
|
440
439
|
end
|
@@ -443,7 +442,7 @@ describe "Routing" do
|
|
443
442
|
assert_equal "js", body
|
444
443
|
end
|
445
444
|
|
446
|
-
should
|
445
|
+
it 'should not default to HTML if HTML is not provided and no type is given' do
|
447
446
|
mock_app do
|
448
447
|
get(:a, :provides => [:js]){ content_type }
|
449
448
|
end
|
@@ -452,7 +451,7 @@ describe "Routing" do
|
|
452
451
|
assert_equal "application/javascript;charset=utf-8", content_type
|
453
452
|
end
|
454
453
|
|
455
|
-
should
|
454
|
+
it 'should not match routes if url_format and http_accept is provided but not included' do
|
456
455
|
mock_app do
|
457
456
|
get(:a, :provides => [:js, :html]){ content_type }
|
458
457
|
end
|
@@ -461,7 +460,7 @@ describe "Routing" do
|
|
461
460
|
assert_equal 404, status
|
462
461
|
end
|
463
462
|
|
464
|
-
should
|
463
|
+
it 'should generate routes for format simple' do
|
465
464
|
mock_app do
|
466
465
|
get(:foo, :provides => [:html, :rss]) { render :haml, "Test" }
|
467
466
|
end
|
@@ -471,7 +470,7 @@ describe "Routing" do
|
|
471
470
|
assert_equal "Test\n", body
|
472
471
|
end
|
473
472
|
|
474
|
-
|
473
|
+
it 'should inject the controller name into the request' do
|
475
474
|
mock_app do
|
476
475
|
controller :posts do
|
477
476
|
get(:index) { request.controller }
|
@@ -486,7 +485,7 @@ describe "Routing" do
|
|
486
485
|
assert_equal "mini", body
|
487
486
|
end
|
488
487
|
|
489
|
-
|
488
|
+
it 'should inject the action name into the request' do
|
490
489
|
mock_app do
|
491
490
|
controller :posts do
|
492
491
|
get('/omnomnom(/:id)') { request.action.inspect }
|
@@ -501,7 +500,7 @@ describe "Routing" do
|
|
501
500
|
assert_equal ":a", body
|
502
501
|
end
|
503
502
|
|
504
|
-
should
|
503
|
+
it 'should support not_found' do
|
505
504
|
mock_app do
|
506
505
|
not_found { 'whatever' }
|
507
506
|
|
@@ -517,7 +516,7 @@ describe "Routing" do
|
|
517
516
|
assert_equal 200, status
|
518
517
|
end
|
519
518
|
|
520
|
-
|
519
|
+
it 'should inject the route into the request' do
|
521
520
|
mock_app do
|
522
521
|
controller :posts do
|
523
522
|
get(:index) { request.route_obj.name.to_s }
|
@@ -527,7 +526,7 @@ describe "Routing" do
|
|
527
526
|
assert_equal "posts index", body
|
528
527
|
end
|
529
528
|
|
530
|
-
should
|
529
|
+
it 'should preserve the format if you set it manually' do
|
531
530
|
mock_app do
|
532
531
|
before do
|
533
532
|
params[:format] = "json"
|
@@ -545,7 +544,7 @@ describe "Routing" do
|
|
545
544
|
assert_equal ":json", body
|
546
545
|
end
|
547
546
|
|
548
|
-
should
|
547
|
+
it 'should correctly accept "." in the route' do
|
549
548
|
mock_app do
|
550
549
|
get "test.php", :provides => [:html, :json] do
|
551
550
|
content_type.inspect
|
@@ -557,7 +556,7 @@ describe "Routing" do
|
|
557
556
|
assert_equal ":json", body
|
558
557
|
end
|
559
558
|
|
560
|
-
should
|
559
|
+
it 'should correctly accept priority of format' do
|
561
560
|
mock_app do
|
562
561
|
get "test.php", :provides => [:html, :json, :xml] do
|
563
562
|
content_type.inspect
|
@@ -574,7 +573,7 @@ describe "Routing" do
|
|
574
573
|
assert_equal ":json", body
|
575
574
|
end
|
576
575
|
|
577
|
-
should
|
576
|
+
it 'should generate routes for format with controller' do
|
578
577
|
mock_app do
|
579
578
|
controller :posts do
|
580
579
|
get(:index, :provides => [:html, :rss, :atom, :js]) { render :haml, "Index.#{content_type}" }
|
@@ -597,7 +596,7 @@ describe "Routing" do
|
|
597
596
|
assert_equal "Show.atom\n", body
|
598
597
|
end
|
599
598
|
|
600
|
-
should
|
599
|
+
it 'should map routes' do
|
601
600
|
mock_app do
|
602
601
|
get(:bar){ "bar" }
|
603
602
|
end
|
@@ -606,7 +605,7 @@ describe "Routing" do
|
|
606
605
|
assert_equal "/bar", @app.url(:bar)
|
607
606
|
end
|
608
607
|
|
609
|
-
should
|
608
|
+
it 'should remove index from path' do
|
610
609
|
mock_app do
|
611
610
|
get(:index){ "index" }
|
612
611
|
get("/accounts/index"){ "accounts" }
|
@@ -618,7 +617,7 @@ describe "Routing" do
|
|
618
617
|
assert_equal "accounts", body
|
619
618
|
end
|
620
619
|
|
621
|
-
should
|
620
|
+
it 'should remove index from path with params' do
|
622
621
|
mock_app do
|
623
622
|
get(:index, :with => :name){ "index with #{params[:name]}" }
|
624
623
|
end
|
@@ -627,7 +626,7 @@ describe "Routing" do
|
|
627
626
|
assert_equal "/john", @app.url(:index, :name => "john")
|
628
627
|
end
|
629
628
|
|
630
|
-
should
|
629
|
+
it 'should parse named params' do
|
631
630
|
mock_app do
|
632
631
|
get(:print, :with => :id){ "Im #{params[:id]}" }
|
633
632
|
end
|
@@ -636,7 +635,7 @@ describe "Routing" do
|
|
636
635
|
assert_equal "/print/9", @app.url(:print, :id => 9)
|
637
636
|
end
|
638
637
|
|
639
|
-
should
|
638
|
+
it 'should 405 on wrong request_method' do
|
640
639
|
mock_app do
|
641
640
|
post('/bar'){ "bar" }
|
642
641
|
end
|
@@ -644,7 +643,7 @@ describe "Routing" do
|
|
644
643
|
assert_equal 405, status
|
645
644
|
end
|
646
645
|
|
647
|
-
should
|
646
|
+
it 'should respond to' do
|
648
647
|
mock_app do
|
649
648
|
get(:a, :provides => :js){ "js" }
|
650
649
|
get(:b, :provides => :any){ "any" }
|
@@ -673,7 +672,7 @@ describe "Routing" do
|
|
673
672
|
assert_equal "html,js", body
|
674
673
|
end
|
675
674
|
|
676
|
-
should
|
675
|
+
it 'should respond_to and set content_type' do
|
677
676
|
Rack::Mime::MIME_TYPES['.foo'] = 'application/foo'
|
678
677
|
mock_app do
|
679
678
|
get :a, :provides => :any do
|
@@ -699,7 +698,7 @@ describe "Routing" do
|
|
699
698
|
assert_equal 'text/html;charset=utf-8', response["Content-Type"]
|
700
699
|
end
|
701
700
|
|
702
|
-
should
|
701
|
+
it 'should use controllers' do
|
703
702
|
mock_app do
|
704
703
|
controller "/admin" do
|
705
704
|
get("/"){ "index" }
|
@@ -712,7 +711,7 @@ describe "Routing" do
|
|
712
711
|
assert_equal "show 1", body
|
713
712
|
end
|
714
713
|
|
715
|
-
should
|
714
|
+
it 'should use named controllers' do
|
716
715
|
mock_app do
|
717
716
|
controller :admin do
|
718
717
|
get(:index, :with => :id){ params[:id] }
|
@@ -732,7 +731,7 @@ describe "Routing" do
|
|
732
731
|
assert_equal "foo_bar_index", body
|
733
732
|
end
|
734
733
|
|
735
|
-
should
|
734
|
+
it 'should use map and with' do
|
736
735
|
mock_app do
|
737
736
|
get :index, :map => '/bugs', :with => :id do
|
738
737
|
params[:id]
|
@@ -743,7 +742,7 @@ describe "Routing" do
|
|
743
742
|
assert_equal "/bugs/4", @app.url(:index, :id => 4)
|
744
743
|
end
|
745
744
|
|
746
|
-
should
|
745
|
+
it 'should ignore trailing delimiters within a named controller' do
|
747
746
|
mock_app do
|
748
747
|
controller :posts do
|
749
748
|
get(:index, :provides => [:html, :js]){ "index" }
|
@@ -765,7 +764,7 @@ describe "Routing" do
|
|
765
764
|
assert_equal "new", body
|
766
765
|
end
|
767
766
|
|
768
|
-
should
|
767
|
+
it 'should ignore trailing delimiters within a named controller for unnamed actions' do
|
769
768
|
mock_app do
|
770
769
|
controller :accounts do
|
771
770
|
get("/") { "account_index" }
|
@@ -789,7 +788,7 @@ describe "Routing" do
|
|
789
788
|
assert_equal "vote_index", body
|
790
789
|
end
|
791
790
|
|
792
|
-
should
|
791
|
+
it 'should use named controllers with array routes' do
|
793
792
|
mock_app do
|
794
793
|
controller :admin do
|
795
794
|
get(:index){ "index" }
|
@@ -809,7 +808,7 @@ describe "Routing" do
|
|
809
808
|
assert_equal "foo_bar_index", body
|
810
809
|
end
|
811
810
|
|
812
|
-
should
|
811
|
+
it 'should support a reindex action and remove index inside controller' do
|
813
812
|
mock_app do
|
814
813
|
controller :posts do
|
815
814
|
get(:index){ "index" }
|
@@ -823,7 +822,7 @@ describe "Routing" do
|
|
823
822
|
assert_equal "reindex", body
|
824
823
|
end
|
825
824
|
|
826
|
-
should
|
825
|
+
it 'should use uri_root' do
|
827
826
|
mock_app do
|
828
827
|
get(:foo){ "foo" }
|
829
828
|
end
|
@@ -837,7 +836,7 @@ describe "Routing" do
|
|
837
836
|
assert_equal "/testing/bar/foo", @app.url(:foo)
|
838
837
|
end
|
839
838
|
|
840
|
-
should
|
839
|
+
it 'should use uri_root with controllers' do
|
841
840
|
mock_app do
|
842
841
|
controller :foo do
|
843
842
|
get(:bar){ "bar" }
|
@@ -847,7 +846,7 @@ describe "Routing" do
|
|
847
846
|
assert_equal "/testing/foo/bar", @app.url(:foo, :bar)
|
848
847
|
end
|
849
848
|
|
850
|
-
should
|
849
|
+
it 'should use RACK_BASE_URI' do
|
851
850
|
mock_app do
|
852
851
|
get(:foo){ "foo" }
|
853
852
|
end
|
@@ -859,7 +858,7 @@ describe "Routing" do
|
|
859
858
|
ENV['RACK_BASE_URI'] = nil
|
860
859
|
end
|
861
860
|
|
862
|
-
should
|
861
|
+
it 'should reset routes' do
|
863
862
|
mock_app do
|
864
863
|
get("/"){ "foo" }
|
865
864
|
reset_router!
|
@@ -868,7 +867,7 @@ describe "Routing" do
|
|
868
867
|
assert_equal 404, status
|
869
868
|
end
|
870
869
|
|
871
|
-
should
|
870
|
+
it 'should match params and format' do
|
872
871
|
app = mock_app do
|
873
872
|
get '/:id', :provides => [:json, :html] do |id, _|
|
874
873
|
id
|
@@ -887,7 +886,7 @@ describe "Routing" do
|
|
887
886
|
end
|
888
887
|
|
889
888
|
|
890
|
-
should
|
889
|
+
it 'should respect priorities' do
|
891
890
|
route_order = []
|
892
891
|
mock_app do
|
893
892
|
get(:index, :priority => :normal) { route_order << :normal; pass }
|
@@ -899,7 +898,7 @@ describe "Routing" do
|
|
899
898
|
assert_equal "hello", body
|
900
899
|
end
|
901
900
|
|
902
|
-
should
|
901
|
+
it 'should catch all after controllers' do
|
903
902
|
mock_app do
|
904
903
|
get(:index, :with => :slug, :priority => :low) { "catch all" }
|
905
904
|
controllers :contact do
|
@@ -912,7 +911,7 @@ describe "Routing" do
|
|
912
911
|
assert_equal "catch all", body
|
913
912
|
end
|
914
913
|
|
915
|
-
should
|
914
|
+
it 'should allow optionals' do
|
916
915
|
mock_app do
|
917
916
|
get(:show, :map => "/stories/:type(/:category)") do
|
918
917
|
"#{params[:type]}/#{params[:category]}"
|
@@ -924,7 +923,7 @@ describe "Routing" do
|
|
924
923
|
assert_equal "foo/bar", body
|
925
924
|
end
|
926
925
|
|
927
|
-
should
|
926
|
+
it 'should apply maps' do
|
928
927
|
mock_app do
|
929
928
|
controllers :admin do
|
930
929
|
get(:index, :map => "/"){ "index" }
|
@@ -945,7 +944,7 @@ describe "Routing" do
|
|
945
944
|
assert_equal "wacky 1-2", body
|
946
945
|
end
|
947
946
|
|
948
|
-
should
|
947
|
+
it 'should apply maps when given path is kind of hash' do
|
949
948
|
mock_app do
|
950
949
|
controllers :admin do
|
951
950
|
get(:foobar, "/foo/bar"){ "foobar" }
|
@@ -955,7 +954,7 @@ describe "Routing" do
|
|
955
954
|
assert_equal "foobar", body
|
956
955
|
end
|
957
956
|
|
958
|
-
should
|
957
|
+
it 'should apply parent to route' do
|
959
958
|
mock_app do
|
960
959
|
controllers :project do
|
961
960
|
get(:index, :parent => :user) { "index #{params[:user_id]}" }
|
@@ -974,7 +973,7 @@ describe "Routing" do
|
|
974
973
|
assert_equal "show 3 1 2", body
|
975
974
|
end
|
976
975
|
|
977
|
-
should
|
976
|
+
it 'should respect parent precedence: controllers parents go before route parents' do
|
978
977
|
mock_app do
|
979
978
|
controllers :project do
|
980
979
|
get(:index, :parent => :user) { "index #{params[:user_id]}" }
|
@@ -994,7 +993,7 @@ describe "Routing" do
|
|
994
993
|
assert_equal "index on foo 1 @ baz 2 @ bar", body
|
995
994
|
end
|
996
995
|
|
997
|
-
should
|
996
|
+
it 'should keep a reference to the parent on the route' do
|
998
997
|
mock_app do
|
999
998
|
controllers :project do
|
1000
999
|
get(:index, :parent => :user) { "index #{params[:user_id]}" }
|
@@ -1023,7 +1022,7 @@ describe "Routing" do
|
|
1023
1022
|
assert_equal [:foo, :baz], @app.routes[10].parent
|
1024
1023
|
end
|
1025
1024
|
|
1026
|
-
should
|
1025
|
+
it 'should apply parent to controller' do
|
1027
1026
|
mock_app do
|
1028
1027
|
controller :project, :parent => :user do
|
1029
1028
|
get(:index) { "index #{params[:user_id]}"}
|
@@ -1048,7 +1047,7 @@ describe "Routing" do
|
|
1048
1047
|
assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3)
|
1049
1048
|
end
|
1050
1049
|
|
1051
|
-
should
|
1050
|
+
it 'should apply parent with shallowing to controller' do
|
1052
1051
|
mock_app do
|
1053
1052
|
controller :project do
|
1054
1053
|
parent :user
|
@@ -1093,7 +1092,7 @@ describe "Routing" do
|
|
1093
1092
|
assert_equal user_product_project_url, @app.url(:project, :show, :user_id => 1, :product_id => 2, :id => 3, :shop_id => 1)
|
1094
1093
|
end
|
1095
1094
|
|
1096
|
-
should
|
1095
|
+
it 'should respect map in parents with shallowing' do
|
1097
1096
|
mock_app do
|
1098
1097
|
controller :project do
|
1099
1098
|
parent :shop, :map => "/foo/bar"
|
@@ -1107,7 +1106,7 @@ describe "Routing" do
|
|
1107
1106
|
assert_equal shop_project_url, @app.url(:project, :index, :shop_id => 1)
|
1108
1107
|
end
|
1109
1108
|
|
1110
|
-
should
|
1109
|
+
it 'should use default values' do
|
1111
1110
|
mock_app do
|
1112
1111
|
controller :lang => :it do
|
1113
1112
|
get(:index, :map => "/:lang") { "lang is #{params[:lang]}" }
|
@@ -1122,7 +1121,7 @@ describe "Routing" do
|
|
1122
1121
|
assert_equal "lang is en", body
|
1123
1122
|
end
|
1124
1123
|
|
1125
|
-
should
|
1124
|
+
it 'should transitions to the next matching route on pass' do
|
1126
1125
|
mock_app do
|
1127
1126
|
get '/:foo' do
|
1128
1127
|
pass
|
@@ -1137,7 +1136,43 @@ describe "Routing" do
|
|
1137
1136
|
assert_equal 'Hello World', body
|
1138
1137
|
end
|
1139
1138
|
|
1140
|
-
should
|
1139
|
+
it 'should filters by media type' do
|
1140
|
+
mock_app do
|
1141
|
+
get '/foo', :accepts => [:xml, :json] do
|
1142
|
+
request.env['CONTENT_TYPE']
|
1143
|
+
end
|
1144
|
+
end
|
1145
|
+
|
1146
|
+
get '/foo', {}, { 'CONTENT_TYPE' => 'application/xml' }
|
1147
|
+
assert ok?
|
1148
|
+
assert_equal 'application/xml', body
|
1149
|
+
assert_equal 'application/xml;charset=utf-8', response.headers['Content-Type']
|
1150
|
+
get '/foo'
|
1151
|
+
assert_equal 406, status
|
1152
|
+
get '/foo.xml'
|
1153
|
+
assert_equal 404, status
|
1154
|
+
|
1155
|
+
get '/foo', {}, { 'CONTENT_TYPE' => 'application/json' }
|
1156
|
+
assert ok?
|
1157
|
+
assert_equal 'application/json', body
|
1158
|
+
assert_equal 'application/json', response.headers['Content-Type']
|
1159
|
+
end
|
1160
|
+
|
1161
|
+
it 'should filters by media type when using :accepts as controller option' do
|
1162
|
+
mock_app do
|
1163
|
+
controller accepts: [:xml, :js] do
|
1164
|
+
get '/foo' do
|
1165
|
+
request.env['CONTENT_TYPE']
|
1166
|
+
end
|
1167
|
+
end
|
1168
|
+
end
|
1169
|
+
|
1170
|
+
get '/foo', {}, { 'CONTENT_TYPE' => 'application/javascript' }
|
1171
|
+
assert ok?
|
1172
|
+
assert_equal 'application/javascript', body
|
1173
|
+
end
|
1174
|
+
|
1175
|
+
it 'should filters by accept header' do
|
1141
1176
|
mock_app do
|
1142
1177
|
get '/foo', :provides => [:xml, :js] do
|
1143
1178
|
request.env['HTTP_ACCEPT']
|
@@ -1166,7 +1201,7 @@ describe "Routing" do
|
|
1166
1201
|
assert_equal 406, status
|
1167
1202
|
end
|
1168
1203
|
|
1169
|
-
should
|
1204
|
+
it 'should does not allow global provides' do
|
1170
1205
|
mock_app do
|
1171
1206
|
provides :xml
|
1172
1207
|
|
@@ -1183,7 +1218,7 @@ describe "Routing" do
|
|
1183
1218
|
assert_equal 'Bar in nil', body
|
1184
1219
|
end
|
1185
1220
|
|
1186
|
-
should
|
1221
|
+
it 'should does not allow global provides in controller' do
|
1187
1222
|
mock_app do
|
1188
1223
|
controller :base do
|
1189
1224
|
provides :xml
|
@@ -1202,7 +1237,7 @@ describe "Routing" do
|
|
1202
1237
|
assert_equal 'Bar in nil', body
|
1203
1238
|
end
|
1204
1239
|
|
1205
|
-
should
|
1240
|
+
it 'should map non named routes in controllers' do
|
1206
1241
|
mock_app do
|
1207
1242
|
controller :base do
|
1208
1243
|
get("/foo") { "ok" }
|
@@ -1216,7 +1251,7 @@ describe "Routing" do
|
|
1216
1251
|
assert ok?
|
1217
1252
|
end
|
1218
1253
|
|
1219
|
-
should
|
1254
|
+
it 'should set content_type to :html for both empty Accept as well as Accept text/html' do
|
1220
1255
|
mock_app do
|
1221
1256
|
provides :html
|
1222
1257
|
|
@@ -1230,7 +1265,7 @@ describe "Routing" do
|
|
1230
1265
|
assert_equal 'html', body
|
1231
1266
|
end
|
1232
1267
|
|
1233
|
-
should
|
1268
|
+
it 'should set content_type to :html if Accept */*' do
|
1234
1269
|
mock_app do
|
1235
1270
|
get("/foo", :provides => [:html, :js]) { content_type.to_s }
|
1236
1271
|
end
|
@@ -1241,7 +1276,7 @@ describe "Routing" do
|
|
1241
1276
|
assert_equal 'html', body
|
1242
1277
|
end
|
1243
1278
|
|
1244
|
-
should
|
1279
|
+
it 'should set content_type to :js if Accept includes both application/javascript and */*;q=0.5' do
|
1245
1280
|
mock_app do
|
1246
1281
|
get("/foo", :provides => [:html, :js]) { content_type.to_s }
|
1247
1282
|
end
|
@@ -1249,7 +1284,7 @@ describe "Routing" do
|
|
1249
1284
|
assert_equal 'js', body
|
1250
1285
|
end
|
1251
1286
|
|
1252
|
-
should
|
1287
|
+
it 'should set content_type to :html if Accept */* and provides of :any' do
|
1253
1288
|
mock_app do
|
1254
1289
|
get("/foo", :provides => :any) { content_type.to_s }
|
1255
1290
|
end
|
@@ -1258,7 +1293,7 @@ describe "Routing" do
|
|
1258
1293
|
assert_equal 'html', body
|
1259
1294
|
end
|
1260
1295
|
|
1261
|
-
should
|
1296
|
+
it 'should set content_type to :js if Accept includes both application/javascript, */*;q=0.5 and provides of :any' do
|
1262
1297
|
mock_app do
|
1263
1298
|
get("/foo", :provides => :any) { content_type.to_s }
|
1264
1299
|
end
|
@@ -1267,7 +1302,7 @@ describe "Routing" do
|
|
1267
1302
|
assert_equal 'js', body
|
1268
1303
|
end
|
1269
1304
|
|
1270
|
-
should
|
1305
|
+
it 'should allows custom route-conditions to be set via route options and halt' do
|
1271
1306
|
protector = Module.new do
|
1272
1307
|
def protect(*args)
|
1273
1308
|
condition {
|
@@ -1301,7 +1336,7 @@ describe "Routing" do
|
|
1301
1336
|
assert_equal "hey", body
|
1302
1337
|
end
|
1303
1338
|
|
1304
|
-
should
|
1339
|
+
it 'should allows custom route-conditions to be set via route options using two routes' do
|
1305
1340
|
protector = Module.new do
|
1306
1341
|
def protect(*args)
|
1307
1342
|
condition { authorize(params["user"], params["password"]) }
|
@@ -1334,7 +1369,7 @@ describe "Routing" do
|
|
1334
1369
|
assert_equal "hey", body
|
1335
1370
|
end
|
1336
1371
|
|
1337
|
-
should
|
1372
|
+
it 'should allow concise routing' do
|
1338
1373
|
mock_app do
|
1339
1374
|
get :index, ":id" do
|
1340
1375
|
params[:id]
|
@@ -1352,7 +1387,7 @@ describe "Routing" do
|
|
1352
1387
|
assert_equal "123", body
|
1353
1388
|
end
|
1354
1389
|
|
1355
|
-
should
|
1390
|
+
it 'should support halting with 404 and message' do
|
1356
1391
|
mock_app do
|
1357
1392
|
controller do
|
1358
1393
|
get :index do
|
@@ -1366,7 +1401,7 @@ describe "Routing" do
|
|
1366
1401
|
assert_equal "not found", body
|
1367
1402
|
end
|
1368
1403
|
|
1369
|
-
should
|
1404
|
+
it 'should allow passing & halting in before filters' do
|
1370
1405
|
mock_app do
|
1371
1406
|
controller do
|
1372
1407
|
before { env['QUERY_STRING'] == 'secret' or pass }
|
@@ -1394,7 +1429,7 @@ describe "Routing" do
|
|
1394
1429
|
assert_equal "index", body
|
1395
1430
|
end
|
1396
1431
|
|
1397
|
-
should
|
1432
|
+
it 'should scope filters in the given controller' do
|
1398
1433
|
mock_app do
|
1399
1434
|
before { @global = 'global' }
|
1400
1435
|
after { @global = nil }
|
@@ -1424,7 +1459,7 @@ describe "Routing" do
|
|
1424
1459
|
assert_equal "global", body
|
1425
1460
|
end
|
1426
1461
|
|
1427
|
-
should
|
1462
|
+
it 'should works with optionals params' do
|
1428
1463
|
mock_app do
|
1429
1464
|
get("/foo(/:bar)") { params[:bar] }
|
1430
1465
|
end
|
@@ -1436,7 +1471,7 @@ describe "Routing" do
|
|
1436
1471
|
assert_equal "", body
|
1437
1472
|
end
|
1438
1473
|
|
1439
|
-
should
|
1474
|
+
it 'should work with multiple dashed params' do
|
1440
1475
|
mock_app do
|
1441
1476
|
get "/route/:foo/:bar/:baz", :provides => :html do
|
1442
1477
|
"#{params[:foo]};#{params[:bar]};#{params[:baz]}"
|
@@ -1450,7 +1485,7 @@ describe "Routing" do
|
|
1450
1485
|
assert_equal 'foo;bar-whatever;baz', body
|
1451
1486
|
end
|
1452
1487
|
|
1453
|
-
should
|
1488
|
+
it 'should work with arbitrary params' do
|
1454
1489
|
mock_app do
|
1455
1490
|
get(:testing) { params[:foo] }
|
1456
1491
|
end
|
@@ -1461,7 +1496,7 @@ describe "Routing" do
|
|
1461
1496
|
assert_equal "bar", body
|
1462
1497
|
end
|
1463
1498
|
|
1464
|
-
should
|
1499
|
+
it 'should ignore nil params' do
|
1465
1500
|
mock_app do
|
1466
1501
|
get(:testing, :provides => [:html, :json]) do
|
1467
1502
|
end
|
@@ -1470,7 +1505,7 @@ describe "Routing" do
|
|
1470
1505
|
assert_equal '/testing', @app.url(:testing, :format => nil)
|
1471
1506
|
end
|
1472
1507
|
|
1473
|
-
should
|
1508
|
+
it 'should be able to access params in a before filter' do
|
1474
1509
|
username_from_before_filter = nil
|
1475
1510
|
|
1476
1511
|
mock_app do
|
@@ -1485,7 +1520,7 @@ describe "Routing" do
|
|
1485
1520
|
assert_equal 'josh', username_from_before_filter
|
1486
1521
|
end
|
1487
1522
|
|
1488
|
-
should
|
1523
|
+
it 'should be able to access params normally when a before filter is specified' do
|
1489
1524
|
mock_app do
|
1490
1525
|
before { }
|
1491
1526
|
get :index do
|
@@ -1496,7 +1531,7 @@ describe "Routing" do
|
|
1496
1531
|
assert_equal '{"test"=>"what"}', body
|
1497
1532
|
end
|
1498
1533
|
|
1499
|
-
should
|
1534
|
+
it 'should work only for the given controller and route when using before-filter with route name' do
|
1500
1535
|
mock_app do
|
1501
1536
|
controller :foo do
|
1502
1537
|
before(:index) { @a = "only to :index" }
|
@@ -1510,7 +1545,7 @@ describe "Routing" do
|
|
1510
1545
|
assert_equal '', body
|
1511
1546
|
end
|
1512
1547
|
|
1513
|
-
should
|
1548
|
+
it 'should work only for the given controller and route when using after-filter with route name' do
|
1514
1549
|
mock_app do
|
1515
1550
|
controller :after_controller do
|
1516
1551
|
global = "global variable"
|
@@ -1525,7 +1560,7 @@ describe "Routing" do
|
|
1525
1560
|
assert_equal '', body
|
1526
1561
|
end
|
1527
1562
|
|
1528
|
-
should
|
1563
|
+
it 'should execute the before/after filters when they are inserted after the target route' do
|
1529
1564
|
mock_app do
|
1530
1565
|
controller :after_test do
|
1531
1566
|
global = "global variable"
|
@@ -1541,7 +1576,7 @@ describe "Routing" do
|
|
1541
1576
|
assert_equal 'after', body
|
1542
1577
|
end
|
1543
1578
|
|
1544
|
-
should
|
1579
|
+
it 'should work with controller and arbitrary params' do
|
1545
1580
|
mock_app do
|
1546
1581
|
get(:testing) { params[:foo] }
|
1547
1582
|
controller :test1 do
|
@@ -1561,7 +1596,7 @@ describe "Routing" do
|
|
1561
1596
|
assert_equal "bar2", body
|
1562
1597
|
end
|
1563
1598
|
|
1564
|
-
should
|
1599
|
+
it 'should parse two routes with the same path but different http verbs' do
|
1565
1600
|
mock_app do
|
1566
1601
|
get(:index) { "This is the get index" }
|
1567
1602
|
post(:index) { "This is the post index" }
|
@@ -1572,7 +1607,7 @@ describe "Routing" do
|
|
1572
1607
|
assert_equal "This is the post index", body
|
1573
1608
|
end
|
1574
1609
|
|
1575
|
-
should
|
1610
|
+
it 'should use optionals params' do
|
1576
1611
|
mock_app do
|
1577
1612
|
get(:index, :map => "/(:foo(/:bar))") { "#{params[:foo]}-#{params[:bar]}" }
|
1578
1613
|
end
|
@@ -1582,7 +1617,7 @@ describe "Routing" do
|
|
1582
1617
|
assert_equal "foo-bar", body
|
1583
1618
|
end
|
1584
1619
|
|
1585
|
-
should
|
1620
|
+
it 'should parse two routes with the same path but different http verbs and provides' do
|
1586
1621
|
mock_app do
|
1587
1622
|
get(:index, :provides => [:html, :json]) { "This is the get index.#{content_type}" }
|
1588
1623
|
post(:index, :provides => [:html, :json]) { "This is the post index.#{content_type}" }
|
@@ -1601,7 +1636,7 @@ describe "Routing" do
|
|
1601
1636
|
assert_equal 404, status
|
1602
1637
|
end
|
1603
1638
|
|
1604
|
-
should
|
1639
|
+
it 'should allow controller level mapping' do
|
1605
1640
|
mock_app do
|
1606
1641
|
controller :map => "controller-:id" do
|
1607
1642
|
get(:url3) { "#{params[:id]}" }
|
@@ -1620,7 +1655,7 @@ describe "Routing" do
|
|
1620
1655
|
assert_equal "1, 2", body
|
1621
1656
|
end
|
1622
1657
|
|
1623
|
-
should
|
1658
|
+
it 'should replace name of named controller with mapping path' do
|
1624
1659
|
mock_app do
|
1625
1660
|
controller :ugly, :map => "/pretty/:id" do
|
1626
1661
|
get(:url3) { "#{params[:id]}" }
|
@@ -1647,7 +1682,7 @@ describe "Routing" do
|
|
1647
1682
|
assert_equal 'okay', body
|
1648
1683
|
end
|
1649
1684
|
|
1650
|
-
should
|
1685
|
+
it 'should use absolute and relative maps' do
|
1651
1686
|
mock_app do
|
1652
1687
|
controller :one do
|
1653
1688
|
parent :three
|
@@ -1667,7 +1702,7 @@ describe "Routing" do
|
|
1667
1702
|
assert_equal "/two/four_id", @app.url(:two, :index2, 'four_id')
|
1668
1703
|
end
|
1669
1704
|
|
1670
|
-
should
|
1705
|
+
it 'should work with params and parent options' do
|
1671
1706
|
mock_app do
|
1672
1707
|
controller :test2, :parent => :parent1, :parent1_id => 1 do
|
1673
1708
|
get(:url3) { params[:foo] }
|
@@ -1692,7 +1727,7 @@ describe "Routing" do
|
|
1692
1727
|
assert_equal "bar5", body
|
1693
1728
|
end
|
1694
1729
|
|
1695
|
-
should
|
1730
|
+
it 'should parse params without explicit provides for every matching route' do
|
1696
1731
|
mock_app do
|
1697
1732
|
get(:index, :map => "/foos/:bar") { "get bar = #{params[:bar]}" }
|
1698
1733
|
post :create, :map => "/foos/:bar", :provides => [:html, :js] do
|
@@ -1708,7 +1743,7 @@ describe "Routing" do
|
|
1708
1743
|
assert_equal "post bar = hello", body
|
1709
1744
|
end
|
1710
1745
|
|
1711
|
-
should
|
1746
|
+
it 'should properly route to first foo with two similar routes' do
|
1712
1747
|
mock_app do
|
1713
1748
|
controllers do
|
1714
1749
|
get('/foo/') { "this is foo" }
|
@@ -1723,7 +1758,7 @@ describe "Routing" do
|
|
1723
1758
|
assert_equal "/foo/5/10", body
|
1724
1759
|
end
|
1725
1760
|
|
1726
|
-
should
|
1761
|
+
it 'should index routes should be optional when nested' do
|
1727
1762
|
mock_app do
|
1728
1763
|
controller '/users', :provides => [:json] do
|
1729
1764
|
get '/' do
|
@@ -1735,7 +1770,7 @@ describe "Routing" do
|
|
1735
1770
|
assert_equal "foo", body
|
1736
1771
|
end
|
1737
1772
|
|
1738
|
-
should
|
1773
|
+
it 'should use provides as conditional' do
|
1739
1774
|
mock_app do
|
1740
1775
|
provides :json
|
1741
1776
|
get "/" do
|
@@ -1746,7 +1781,9 @@ describe "Routing" do
|
|
1746
1781
|
assert_equal "foo", body
|
1747
1782
|
end
|
1748
1783
|
|
1749
|
-
|
1784
|
+
it 'should reset provides for routes that did not use it' do
|
1785
|
+
skip
|
1786
|
+
#FIXME
|
1750
1787
|
mock_app do
|
1751
1788
|
get('/foo', :provides => :js){}
|
1752
1789
|
get('/bar'){}
|
@@ -1761,7 +1798,7 @@ describe "Routing" do
|
|
1761
1798
|
assert_equal 404, status
|
1762
1799
|
end
|
1763
1800
|
|
1764
|
-
should
|
1801
|
+
it 'should pass controller conditions to each route' do
|
1765
1802
|
counter = 0
|
1766
1803
|
|
1767
1804
|
mock_app do
|
@@ -1781,7 +1818,7 @@ describe "Routing" do
|
|
1781
1818
|
assert_equal 2, counter
|
1782
1819
|
end
|
1783
1820
|
|
1784
|
-
should
|
1821
|
+
it 'should allow controller conditions to be overridden' do
|
1785
1822
|
counter = 0
|
1786
1823
|
|
1787
1824
|
mock_app do
|
@@ -1801,7 +1838,7 @@ describe "Routing" do
|
|
1801
1838
|
assert_equal 1, counter
|
1802
1839
|
end
|
1803
1840
|
|
1804
|
-
should
|
1841
|
+
it 'should parse params with class level provides' do
|
1805
1842
|
mock_app do
|
1806
1843
|
controllers :posts, :provides => [:html, :js] do
|
1807
1844
|
post(:create, :map => "/foo/:bar/:baz/:id") {
|
@@ -1823,7 +1860,7 @@ describe "Routing" do
|
|
1823
1860
|
assert_equal "POST CREATE bar - baz - 5", body
|
1824
1861
|
end
|
1825
1862
|
|
1826
|
-
should
|
1863
|
+
it 'should parse params properly with inline provides' do
|
1827
1864
|
mock_app do
|
1828
1865
|
controllers :posts do
|
1829
1866
|
post(:create, :map => "/foo/:bar/:baz/:id", :provides => [:html, :js]) {
|
@@ -1841,7 +1878,7 @@ describe "Routing" do
|
|
1841
1878
|
assert_equal "POST CREATE bar - baz - 5", body, "should properly post to create action"
|
1842
1879
|
end
|
1843
1880
|
|
1844
|
-
should
|
1881
|
+
it 'should have overideable format' do
|
1845
1882
|
::Rack::Mime::MIME_TYPES[".other"] = "text/html"
|
1846
1883
|
mock_app do
|
1847
1884
|
before do
|
@@ -1854,7 +1891,7 @@ describe "Routing" do
|
|
1854
1891
|
::Rack::Mime::MIME_TYPES.delete('.other')
|
1855
1892
|
end
|
1856
1893
|
|
1857
|
-
should
|
1894
|
+
it 'should invokes handlers registered with ::error when raised' do
|
1858
1895
|
mock_app do
|
1859
1896
|
set :raise_errors, false
|
1860
1897
|
error(FooError) { 'Foo!' }
|
@@ -1867,7 +1904,7 @@ describe "Routing" do
|
|
1867
1904
|
assert_equal 'Foo!', body
|
1868
1905
|
end
|
1869
1906
|
|
1870
|
-
should
|
1907
|
+
it 'should have MethodOverride middleware' do
|
1871
1908
|
mock_app do
|
1872
1909
|
put('/') { 'okay' }
|
1873
1910
|
end
|
@@ -1877,7 +1914,7 @@ describe "Routing" do
|
|
1877
1914
|
assert_equal 'okay', body
|
1878
1915
|
end
|
1879
1916
|
|
1880
|
-
should
|
1917
|
+
it 'should return value from params' do
|
1881
1918
|
mock_app do
|
1882
1919
|
get("/foo/:bar"){ raise "'bar' should be a string" unless params[:bar].kind_of? String}
|
1883
1920
|
end
|
@@ -1885,7 +1922,7 @@ describe "Routing" do
|
|
1885
1922
|
assert ok?
|
1886
1923
|
end
|
1887
1924
|
|
1888
|
-
should
|
1925
|
+
it 'should return params as a HashWithIndifferentAccess object via GET' do
|
1889
1926
|
mock_app do
|
1890
1927
|
get('/foo/:bar') { "#{params["bar"]} #{params[:bar]}" }
|
1891
1928
|
get(:foo, :map => '/prefix/:var') { "#{params["var"]} #{params[:var]}" }
|
@@ -1898,7 +1935,7 @@ describe "Routing" do
|
|
1898
1935
|
assert_equal "var var", body
|
1899
1936
|
end
|
1900
1937
|
|
1901
|
-
should
|
1938
|
+
it 'should return params as a HashWithIndifferentAccess object via POST' do
|
1902
1939
|
mock_app do
|
1903
1940
|
post('/user') do
|
1904
1941
|
"#{params["user"]["full_name"]} #{params[:user][:full_name]}"
|
@@ -1912,7 +1949,7 @@ describe "Routing" do
|
|
1912
1949
|
assert_equal "example user example user", body
|
1913
1950
|
end
|
1914
1951
|
|
1915
|
-
should
|
1952
|
+
it 'should have MethodOverride middleware with more options' do
|
1916
1953
|
mock_app do
|
1917
1954
|
put('/hi', :provides => [:json]) { 'hi' }
|
1918
1955
|
end
|
@@ -1926,7 +1963,7 @@ describe "Routing" do
|
|
1926
1963
|
assert_equal 405, status
|
1927
1964
|
end
|
1928
1965
|
|
1929
|
-
should
|
1966
|
+
it 'should parse nested params' do
|
1930
1967
|
mock_app do
|
1931
1968
|
get(:index) { "%s %s" % [params[:account][:name], params[:account][:surname]] }
|
1932
1969
|
end
|
@@ -1936,14 +1973,14 @@ describe "Routing" do
|
|
1936
1973
|
assert_equal 'foo bar', body
|
1937
1974
|
end
|
1938
1975
|
|
1939
|
-
should
|
1976
|
+
it 'should render sinatra NotFound page' do
|
1940
1977
|
mock_app { set :environment, :development }
|
1941
1978
|
get "/"
|
1942
1979
|
assert_equal 404, status
|
1943
1980
|
assert_match %r{(Sinatra doesn’t know this ditty.|<h1>Not Found</h1>)}, body
|
1944
1981
|
end
|
1945
1982
|
|
1946
|
-
should
|
1983
|
+
it 'should render a custom NotFound page' do
|
1947
1984
|
mock_app do
|
1948
1985
|
error(Sinatra::NotFound) { "not found" }
|
1949
1986
|
end
|
@@ -1952,7 +1989,7 @@ describe "Routing" do
|
|
1952
1989
|
assert_match /not found/, body
|
1953
1990
|
end
|
1954
1991
|
|
1955
|
-
should
|
1992
|
+
it 'should render a custom 404 page using not_found' do
|
1956
1993
|
mock_app do
|
1957
1994
|
not_found { "custom 404 not found" }
|
1958
1995
|
end
|
@@ -1961,8 +1998,7 @@ describe "Routing" do
|
|
1961
1998
|
assert_equal "custom 404 not found", body
|
1962
1999
|
end
|
1963
2000
|
|
1964
|
-
should
|
1965
|
-
skip # TODO sinatra bug?
|
2001
|
+
it 'should render a custom error page using error method' do
|
1966
2002
|
mock_app do
|
1967
2003
|
error(404) { "custom 404 error" }
|
1968
2004
|
end
|
@@ -1971,7 +2007,7 @@ describe "Routing" do
|
|
1971
2007
|
assert_equal "custom 404 error", body
|
1972
2008
|
end
|
1973
2009
|
|
1974
|
-
should
|
2010
|
+
it 'should render a custom 403 page' do
|
1975
2011
|
mock_app do
|
1976
2012
|
error(403) { "custom 403 not found" }
|
1977
2013
|
get("/") { status 403 }
|
@@ -1981,7 +2017,7 @@ describe "Routing" do
|
|
1981
2017
|
assert_equal "custom 403 not found", body
|
1982
2018
|
end
|
1983
2019
|
|
1984
|
-
should
|
2020
|
+
it 'should recognize paths' do
|
1985
2021
|
mock_app do
|
1986
2022
|
controller :foo do
|
1987
2023
|
get(:bar, :map => "/my/:id/custom-route") { }
|
@@ -1999,7 +2035,7 @@ describe "Routing" do
|
|
1999
2035
|
assert_equal [:with_format, { :id => "9", :format => "js" }], @app.recognize_path(@app.url(:with_format, :id => 9, :format => :js))
|
2000
2036
|
end
|
2001
2037
|
|
2002
|
-
should
|
2038
|
+
it 'should have current_path' do
|
2003
2039
|
mock_app do
|
2004
2040
|
controller :foo do
|
2005
2041
|
get(:index) { current_path }
|
@@ -2017,7 +2053,7 @@ describe "Routing" do
|
|
2017
2053
|
assert_equal "/foo", body
|
2018
2054
|
end
|
2019
2055
|
|
2020
|
-
should
|
2056
|
+
it 'should accept :map and :parent' do
|
2021
2057
|
mock_app do
|
2022
2058
|
controller :posts do
|
2023
2059
|
get :show, :parent => :users, :map => "posts/:id" do
|
@@ -2029,7 +2065,7 @@ describe "Routing" do
|
|
2029
2065
|
assert_equal "123-321", body
|
2030
2066
|
end
|
2031
2067
|
|
2032
|
-
should
|
2068
|
+
it 'should change params in current_path' do
|
2033
2069
|
mock_app do
|
2034
2070
|
get :index, :map => "/paginate/:page" do
|
2035
2071
|
current_path(:page => 66)
|
@@ -2039,7 +2075,7 @@ describe "Routing" do
|
|
2039
2075
|
assert_equal "/paginate/66", body
|
2040
2076
|
end
|
2041
2077
|
|
2042
|
-
should
|
2078
|
+
it 'should not route get :users, :with => :id to /users//' do
|
2043
2079
|
mock_app do
|
2044
2080
|
get(:users, :with => :id) { 'boo' }
|
2045
2081
|
end
|