actionpack 1.8.1 → 1.9.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of actionpack might be problematic. Click here for more details.
- data/CHANGELOG +309 -16
- data/README +1 -1
- data/lib/action_controller.rb +5 -0
- data/lib/action_controller/assertions.rb +57 -12
- data/lib/action_controller/auto_complete.rb +47 -0
- data/lib/action_controller/base.rb +288 -258
- data/lib/action_controller/benchmarking.rb +8 -3
- data/lib/action_controller/caching.rb +88 -42
- data/lib/action_controller/cgi_ext/cgi_ext.rb +1 -1
- data/lib/action_controller/cgi_ext/cgi_methods.rb +41 -11
- data/lib/action_controller/cgi_ext/multipart_progress.rb +169 -0
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +30 -12
- data/lib/action_controller/cgi_process.rb +39 -11
- data/lib/action_controller/code_generation.rb +235 -0
- data/lib/action_controller/cookies.rb +14 -8
- data/lib/action_controller/deprecated_renders_and_redirects.rb +76 -0
- data/lib/action_controller/filters.rb +8 -7
- data/lib/action_controller/helpers.rb +41 -6
- data/lib/action_controller/layout.rb +45 -16
- data/lib/action_controller/request.rb +86 -23
- data/lib/action_controller/rescue.rb +1 -0
- data/lib/action_controller/response.rb +1 -1
- data/lib/action_controller/routing.rb +536 -272
- data/lib/action_controller/scaffolding.rb +30 -25
- data/lib/action_controller/session/active_record_store.rb +251 -50
- data/lib/action_controller/streaming.rb +133 -0
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +0 -7
- data/lib/action_controller/templates/scaffolds/edit.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/layout.rhtml +22 -18
- data/lib/action_controller/templates/scaffolds/list.rhtml +3 -3
- data/lib/action_controller/templates/scaffolds/new.rhtml +2 -2
- data/lib/action_controller/templates/scaffolds/show.rhtml +1 -1
- data/lib/action_controller/test_process.rb +68 -47
- data/lib/action_controller/upload_progress.rb +421 -0
- data/lib/action_controller/url_rewriter.rb +8 -11
- data/lib/action_controller/vendor/html-scanner/html/document.rb +6 -5
- data/lib/action_controller/vendor/html-scanner/html/node.rb +70 -14
- data/lib/action_controller/vendor/html-scanner/html/tokenizer.rb +17 -10
- data/lib/action_controller/vendor/html-scanner/html/version.rb +3 -3
- data/lib/action_controller/vendor/xml_simple.rb +1019 -0
- data/lib/action_controller/verification.rb +36 -30
- data/lib/action_view/base.rb +21 -14
- data/lib/action_view/helpers/active_record_helper.rb +15 -13
- data/lib/action_view/helpers/asset_tag_helper.rb +26 -9
- data/lib/action_view/helpers/benchmark_helper.rb +24 -0
- data/lib/action_view/helpers/capture_helper.rb +7 -5
- data/lib/action_view/helpers/date_helper.rb +63 -46
- data/lib/action_view/helpers/form_helper.rb +7 -1
- data/lib/action_view/helpers/form_options_helper.rb +19 -11
- data/lib/action_view/helpers/form_tag_helper.rb +5 -1
- data/lib/action_view/helpers/javascript_helper.rb +403 -35
- data/lib/action_view/helpers/javascripts/controls.js +261 -0
- data/lib/action_view/helpers/javascripts/dragdrop.js +476 -0
- data/lib/action_view/helpers/javascripts/effects.js +570 -0
- data/lib/action_view/helpers/javascripts/prototype.js +633 -371
- data/lib/action_view/helpers/number_helper.rb +11 -13
- data/lib/action_view/helpers/tag_helper.rb +1 -2
- data/lib/action_view/helpers/text_helper.rb +69 -6
- data/lib/action_view/helpers/upload_progress_helper.rb +433 -0
- data/lib/action_view/helpers/url_helper.rb +98 -3
- data/lib/action_view/partials.rb +14 -8
- data/lib/action_view/vendor/builder/xmlmarkup.rb +11 -0
- data/rakefile +13 -5
- data/test/abstract_unit.rb +1 -1
- data/test/controller/action_pack_assertions_test.rb +52 -9
- data/test/controller/active_record_assertions_test.rb +119 -120
- data/test/controller/active_record_store_test.rb +111 -0
- data/test/controller/addresses_render_test.rb +45 -0
- data/test/controller/caching_filestore.rb +92 -0
- data/test/controller/capture_test.rb +39 -0
- data/test/controller/cgi_test.rb +40 -3
- data/test/controller/helper_test.rb +65 -13
- data/test/controller/multipart_progress_testx.rb +365 -0
- data/test/controller/new_render_test.rb +263 -0
- data/test/controller/redirect_test.rb +64 -0
- data/test/controller/render_test.rb +20 -21
- data/test/controller/request_test.rb +83 -3
- data/test/controller/routing_test.rb +702 -0
- data/test/controller/send_file_test.rb +2 -0
- data/test/controller/test_test.rb +44 -8
- data/test/controller/upload_progress_testx.rb +89 -0
- data/test/controller/verification_test.rb +94 -29
- data/test/fixtures/addresses/list.rhtml +1 -0
- data/test/fixtures/test/capturing.rhtml +4 -0
- data/test/fixtures/test/list.rhtml +1 -1
- data/test/fixtures/test/update_element_with_capture.rhtml +9 -0
- data/test/template/active_record_helper_test.rb +30 -15
- data/test/template/asset_tag_helper_test.rb +12 -5
- data/test/template/benchmark_helper_test.rb +72 -0
- data/test/template/date_helper_test.rb +69 -0
- data/test/template/form_helper_test.rb +18 -10
- data/test/template/form_options_helper_test.rb +40 -5
- data/test/template/javascript_helper.rb +149 -2
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +4 -0
- data/test/template/text_helper_test.rb +36 -0
- data/test/template/upload_progress_helper_testx.rb +272 -0
- data/test/template/url_helper_test.rb +30 -0
- metadata +30 -6
- data/test/controller/layout_test.rb +0 -49
- data/test/controller/routing_tests.rb +0 -543
@@ -21,6 +21,28 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
21
21
|
end
|
22
22
|
|
23
23
|
# todo: missing test cases
|
24
|
+
def test_button_to_with_straight_url
|
25
|
+
assert_equal "<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>", button_to("Hello", "http://www.example.com")
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_button_to_with_javascript_confirm
|
29
|
+
assert_equal(
|
30
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input onclick=\"return confirm('Are you sure?');\" type=\"submit\" value=\"Hello\" /></div></form>",
|
31
|
+
button_to("Hello", "http://www.example.com", :confirm => "Are you sure?")
|
32
|
+
)
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_button_to_enabled_disabled
|
36
|
+
assert_equal(
|
37
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input type=\"submit\" value=\"Hello\" /></div></form>",
|
38
|
+
button_to("Hello", "http://www.example.com", :disabled => false)
|
39
|
+
)
|
40
|
+
assert_equal(
|
41
|
+
"<form method=\"post\" action=\"http://www.example.com\" class=\"button-to\"><div><input disabled=\"disabled\" type=\"submit\" value=\"Hello\" /></div></form>",
|
42
|
+
button_to("Hello", "http://www.example.com", :disabled => true)
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
24
46
|
def test_link_tag_with_straight_url
|
25
47
|
assert_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", "http://www.example.com")
|
26
48
|
end
|
@@ -94,6 +116,14 @@ class UrlHelperTest < Test::Unit::TestCase
|
|
94
116
|
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex")
|
95
117
|
end
|
96
118
|
|
119
|
+
def test_mail_to_with_replace_options
|
120
|
+
assert_equal "<a href=\"mailto:wolfgang@stufenlos.net\">wolfgang(at)stufenlos(dot)net</a>", mail_to("wolfgang@stufenlos.net", nil, :replace_at => "(at)", :replace_dot => "(dot)")
|
121
|
+
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain.com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)")
|
122
|
+
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">My email</a>", mail_to("me@domain.com", "My email", :encode => "hex", :replace_at => "(at)")
|
123
|
+
assert_equal "<a href=\"mailto:%6d%65@%64%6f%6d%61%69%6e.%63%6f%6d\">me(at)domain(dot)com</a>", mail_to("me@domain.com", nil, :encode => "hex", :replace_at => "(at)", :replace_dot => "(dot)")
|
124
|
+
assert_equal "<script type=\"text/javascript\" language=\"javascript\">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%6d%65%40%64%6f%6d%61%69%6e%2e%63%6f%6d%22%3e%4d%79%20%65%6d%61%69%6c%3c%2f%61%3e%27%29%3b'))</script>", mail_to("me@domain.com", "My email", :encode => "javascript", :replace_at => "(at)", :replace_dot => "(dot)")
|
125
|
+
end
|
126
|
+
|
97
127
|
def test_link_with_nil_html_options
|
98
128
|
assert_equal "<a href=\"http://www.example.com\">Hello</a>", link_to("Hello", {:action => 'myaction'}, nil)
|
99
129
|
end
|
metadata
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
|
-
rubygems_version: 0.8.
|
2
|
+
rubygems_version: 0.8.10
|
3
3
|
specification_version: 1
|
4
4
|
name: actionpack
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 1.
|
7
|
-
date: 2005-
|
6
|
+
version: 1.9.0
|
7
|
+
date: 2005-07-06
|
8
8
|
summary: Web-flow and rendering framework putting the VC in MVC.
|
9
9
|
require_paths:
|
10
10
|
- lib
|
@@ -41,15 +41,18 @@ files:
|
|
41
41
|
- lib/action_view
|
42
42
|
- lib/action_view.rb
|
43
43
|
- lib/action_controller/assertions.rb
|
44
|
+
- lib/action_controller/auto_complete.rb
|
44
45
|
- lib/action_controller/base.rb
|
45
46
|
- lib/action_controller/benchmarking.rb
|
46
47
|
- lib/action_controller/caching.rb
|
47
48
|
- lib/action_controller/cgi_ext
|
48
49
|
- lib/action_controller/cgi_process.rb
|
50
|
+
- lib/action_controller/code_generation.rb
|
49
51
|
- lib/action_controller/components.rb
|
50
52
|
- lib/action_controller/cookies.rb
|
51
53
|
- lib/action_controller/dependencies.rb
|
52
54
|
- lib/action_controller/deprecated_assertions.rb
|
55
|
+
- lib/action_controller/deprecated_renders_and_redirects.rb
|
53
56
|
- lib/action_controller/filters.rb
|
54
57
|
- lib/action_controller/flash.rb
|
55
58
|
- lib/action_controller/helpers.rb
|
@@ -62,14 +65,17 @@ files:
|
|
62
65
|
- lib/action_controller/scaffolding.rb
|
63
66
|
- lib/action_controller/session
|
64
67
|
- lib/action_controller/session.rb
|
68
|
+
- lib/action_controller/streaming.rb
|
65
69
|
- lib/action_controller/templates
|
66
70
|
- lib/action_controller/test_process.rb
|
71
|
+
- lib/action_controller/upload_progress.rb
|
67
72
|
- lib/action_controller/url_rewriter.rb
|
68
73
|
- lib/action_controller/vendor
|
69
74
|
- lib/action_controller/verification.rb
|
70
75
|
- lib/action_controller/cgi_ext/cgi_ext.rb
|
71
76
|
- lib/action_controller/cgi_ext/cgi_methods.rb
|
72
77
|
- lib/action_controller/cgi_ext/cookie_performance_fix.rb
|
78
|
+
- lib/action_controller/cgi_ext/multipart_progress.rb
|
73
79
|
- lib/action_controller/cgi_ext/raw_post_data_fix.rb
|
74
80
|
- lib/action_controller/session/active_record_store.rb
|
75
81
|
- lib/action_controller/session/drb_server.rb
|
@@ -90,6 +96,7 @@ files:
|
|
90
96
|
- lib/action_controller/templates/scaffolds/new.rhtml
|
91
97
|
- lib/action_controller/templates/scaffolds/show.rhtml
|
92
98
|
- lib/action_controller/vendor/html-scanner
|
99
|
+
- lib/action_controller/vendor/xml_simple.rb
|
93
100
|
- lib/action_controller/vendor/html-scanner/html
|
94
101
|
- lib/action_controller/vendor/html-scanner/html/document.rb
|
95
102
|
- lib/action_controller/vendor/html-scanner/html/node.rb
|
@@ -102,6 +109,7 @@ files:
|
|
102
109
|
- lib/action_view/vendor
|
103
110
|
- lib/action_view/helpers/active_record_helper.rb
|
104
111
|
- lib/action_view/helpers/asset_tag_helper.rb
|
112
|
+
- lib/action_view/helpers/benchmark_helper.rb
|
105
113
|
- lib/action_view/helpers/cache_helper.rb
|
106
114
|
- lib/action_view/helpers/capture_helper.rb
|
107
115
|
- lib/action_view/helpers/date_helper.rb
|
@@ -115,7 +123,11 @@ files:
|
|
115
123
|
- lib/action_view/helpers/pagination_helper.rb
|
116
124
|
- lib/action_view/helpers/tag_helper.rb
|
117
125
|
- lib/action_view/helpers/text_helper.rb
|
126
|
+
- lib/action_view/helpers/upload_progress_helper.rb
|
118
127
|
- lib/action_view/helpers/url_helper.rb
|
128
|
+
- lib/action_view/helpers/javascripts/controls.js
|
129
|
+
- lib/action_view/helpers/javascripts/dragdrop.js
|
130
|
+
- lib/action_view/helpers/javascripts/effects.js
|
119
131
|
- lib/action_view/helpers/javascripts/prototype.js
|
120
132
|
- lib/action_view/vendor/builder
|
121
133
|
- lib/action_view/vendor/builder.rb
|
@@ -129,7 +141,11 @@ files:
|
|
129
141
|
- test/template
|
130
142
|
- test/controller/action_pack_assertions_test.rb
|
131
143
|
- test/controller/active_record_assertions_test.rb
|
144
|
+
- test/controller/active_record_store_test.rb
|
145
|
+
- test/controller/addresses_render_test.rb
|
132
146
|
- test/controller/base_tests.rb
|
147
|
+
- test/controller/caching_filestore.rb
|
148
|
+
- test/controller/capture_test.rb
|
133
149
|
- test/controller/cgi_test.rb
|
134
150
|
- test/controller/components_test.rb
|
135
151
|
- test/controller/cookie_test.rb
|
@@ -137,20 +153,24 @@ files:
|
|
137
153
|
- test/controller/filters_test.rb
|
138
154
|
- test/controller/flash_test.rb
|
139
155
|
- test/controller/helper_test.rb
|
140
|
-
- test/controller/
|
156
|
+
- test/controller/multipart_progress_testx.rb
|
157
|
+
- test/controller/new_render_test.rb
|
141
158
|
- test/controller/raw_post_test.rb
|
142
159
|
- test/controller/redirect_test.rb
|
143
160
|
- test/controller/render_test.rb
|
144
161
|
- test/controller/request_test.rb
|
145
|
-
- test/controller/
|
162
|
+
- test/controller/routing_test.rb
|
146
163
|
- test/controller/send_file_test.rb
|
147
164
|
- test/controller/test_test.rb
|
165
|
+
- test/controller/upload_progress_testx.rb
|
148
166
|
- test/controller/verification_test.rb
|
167
|
+
- test/fixtures/addresses
|
149
168
|
- test/fixtures/fun
|
150
169
|
- test/fixtures/helpers
|
151
170
|
- test/fixtures/layouts
|
152
171
|
- test/fixtures/scope
|
153
172
|
- test/fixtures/test
|
173
|
+
- test/fixtures/addresses/list.rhtml
|
154
174
|
- test/fixtures/fun/games
|
155
175
|
- test/fixtures/fun/games/hello_world.rhtml
|
156
176
|
- test/fixtures/helpers/abc_helper.rb
|
@@ -162,13 +182,16 @@ files:
|
|
162
182
|
- test/fixtures/scope/test/modgreet.rhtml
|
163
183
|
- test/fixtures/test/_customer.rhtml
|
164
184
|
- test/fixtures/test/_partial_only.rhtml
|
185
|
+
- test/fixtures/test/capturing.rhtml
|
165
186
|
- test/fixtures/test/greeting.rhtml
|
166
187
|
- test/fixtures/test/hello.rxml
|
167
188
|
- test/fixtures/test/hello_world.rhtml
|
168
189
|
- test/fixtures/test/hello_xml_world.rxml
|
169
190
|
- test/fixtures/test/list.rhtml
|
191
|
+
- test/fixtures/test/update_element_with_capture.rhtml
|
170
192
|
- test/template/active_record_helper_test.rb
|
171
193
|
- test/template/asset_tag_helper_test.rb
|
194
|
+
- test/template/benchmark_helper_test.rb
|
172
195
|
- test/template/date_helper_test.rb
|
173
196
|
- test/template/form_helper_test.rb
|
174
197
|
- test/template/form_options_helper_test.rb
|
@@ -177,6 +200,7 @@ files:
|
|
177
200
|
- test/template/number_helper_test.rb
|
178
201
|
- test/template/tag_helper_test.rb
|
179
202
|
- test/template/text_helper_test.rb
|
203
|
+
- test/template/upload_progress_helper_testx.rb
|
180
204
|
- test/template/url_helper_test.rb
|
181
205
|
- examples/address_book
|
182
206
|
- examples/address_book_controller.cgi
|
@@ -209,5 +233,5 @@ dependencies:
|
|
209
233
|
-
|
210
234
|
- "="
|
211
235
|
- !ruby/object:Gem::Version
|
212
|
-
version: 1.0
|
236
|
+
version: 1.1.0
|
213
237
|
version:
|
@@ -1,49 +0,0 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
-
|
3
|
-
class TestLayoutController < ActionController::Base
|
4
|
-
layout "layouts/standard"
|
5
|
-
|
6
|
-
def hello_world
|
7
|
-
end
|
8
|
-
|
9
|
-
def hello_world_outside_layout
|
10
|
-
end
|
11
|
-
|
12
|
-
def rescue_action(e) raise end
|
13
|
-
end
|
14
|
-
|
15
|
-
class ChildWithoutTestLayoutController < TestLayoutController
|
16
|
-
layout nil
|
17
|
-
|
18
|
-
def hello_world
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
class ChildWithOtherTestLayoutController < TestLayoutController
|
23
|
-
layout nil
|
24
|
-
|
25
|
-
def hello_world
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
class RenderTest < Test::Unit::TestCase
|
30
|
-
def setup
|
31
|
-
@request = ActionController::TestRequest.new
|
32
|
-
@response = ActionController::TestResponse.new
|
33
|
-
|
34
|
-
@request.host = "www.nextangle.com"
|
35
|
-
end
|
36
|
-
|
37
|
-
def test_layout_rendering
|
38
|
-
@request.action = "hello_world"
|
39
|
-
response = process_request
|
40
|
-
assert_equal "200 OK", response.headers["Status"]
|
41
|
-
assert_equal "layouts/standard", response.template.template_name
|
42
|
-
end
|
43
|
-
|
44
|
-
|
45
|
-
private
|
46
|
-
def process_request
|
47
|
-
TestLayoutController.process(@request, @response)
|
48
|
-
end
|
49
|
-
end
|
@@ -1,543 +0,0 @@
|
|
1
|
-
# Code Generated by ZenTest v. 2.3.0
|
2
|
-
# Couldn't find class for name Routing
|
3
|
-
# classname: asrt / meth = ratio%
|
4
|
-
# ActionController::Routing::RouteSet: 0 / 16 = 0.00%
|
5
|
-
# ActionController::Routing::RailsRoute: 0 / 4 = 0.00%
|
6
|
-
# ActionController::Routing::Route: 0 / 8 = 0.00%
|
7
|
-
|
8
|
-
require File.dirname(__FILE__) + '/../abstract_unit'
|
9
|
-
require 'test/unit'
|
10
|
-
require 'cgi'
|
11
|
-
|
12
|
-
class FakeController
|
13
|
-
attr_reader :controller_path
|
14
|
-
attr_reader :name
|
15
|
-
def initialize(name, controller_path)
|
16
|
-
@name = name
|
17
|
-
@controller_path = controller_path
|
18
|
-
end
|
19
|
-
def kind_of?(x)
|
20
|
-
x === Class || x == FakeController
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
module Controllers
|
25
|
-
module Admin
|
26
|
-
UserController = FakeController.new 'Admin::UserController', 'admin/user'
|
27
|
-
AccessController = FakeController.new 'Admin::AccessController', 'admin/access'
|
28
|
-
end
|
29
|
-
module Editing
|
30
|
-
PageController = FakeController.new 'Editing::PageController', 'editing/page'
|
31
|
-
ImageController = FakeController.new 'Editing::ImageController', 'editing/image'
|
32
|
-
end
|
33
|
-
module User
|
34
|
-
NewsController = FakeController.new 'User::NewsController', 'user/news'
|
35
|
-
PaymentController = FakeController.new 'User::PaymentController', 'user/payment'
|
36
|
-
end
|
37
|
-
ContentController = FakeController.new 'ContentController', 'content'
|
38
|
-
ResourceController = FakeController.new 'ResourceController', 'resource'
|
39
|
-
end
|
40
|
-
|
41
|
-
# Extend the modules with the required methods...
|
42
|
-
[Controllers, Controllers::Admin, Controllers::Editing, Controllers::User].each do |mod|
|
43
|
-
mod.instance_eval('alias :const_available? :const_defined?')
|
44
|
-
mod.constants.each {|k| Object.const_set(k, mod.const_get(k))} # export the modules & controller classes.
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
class RouteTests < Test::Unit::TestCase
|
49
|
-
def route(*args)
|
50
|
-
return @route if @route && (args.empty? || @args == args)
|
51
|
-
@args = args
|
52
|
-
@route = ActionController::Routing::Route.new(*args)
|
53
|
-
return @route
|
54
|
-
end
|
55
|
-
|
56
|
-
def setup
|
57
|
-
self.route '/:controller/:action/:id'
|
58
|
-
@defaults = {:controller => 'content', :action => 'show', :id => '314'}
|
59
|
-
end
|
60
|
-
|
61
|
-
# Don't put a leading / on the url.
|
62
|
-
# Make sure the controller is one from the above fake Controllers module.
|
63
|
-
def verify_recognize(url, expected_options, reason='')
|
64
|
-
url = url.split('/') if url.kind_of? String
|
65
|
-
reason = ": #{reason}" unless reason.empty?
|
66
|
-
controller_class, options = @route.recognize(url)
|
67
|
-
assert_not_equal nil, controller_class, "#{@route.inspect} didn't recognize #{url}#{reason}\n #{options}"
|
68
|
-
assert_equal expected_options, options, "#{@route.inspect} produced wrong options for #{url}#{reason}"
|
69
|
-
end
|
70
|
-
|
71
|
-
# The expected url should not have a leading /
|
72
|
-
# You can use @defaults if you want a set of plausible defaults
|
73
|
-
def verify_generate(expected_url, expected_extras, options, defaults, reason='')
|
74
|
-
reason = "#{reason}: " unless reason.empty?
|
75
|
-
components, extras = @route.generate(options, defaults)
|
76
|
-
assert_not_equal nil, components, "#{reason}#{@route.inspect} didn't generate for \n options = #{options.inspect}\n defaults = #{defaults.inspect}\n #{extras}"
|
77
|
-
assert_equal expected_extras, extras, "#{reason} #{@route.inspect}.generate: incorrect extra's"
|
78
|
-
assert_equal expected_url, components.join('/'), "#{reason} #{@route.inspect}.generate: incorrect url"
|
79
|
-
end
|
80
|
-
|
81
|
-
def test_recognize_default_unnested_with_action_and_id
|
82
|
-
verify_recognize('content/action/id', {:controller => 'content', :action => 'action', :id => 'id'})
|
83
|
-
verify_recognize('content/show/10', {:controller => 'content', :action => 'show', :id => '10'})
|
84
|
-
end
|
85
|
-
def test_generate_default_unnested_with_action_and_id_no_extras
|
86
|
-
verify_generate('content/action/id', {}, {:controller => 'content', :action => 'action', :id => 'id'}, @defaults)
|
87
|
-
verify_generate('content/show/10', {}, {:controller => 'content', :action => 'show', :id => '10'}, @defaults)
|
88
|
-
end
|
89
|
-
def test_generate_default_unnested_with_action_and_id
|
90
|
-
verify_generate('content/action/id', {:a => 'a'}, {:controller => 'content', :action => 'action', :id => 'id', :a => 'a'}, @defaults)
|
91
|
-
verify_generate('content/show/10', {:a => 'a'}, {:controller => 'content', :action => 'show', :id => '10', :a => 'a'}, @defaults)
|
92
|
-
end
|
93
|
-
|
94
|
-
# Note that we can't put tests here for proper relative controller handline
|
95
|
-
# because that is handled by RouteSet.
|
96
|
-
def test_recognize_default_nested_with_action_and_id
|
97
|
-
verify_recognize('admin/user/action/id', {:controller => 'admin/user', :action => 'action', :id => 'id'})
|
98
|
-
verify_recognize('admin/user/show/10', {:controller => 'admin/user', :action => 'show', :id => '10'})
|
99
|
-
end
|
100
|
-
def test_generate_default_nested_with_action_and_id_no_extras
|
101
|
-
verify_generate('admin/user/action/id', {}, {:controller => 'admin/user', :action => 'action', :id => 'id'}, @defaults)
|
102
|
-
verify_generate('admin/user/show/10', {}, {:controller => 'admin/user', :action => 'show', :id => '10'}, @defaults)
|
103
|
-
end
|
104
|
-
def test_generate_default_nested_with_action_and_id_relative_to_root
|
105
|
-
verify_generate('admin/user/action/id', {:a => 'a'}, {:controller => 'admin/user', :action => 'action', :id => 'id', :a => 'a'}, @defaults)
|
106
|
-
verify_generate('admin/user/show/10', {:a => 'a'}, {:controller => 'admin/user', :action => 'show', :id => '10', :a => 'a'}, @defaults)
|
107
|
-
end
|
108
|
-
|
109
|
-
def test_recognize_default_nested_with_action
|
110
|
-
verify_recognize('admin/user/action', {:controller => 'admin/user', :action => 'action'})
|
111
|
-
verify_recognize('admin/user/show', {:controller => 'admin/user', :action => 'show'})
|
112
|
-
end
|
113
|
-
def test_generate_default_nested_with_action_no_extras
|
114
|
-
verify_generate('admin/user/action', {}, {:controller => 'admin/user', :action => 'action'}, @defaults)
|
115
|
-
verify_generate('admin/user/show', {}, {:controller => 'admin/user', :action => 'show'}, @defaults)
|
116
|
-
end
|
117
|
-
def test_generate_default_nested_with_action
|
118
|
-
verify_generate('admin/user/action', {:a => 'a'}, {:controller => 'admin/user', :action => 'action', :a => 'a'}, @defaults)
|
119
|
-
verify_generate('admin/user/show', {:a => 'a'}, {:controller => 'admin/user', :action => 'show', :a => 'a'}, @defaults)
|
120
|
-
end
|
121
|
-
|
122
|
-
def test_recognize_default_nested_with_id_and_index
|
123
|
-
verify_recognize('admin/user/index/hello', {:controller => 'admin/user', :id => 'hello', :action => 'index'})
|
124
|
-
verify_recognize('admin/user/index/10', {:controller => 'admin/user', :id => "10", :action => 'index'})
|
125
|
-
end
|
126
|
-
def test_generate_default_nested_with_id_no_extras
|
127
|
-
verify_generate('admin/user/index/hello', {}, {:controller => 'admin/user', :id => 'hello'}, @defaults)
|
128
|
-
verify_generate('admin/user/index/10', {}, {:controller => 'admin/user', :id => 10}, @defaults)
|
129
|
-
end
|
130
|
-
def test_generate_default_nested_with_id
|
131
|
-
verify_generate('admin/user/index/hello', {:a => 'a'}, {:controller => 'admin/user', :id => 'hello', :a => 'a'}, @defaults)
|
132
|
-
verify_generate('admin/user/index/10', {:a => 'a'}, {:controller => 'admin/user', :id => 10, :a => 'a'}, @defaults)
|
133
|
-
end
|
134
|
-
|
135
|
-
def test_recognize_default_nested
|
136
|
-
verify_recognize('admin/user', {:controller => 'admin/user', :action => 'index'})
|
137
|
-
verify_recognize('admin/user', {:controller => 'admin/user', :action => 'index'})
|
138
|
-
end
|
139
|
-
def test_generate_default_nested_no_extras
|
140
|
-
verify_generate('admin/user', {}, {:controller => 'admin/user'}, @defaults)
|
141
|
-
verify_generate('admin/user', {}, {:controller => 'admin/user'}, @defaults)
|
142
|
-
end
|
143
|
-
def test_generate_default_nested
|
144
|
-
verify_generate('admin/user', {:a => 'a'}, {:controller => 'admin/user', :a => 'a'}, @defaults)
|
145
|
-
verify_generate('admin/user', {:a => 'a'}, {:controller => 'admin/user', :a => 'a'}, @defaults)
|
146
|
-
end
|
147
|
-
|
148
|
-
# Test generate with a default controller set.
|
149
|
-
def test_generate_default_controller
|
150
|
-
route '/:controller/:action/:id', :action => 'index', :id => nil, :controller => 'content'
|
151
|
-
@defaults[:controller] = 'resource'
|
152
|
-
|
153
|
-
verify_generate('', {}, {:controller => 'content'}, @defaults)
|
154
|
-
verify_generate('', {}, {:controller => 'content', :action => 'index'}, @defaults)
|
155
|
-
verify_generate('content/not-index', {}, {:controller => 'content', :action => 'not-index'}, @defaults)
|
156
|
-
verify_generate('content/index/10', {}, {:controller => 'content', :id => 10}, @defaults)
|
157
|
-
verify_generate('content/index/hi', {}, {:controller => 'content', :action => 'index', :id => 'hi'}, @defaults)
|
158
|
-
verify_generate('', {:a => 'a'}, {:controller => 'content', :a => 'a'}, @defaults)
|
159
|
-
verify_generate('', {:a => 'a'}, {:controller => 'content', :a => 'a'}, @defaults)
|
160
|
-
|
161
|
-
# Call some other generator tests
|
162
|
-
test_generate_default_unnested_with_action_and_id
|
163
|
-
test_generate_default_nested_with_action_and_id_no_extras
|
164
|
-
test_generate_default_nested_with_id
|
165
|
-
test_generate_default_nested_with_id_no_extras
|
166
|
-
end
|
167
|
-
|
168
|
-
# Test generate with a default controller set.
|
169
|
-
def test_generate_default_controller
|
170
|
-
route '/:controller/:action/:id', :action => 'index', :id => nil, :controller => 'content'
|
171
|
-
@defaults[:controller] = 'resource'
|
172
|
-
verify_recognize('', {:controller => 'content', :action => 'index'})
|
173
|
-
verify_recognize('content', {:controller => 'content', :action => 'index'})
|
174
|
-
verify_recognize('content/index', {:controller => 'content', :action => 'index'})
|
175
|
-
verify_recognize('content/index/10', {:controller => 'content', :action => 'index', :id => '10'})
|
176
|
-
end
|
177
|
-
# Make sure generation & recognition don't happen in some cases:
|
178
|
-
def test_no_generate_on_no_options
|
179
|
-
assert_equal nil, @route.generate({}, {})[0]
|
180
|
-
end
|
181
|
-
def test_requirements
|
182
|
-
route 'some_static/route', :controller => 'content'
|
183
|
-
assert_equal nil, @route.generate({}, {})[0]
|
184
|
-
assert_equal nil, @route.generate({:controller => "dog"}, {})[0]
|
185
|
-
assert_equal nil, @route.recognize([])[0]
|
186
|
-
assert_equal nil, @route.recognize(%w{some_static route with more than expected})[0]
|
187
|
-
end
|
188
|
-
|
189
|
-
def test_basecamp
|
190
|
-
route 'clients/', :controller => 'content'
|
191
|
-
verify_generate('clients', {}, {:controller => 'content'}, {}) # Would like to have clients/
|
192
|
-
verify_generate('clients', {}, {:controller => 'content'}, @defaults)
|
193
|
-
end
|
194
|
-
|
195
|
-
def test_regexp_requirements
|
196
|
-
const_options = {:controller => 'content', :action => 'by_date'}
|
197
|
-
route ':year/:month/:day', const_options.merge(:year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/)
|
198
|
-
verify_recognize('2004/01/02', const_options.merge(:year => '2004', :month => '01', :day => '02'))
|
199
|
-
verify_recognize('2004/1/2', const_options.merge(:year => '2004', :month => '1', :day => '2'))
|
200
|
-
assert_equal nil, @route.recognize(%w{200 10 10})[0]
|
201
|
-
assert_equal nil, @route.recognize(%w{content show 10})[0]
|
202
|
-
|
203
|
-
verify_generate('2004/01/02', {}, const_options.merge(:year => '2004', :month => '01', :day => '02'), @defaults)
|
204
|
-
verify_generate('2004/1/2', {}, const_options.merge(:year => '2004', :month => '1', :day => '2'), @defaults)
|
205
|
-
assert_equal nil, @route.generate(const_options.merge(:year => '12004', :month => '01', :day => '02'), @defaults)[0]
|
206
|
-
end
|
207
|
-
|
208
|
-
def test_regexp_requirement_not_in_path
|
209
|
-
assert_raises(ArgumentError) {route 'constant/path', :controller => 'content', :action => 'by_date', :something => /\d+/}
|
210
|
-
end
|
211
|
-
|
212
|
-
def test_special_hash_names
|
213
|
-
route ':year/:name', :requirements => {:year => /\d{4}/, :controller => 'content'}, :defaults => {:name => 'ulysses'}, :action => 'show_bio_year'
|
214
|
-
verify_generate('1984', {}, {:controller => 'content', :action => 'show_bio_year', :year => 1984}, @defaults)
|
215
|
-
verify_generate('1984', {}, {:controller => 'content', :action => 'show_bio_year', :year => '1984'}, @defaults)
|
216
|
-
verify_generate('1984/odessys', {}, {:controller => 'content', :action => 'show_bio_year', :year => 1984, :name => 'odessys'}, @defaults)
|
217
|
-
verify_generate('1984/odessys', {}, {:controller => 'content', :action => 'show_bio_year', :year => '1984', :name => 'odessys'}, @defaults)
|
218
|
-
|
219
|
-
verify_recognize('1984/odessys', {:controller => 'content', :action => 'show_bio_year', :year => '1984', :name => 'odessys'})
|
220
|
-
verify_recognize('1984', {:controller => 'content', :action => 'show_bio_year', :year => '1984', :name => 'ulysses'})
|
221
|
-
end
|
222
|
-
|
223
|
-
def test_defaults_and_restrictions_for_items_not_in_path
|
224
|
-
assert_raises(ArgumentError) {route ':year/:name', :requirements => {:year => /\d{4}/}, :defaults => {:name => 'ulysses', :controller => 'content'}, :action => 'show_bio_year'}
|
225
|
-
assert_raises(ArgumentError) {route ':year/:name', :requirements => {:year => /\d{4}/, :imagine => /./}, :defaults => {:name => 'ulysses'}, :controller => 'content', :action => 'show_bio_year'}
|
226
|
-
end
|
227
|
-
|
228
|
-
def test_optionals_with_regexp
|
229
|
-
route ':year/:month/:day', :requirements => {:year => /\d{4}/, :month => /\d{1,2}/, :day => /\d{1,2}/},
|
230
|
-
:defaults => {:month => nil, :day => nil},
|
231
|
-
:controller => 'content', :action => 'post_by_day'
|
232
|
-
verify_recognize('2005/06/12', {:controller => 'content', :action => 'post_by_day', :year => '2005', :month => '06', :day => '12'})
|
233
|
-
verify_recognize('2005/06', {:controller => 'content', :action => 'post_by_day', :year => '2005', :month => '06'})
|
234
|
-
verify_recognize('2005', {:controller => 'content', :action => 'post_by_day', :year => '2005'})
|
235
|
-
|
236
|
-
verify_generate('2005/06/12', {}, {:controller => 'content', :action => 'post_by_day', :year => '2005', :month => '06', :day => '12'}, @defaults)
|
237
|
-
verify_generate('2005/06', {}, {:controller => 'content', :action => 'post_by_day', :year => '2005', :month => '06'}, @defaults)
|
238
|
-
verify_generate('2005', {}, {:controller => 'content', :action => 'post_by_day', :year => '2005'}, @defaults)
|
239
|
-
end
|
240
|
-
|
241
|
-
|
242
|
-
def test_basecamp2
|
243
|
-
route 'clients/:client_name/:project_name/', :controller => 'content', :action => 'start_page_redirect'
|
244
|
-
verify_recognize('clients/projects/2', {:controller => 'content', :client_name => 'projects', :project_name => '2', :action => 'start_page_redirect'})
|
245
|
-
end
|
246
|
-
|
247
|
-
def test_xal_style_dates
|
248
|
-
route 'articles/:category/:year/:month/:day', :controller => 'content', :action => 'list_articles', :category => 'all', :year => nil, :month => nil, :day =>nil
|
249
|
-
verify_recognize('articles', {:controller => 'content', :action => 'list_articles', :category => 'all'})
|
250
|
-
verify_recognize('articles/porn', {:controller => 'content', :action => 'list_articles', :category => 'porn'})
|
251
|
-
verify_recognize('articles/news/2005/08', {:controller => 'content', :action => 'list_articles', :category => 'news', :year => '2005', :month => '08'})
|
252
|
-
verify_recognize('articles/news/2005/08/04', {:controller => 'content', :action => 'list_articles', :category => 'news', :year => '2005', :month => '08', :day => '04'})
|
253
|
-
assert_equal nil, @route.recognize(%w{articles too many components are here})[0]
|
254
|
-
assert_equal nil, @route.recognize('')[0]
|
255
|
-
|
256
|
-
verify_generate('articles', {}, {:controller => 'content', :action => 'list_articles'}, @defaults)
|
257
|
-
verify_generate('articles', {}, {:controller => 'content', :action => 'list_articles', :category => 'all'}, @defaults)
|
258
|
-
verify_generate('articles/news', {}, {:controller => 'content', :action => 'list_articles', :category => 'news'}, @defaults)
|
259
|
-
verify_generate('articles/news/2005', {}, {:controller => 'content', :action => 'list_articles', :category => 'news', :year => '2005'}, @defaults)
|
260
|
-
verify_generate('articles/news/2005/05', {}, {:controller => 'content', :action => 'list_articles', :category => 'news', :year => '2005', :month => '05'}, @defaults)
|
261
|
-
verify_generate('articles/news/2005/05/16', {}, {:controller => 'content', :action => 'list_articles', :category => 'news', :year => '2005', :month => '05', :day => '16'}, @defaults)
|
262
|
-
|
263
|
-
assert_equal nil, @route.generate({:controller => 'content', :action => 'list_articles', :day => '2'}, @defaults)[0]
|
264
|
-
# The above case should fail because a nil value cannot be present in a path.
|
265
|
-
# In other words, since :day is given, :month and :year must be given too.
|
266
|
-
end
|
267
|
-
|
268
|
-
|
269
|
-
def test_no_controller
|
270
|
-
route 'some/:special/:route', :controller => 'a/missing/controller', :action => 'anything'
|
271
|
-
assert_raises(ActionController::RoutingError, "Should raise due to nonexistant controller") {@route.recognize(%w{some matching path})}
|
272
|
-
end
|
273
|
-
def test_bad_controller_path
|
274
|
-
assert_equal nil, @route.recognize(%w{no such controller fake_action id})[0]
|
275
|
-
end
|
276
|
-
def test_too_short_path
|
277
|
-
assert_equal nil, @route.recognize([])[0]
|
278
|
-
route 'some/static/route', :controller => 'content', :action => 'show'
|
279
|
-
assert_equal nil, route.recognize([])[0]
|
280
|
-
end
|
281
|
-
def test_too_long_path
|
282
|
-
assert_equal nil, @route.recognize(%w{content action id some extra components})[0]
|
283
|
-
end
|
284
|
-
def test_incorrect_static_component
|
285
|
-
route 'some/static/route', :controller => 'content', :action => 'show'
|
286
|
-
assert_equal nil, route.recognize(%w{an non_matching path})[0]
|
287
|
-
end
|
288
|
-
def test_no_controller_defined
|
289
|
-
route 'some/:path/:without/a/controller'
|
290
|
-
assert_equal nil, route.recognize(%w{some matching path a controller})[0]
|
291
|
-
end
|
292
|
-
|
293
|
-
def test_mismatching_requirements
|
294
|
-
route 'some/path', :controller => 'content', :action => 'fish'
|
295
|
-
assert_equal nil, route.generate({:controller => 'admin/user', :action => 'list'})[0]
|
296
|
-
assert_equal nil, route.generate({:controller => 'content', :action => 'list'})[0]
|
297
|
-
assert_equal nil, route.generate({:controller => 'admin/user', :action => 'fish'})[0]
|
298
|
-
end
|
299
|
-
|
300
|
-
def test_missing_value_for_generate
|
301
|
-
assert_equal nil, route.generate({})[0] # :controller is missing
|
302
|
-
end
|
303
|
-
def test_nils_inside_generated_path
|
304
|
-
route 'show/:year/:month/:day', :month => nil, :day => nil, :controller => 'content', :action => 'by_date'
|
305
|
-
assert_equal nil, route.generate({:year => 2005, :day => 10})[0]
|
306
|
-
end
|
307
|
-
|
308
|
-
def test_expand_controller_path_non_nested_no_leftover
|
309
|
-
controller, leftovers = @route.send :eat_path_to_controller, %w{content}
|
310
|
-
assert_equal Controllers::ContentController, controller
|
311
|
-
assert_equal [], leftovers
|
312
|
-
end
|
313
|
-
def test_expand_controller_path_non_nested_with_leftover
|
314
|
-
controller, leftovers = @route.send :eat_path_to_controller, %w{content action id}
|
315
|
-
assert_equal Controllers::ContentController, controller
|
316
|
-
assert_equal %w{action id}, leftovers
|
317
|
-
end
|
318
|
-
def test_expand_controller_path_nested_no_leftover
|
319
|
-
controller, leftovers = @route.send :eat_path_to_controller, %w{admin user}
|
320
|
-
assert_equal Controllers::Admin::UserController, controller
|
321
|
-
assert_equal [], leftovers
|
322
|
-
end
|
323
|
-
def test_expand_controller_path_nested_no_leftover
|
324
|
-
controller, leftovers = @route.send :eat_path_to_controller, %w{admin user action id}
|
325
|
-
assert_equal Controllers::Admin::UserController, controller
|
326
|
-
assert_equal %w{action id}, leftovers
|
327
|
-
end
|
328
|
-
|
329
|
-
def test_path_collection
|
330
|
-
route '*path_info', :controller => 'content', :action => 'fish'
|
331
|
-
verify_recognize'path/with/slashes',
|
332
|
-
:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
|
333
|
-
verify_generate('path/with/slashes', {},
|
334
|
-
{:controller => 'content', :action => 'fish', :path_info => 'path/with/slashes'},
|
335
|
-
{})
|
336
|
-
end
|
337
|
-
def test_path_collection_with_array
|
338
|
-
route '*path_info', :controller => 'content', :action => 'fish'
|
339
|
-
verify_recognize'path/with/slashes',
|
340
|
-
:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)
|
341
|
-
verify_generate('path/with/slashes', {},
|
342
|
-
{:controller => 'content', :action => 'fish', :path_info => %w(path with slashes)},
|
343
|
-
{})
|
344
|
-
end
|
345
|
-
|
346
|
-
def test_path_empty_list
|
347
|
-
route '*a', :controller => 'content'
|
348
|
-
verify_recognize '', :controller => 'content', :a => []
|
349
|
-
end
|
350
|
-
|
351
|
-
def test_special_characters
|
352
|
-
route ':id', :controller => 'content', :action => 'fish'
|
353
|
-
verify_recognize'id+with+spaces',
|
354
|
-
:controller => 'content', :action => 'fish', :id => 'id with spaces'
|
355
|
-
verify_generate('id+with+spaces', {},
|
356
|
-
{:controller => 'content', :action => 'fish', :id => 'id with spaces'}, {})
|
357
|
-
verify_recognize 'id%2Fwith%2Fslashes',
|
358
|
-
:controller => 'content', :action => 'fish', :id => 'id/with/slashes'
|
359
|
-
verify_generate('id%2Fwith%2Fslashes', {},
|
360
|
-
{:controller => 'content', :action => 'fish', :id => 'id/with/slashes'}, {})
|
361
|
-
end
|
362
|
-
|
363
|
-
def test_generate_with_numeric_param
|
364
|
-
o = Object.new
|
365
|
-
def o.to_param() 10 end
|
366
|
-
verify_generate('content/action/10', {}, {:controller => 'content', :action => 'action', :id => o}, @defaults)
|
367
|
-
verify_generate('content/show/10', {}, {:controller => 'content', :action => 'show', :id => o}, @defaults)
|
368
|
-
end
|
369
|
-
end
|
370
|
-
|
371
|
-
class RouteSetTests < Test::Unit::TestCase
|
372
|
-
def setup
|
373
|
-
@set = ActionController::Routing::RouteSet.new
|
374
|
-
@rails_route = ActionController::Routing::Route.new '/:controller/:action/:id', :action => 'index', :id => nil
|
375
|
-
@request = ActionController::TestRequest.new({}, {}, nil)
|
376
|
-
end
|
377
|
-
def test_emptyness
|
378
|
-
assert_equal true, @set.empty?, "New RouteSets should respond to empty? with true."
|
379
|
-
@set.each { flunk "New RouteSets should be empty." }
|
380
|
-
end
|
381
|
-
def test_add_illegal_route
|
382
|
-
assert_raises(TypeError) {@set.add_route "I'm not actually a route."}
|
383
|
-
end
|
384
|
-
def test_add_normal_route
|
385
|
-
@set.add_route @rails_route
|
386
|
-
seen = false
|
387
|
-
@set.each do |route|
|
388
|
-
assert_equal @rails_route, route
|
389
|
-
flunk("Each should have yielded only a single route!") if seen
|
390
|
-
seen = true
|
391
|
-
end
|
392
|
-
end
|
393
|
-
|
394
|
-
def test_expand_controller_path_non_relative
|
395
|
-
defaults = {:controller => 'admin/user', :action => 'list'}
|
396
|
-
options = {:controller => '/content'}
|
397
|
-
@set.expand_controller_path!(options, defaults)
|
398
|
-
assert_equal({:controller => 'content'}, options)
|
399
|
-
end
|
400
|
-
def test_expand_controller_path_relative_to_nested
|
401
|
-
defaults = {:controller => 'admin/user', :action => 'list'}
|
402
|
-
options = {:controller => 'access'}
|
403
|
-
@set.expand_controller_path!(options, defaults)
|
404
|
-
assert_equal({:controller => 'admin/access'}, options)
|
405
|
-
end
|
406
|
-
def test_expand_controller_path_relative_to_root
|
407
|
-
defaults = {:controller => 'content', :action => 'list'}
|
408
|
-
options = {:controller => 'resource'}
|
409
|
-
@set.expand_controller_path!(options, defaults)
|
410
|
-
assert_equal({:controller => 'resource'}, options)
|
411
|
-
end
|
412
|
-
def test_expand_controller_path_into_module
|
413
|
-
defaults = {:controller => 'content', :action => 'list'}
|
414
|
-
options = {:controller => 'admin/user'}
|
415
|
-
@set.expand_controller_path!(options, defaults)
|
416
|
-
assert_equal({:controller => 'admin/user'}, options)
|
417
|
-
end
|
418
|
-
def test_expand_controller_path_switch_module_with_absolute
|
419
|
-
defaults = {:controller => 'user/news', :action => 'list'}
|
420
|
-
options = {:controller => '/admin/user'}
|
421
|
-
@set.expand_controller_path!(options, defaults)
|
422
|
-
assert_equal({:controller => 'admin/user'}, options)
|
423
|
-
end
|
424
|
-
def test_expand_controller_no_default
|
425
|
-
options = {:controller => 'content'}
|
426
|
-
@set.expand_controller_path!(options, {})
|
427
|
-
assert_equal({:controller => 'content'}, options)
|
428
|
-
end
|
429
|
-
|
430
|
-
# Don't put a leading / on the url.
|
431
|
-
# Make sure the controller is one from the above fake Controllers module.
|
432
|
-
def verify_recognize(expected_controller, expected_path_parameters=nil, path=nil)
|
433
|
-
@set.add_route(@rails_route) if @set.empty?
|
434
|
-
@request.path = path if path
|
435
|
-
controller = @set.recognize!(@request)
|
436
|
-
assert_equal expected_controller, controller
|
437
|
-
assert_equal expected_path_parameters, @request.path_parameters if expected_path_parameters
|
438
|
-
end
|
439
|
-
|
440
|
-
# The expected url should not have a leading /
|
441
|
-
# You can use @defaults if you want a set of plausible defaults
|
442
|
-
def verify_generate(expected_url, options, expected_extras={})
|
443
|
-
@set.add_route(@rails_route) if @set.empty?
|
444
|
-
components, extras = @set.generate(options, @request)
|
445
|
-
assert_equal expected_extras, extras, "#incorrect extra's"
|
446
|
-
assert_equal expected_url, components.join('/'), "incorrect url"
|
447
|
-
end
|
448
|
-
def typical_request
|
449
|
-
@request.path_parameters = {:controller => 'content', :action => 'show', :id => '10'}
|
450
|
-
end
|
451
|
-
def typical_nested_request
|
452
|
-
@request.path_parameters = {:controller => 'admin/user', :action => 'grant', :id => '02seckar'}
|
453
|
-
end
|
454
|
-
|
455
|
-
def test_generate_typical_controller_action_path
|
456
|
-
typical_request
|
457
|
-
verify_generate('content/list', {:controller => 'content', :action => 'list'})
|
458
|
-
end
|
459
|
-
def test_generate_typical_controller_index_path_explicit_index
|
460
|
-
typical_request
|
461
|
-
verify_generate('content', {:controller => 'content', :action => 'index'})
|
462
|
-
end
|
463
|
-
def test_generate_typical_controller_index_path_explicit_index
|
464
|
-
typical_request
|
465
|
-
verify_generate('content', {:controller => 'content', :action => 'index'})
|
466
|
-
end
|
467
|
-
def test_generate_typical_controller_index_path_implicit_index
|
468
|
-
typical_request
|
469
|
-
@request.path_parameters[:controller] = 'resource'
|
470
|
-
verify_generate('content', {:controller => 'content'})
|
471
|
-
end
|
472
|
-
|
473
|
-
def test_generate_no_perfect_route
|
474
|
-
typical_request
|
475
|
-
verify_generate('admin/user/show/43seckar', {:controller => 'admin/user', :action => 'show', :id => '43seckar', :likes_fishing => 'fuzzy(0.3)'}, {:likes_fishing => 'fuzzy(0.3)'})
|
476
|
-
end
|
477
|
-
|
478
|
-
def test_generate_no_match
|
479
|
-
@set.add_route(@rails_route)
|
480
|
-
@request.path_parameters = {}
|
481
|
-
assert_raises(ActionController::RoutingError) {@set.generate({}, @request)}
|
482
|
-
end
|
483
|
-
|
484
|
-
def test_encoded_strings
|
485
|
-
verify_recognize(Controllers::Admin::UserController, {:controller => 'admin/user', :action => 'info', :id => "Nicholas Seckar"}, path='/admin/user/info/Nicholas%20Seckar')
|
486
|
-
end
|
487
|
-
|
488
|
-
def test_action_dropped_when_controller_changes
|
489
|
-
@request.path_parameters = {:controller => 'content', :action => 'list'}
|
490
|
-
options = {:controller => 'resource'}
|
491
|
-
@set.connect ':action/:controller'
|
492
|
-
verify_generate('index/resource', options)
|
493
|
-
end
|
494
|
-
|
495
|
-
def test_action_dropped_when_controller_given
|
496
|
-
@request.path_parameters = {:controller => 'content', :action => 'list'}
|
497
|
-
options = {:controller => 'content'}
|
498
|
-
@set.connect ':action/:controller'
|
499
|
-
verify_generate('index/content', options)
|
500
|
-
end
|
501
|
-
|
502
|
-
def test_default_dropped_with_nil_option
|
503
|
-
@request.path_parameters = {:controller => 'content', :action => 'action', :id => '10'}
|
504
|
-
verify_generate 'content/action', {:id => nil}
|
505
|
-
end
|
506
|
-
|
507
|
-
def test_url_to_self
|
508
|
-
@request.path_parameters = {:controller => 'admin/users', :action => 'index'}
|
509
|
-
verify_generate 'admin/users', {}
|
510
|
-
end
|
511
|
-
|
512
|
-
def test_url_with_spaces_in_controller
|
513
|
-
@request.path = 'not%20a%20valid/controller/name'
|
514
|
-
@set.add_route(@rails_route) if @set.empty?
|
515
|
-
assert_raises(ActionController::RoutingError) {@set.recognize!(@request)}
|
516
|
-
end
|
517
|
-
def test_url_with_dots_in_controller
|
518
|
-
@request.path = 'not.valid/controller/name'
|
519
|
-
@set.add_route(@rails_route) if @set.empty?
|
520
|
-
assert_raises(ActionController::RoutingError) {@set.recognize!(@request)}
|
521
|
-
end
|
522
|
-
|
523
|
-
def test_generate_of_empty_url
|
524
|
-
@set.connect '', :controller => 'content', :action => 'view', :id => "1"
|
525
|
-
@set.add_route(@rails_route)
|
526
|
-
verify_generate('content/view/2', {:controller => 'content', :action => 'view', :id => 2})
|
527
|
-
verify_generate('', {:controller => 'content', :action => 'view', :id => 1})
|
528
|
-
end
|
529
|
-
def test_generate_of_empty_url_with_numeric_requirement
|
530
|
-
@set.connect '', :controller => 'content', :action => 'view', :id => 1
|
531
|
-
@set.add_route(@rails_route)
|
532
|
-
verify_generate('content/view/2', {:controller => 'content', :action => 'view', :id => 2})
|
533
|
-
verify_generate('', {:controller => 'content', :action => 'view', :id => 1})
|
534
|
-
end
|
535
|
-
end
|
536
|
-
|
537
|
-
#require '../assertions/action_pack_assertions.rb'
|
538
|
-
class AssertionRoutingTests < Test::Unit::TestCase
|
539
|
-
def test_assert_routing
|
540
|
-
ActionController::Routing::Routes.reload rescue nil
|
541
|
-
assert_routing('content', {:controller => 'content', :action => 'index'})
|
542
|
-
end
|
543
|
-
end
|