actionpack 1.9.1 → 1.10.1
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 +237 -0
- data/README +12 -12
- data/lib/action_controller.rb +17 -12
- data/lib/action_controller/assertions.rb +119 -67
- data/lib/action_controller/base.rb +184 -102
- data/lib/action_controller/benchmarking.rb +35 -6
- data/lib/action_controller/caching.rb +115 -58
- data/lib/action_controller/cgi_ext/cgi_methods.rb +54 -21
- data/lib/action_controller/cgi_ext/cookie_performance_fix.rb +39 -35
- data/lib/action_controller/cgi_ext/raw_post_data_fix.rb +34 -21
- data/lib/action_controller/cgi_process.rb +23 -20
- data/lib/action_controller/components.rb +11 -2
- data/lib/action_controller/dependencies.rb +0 -5
- data/lib/action_controller/deprecated_redirects.rb +17 -0
- data/lib/action_controller/filters.rb +13 -9
- data/lib/action_controller/flash.rb +7 -7
- data/lib/action_controller/helpers.rb +1 -14
- data/lib/action_controller/layout.rb +40 -29
- data/lib/action_controller/macros/auto_complete.rb +52 -0
- data/lib/action_controller/macros/in_place_editing.rb +32 -0
- data/lib/action_controller/pagination.rb +44 -28
- data/lib/action_controller/request.rb +54 -40
- data/lib/action_controller/rescue.rb +8 -6
- data/lib/action_controller/routing.rb +77 -28
- data/lib/action_controller/scaffolding.rb +10 -14
- data/lib/action_controller/session/active_record_store.rb +36 -7
- data/lib/action_controller/session_management.rb +126 -0
- data/lib/action_controller/streaming.rb +14 -5
- data/lib/action_controller/templates/rescues/_request_and_response.rhtml +1 -1
- data/lib/action_controller/templates/rescues/_trace.rhtml +24 -0
- data/lib/action_controller/templates/rescues/diagnostics.rhtml +2 -13
- data/lib/action_controller/templates/rescues/template_error.rhtml +4 -2
- data/lib/action_controller/templates/scaffolds/list.rhtml +1 -1
- data/lib/action_controller/test_process.rb +35 -17
- data/lib/action_controller/upload_progress.rb +52 -0
- data/lib/action_controller/url_rewriter.rb +21 -16
- data/lib/action_controller/vendor/html-scanner/html/document.rb +2 -2
- data/lib/action_controller/vendor/html-scanner/html/node.rb +30 -3
- data/lib/action_pack/version.rb +9 -0
- data/lib/action_view.rb +1 -1
- data/lib/action_view/base.rb +204 -60
- data/lib/action_view/compiled_templates.rb +70 -0
- data/lib/action_view/helpers/active_record_helper.rb +7 -3
- data/lib/action_view/helpers/asset_tag_helper.rb +22 -12
- data/lib/action_view/helpers/capture_helper.rb +2 -10
- data/lib/action_view/helpers/date_helper.rb +21 -13
- data/lib/action_view/helpers/form_helper.rb +14 -10
- data/lib/action_view/helpers/form_options_helper.rb +4 -4
- data/lib/action_view/helpers/form_tag_helper.rb +59 -25
- data/lib/action_view/helpers/java_script_macros_helper.rb +188 -0
- data/lib/action_view/helpers/javascript_helper.rb +68 -133
- data/lib/action_view/helpers/javascripts/controls.js +427 -165
- data/lib/action_view/helpers/javascripts/dragdrop.js +256 -277
- data/lib/action_view/helpers/javascripts/effects.js +766 -277
- data/lib/action_view/helpers/javascripts/prototype.js +906 -218
- data/lib/action_view/helpers/javascripts/slider.js +258 -0
- data/lib/action_view/helpers/number_helper.rb +4 -3
- data/lib/action_view/helpers/pagination_helper.rb +42 -27
- data/lib/action_view/helpers/tag_helper.rb +25 -11
- data/lib/action_view/helpers/text_helper.rb +119 -13
- data/lib/action_view/helpers/upload_progress_helper.rb +2 -2
- data/lib/action_view/helpers/url_helper.rb +68 -21
- data/lib/action_view/partials.rb +17 -6
- data/lib/action_view/template_error.rb +19 -24
- data/rakefile +4 -3
- data/test/abstract_unit.rb +2 -1
- data/test/controller/action_pack_assertions_test.rb +62 -2
- data/test/controller/active_record_assertions_test.rb +5 -6
- data/test/controller/active_record_store_test.rb +23 -1
- data/test/controller/addresses_render_test.rb +4 -0
- data/test/controller/{base_tests.rb → base_test.rb} +4 -3
- data/test/controller/benchmark_test.rb +36 -0
- data/test/controller/caching_filestore.rb +22 -40
- data/test/controller/capture_test.rb +10 -1
- data/test/controller/cgi_test.rb +145 -23
- data/test/controller/components_test.rb +50 -0
- data/test/controller/custom_handler_test.rb +3 -3
- data/test/controller/fake_controllers.rb +24 -0
- data/test/controller/filters_test.rb +6 -6
- data/test/controller/flash_test.rb +6 -6
- data/test/controller/fragment_store_setting_test.rb +45 -0
- data/test/controller/helper_test.rb +1 -3
- data/test/controller/new_render_test.rb +119 -7
- data/test/controller/redirect_test.rb +11 -1
- data/test/controller/render_test.rb +34 -1
- data/test/controller/request_test.rb +14 -5
- data/test/controller/routing_test.rb +238 -42
- data/test/controller/send_file_test.rb +11 -10
- data/test/controller/session_management_test.rb +94 -0
- data/test/controller/test_test.rb +194 -5
- data/test/controller/url_rewriter_test.rb +46 -0
- data/test/fixtures/layouts/talk_from_action.rhtml +2 -0
- data/test/fixtures/layouts/yield.rhtml +2 -0
- data/test/fixtures/multipart/binary_file +0 -0
- data/test/fixtures/multipart/large_text_file +10 -0
- data/test/fixtures/multipart/mixed_files +0 -0
- data/test/fixtures/multipart/single_parameter +5 -0
- data/test/fixtures/multipart/text_file +10 -0
- data/test/fixtures/test/_customer_greeting.rhtml +1 -0
- data/test/fixtures/test/_hash_object.rhtml +1 -0
- data/test/fixtures/test/_person.rhtml +2 -0
- data/test/fixtures/test/action_talk_to_layout.rhtml +2 -0
- data/test/fixtures/test/content_for.rhtml +2 -0
- data/test/fixtures/test/potential_conflicts.rhtml +4 -0
- data/test/template/active_record_helper_test.rb +15 -8
- data/test/template/asset_tag_helper_test.rb +40 -16
- data/test/template/compiled_templates_tests.rb +63 -0
- data/test/template/date_helper_test.rb +80 -4
- data/test/template/form_helper_test.rb +48 -42
- data/test/template/form_options_helper_test.rb +40 -40
- data/test/template/form_tag_helper_test.rb +21 -15
- data/test/template/java_script_macros_helper_test.rb +56 -0
- data/test/template/javascript_helper_test.rb +70 -47
- data/test/template/number_helper_test.rb +2 -0
- data/test/template/tag_helper_test.rb +9 -0
- data/test/template/text_helper_test.rb +146 -1
- data/test/template/upload_progress_helper_testx.rb +11 -147
- data/test/template/url_helper_test.rb +90 -22
- data/test/testing_sandbox.rb +26 -0
- metadata +37 -7
- data/lib/action_controller/auto_complete.rb +0 -47
- data/lib/action_controller/deprecated_renders_and_redirects.rb +0 -76
- data/lib/action_controller/session.rb +0 -14
@@ -17,6 +17,11 @@ class RedirectController < ActionController::Base
|
|
17
17
|
redirect_to :controller => 'module_test/module_redirect', :action => "hello_world"
|
18
18
|
end
|
19
19
|
|
20
|
+
def redirect_with_assigns
|
21
|
+
@hello = "world"
|
22
|
+
redirect_to :action => "hello_world"
|
23
|
+
end
|
24
|
+
|
20
25
|
def rescue_errors(e) raise e end
|
21
26
|
|
22
27
|
protected
|
@@ -56,6 +61,11 @@ class RedirectTest < Test::Unit::TestCase
|
|
56
61
|
get :module_redirect
|
57
62
|
assert_redirected_to :controller => 'module_test/module_redirect', :action => 'hello_world'
|
58
63
|
end
|
64
|
+
|
65
|
+
def test_redirect_with_assigns
|
66
|
+
get :redirect_with_assigns
|
67
|
+
assert_equal "world", assigns["hello"]
|
68
|
+
end
|
59
69
|
end
|
60
70
|
|
61
71
|
module ModuleTest
|
@@ -97,4 +107,4 @@ module ModuleTest
|
|
97
107
|
assert_redirected_to :controller => 'redirect', :action => "hello_world"
|
98
108
|
end
|
99
109
|
end
|
100
|
-
end
|
110
|
+
end
|
@@ -75,6 +75,20 @@ class TestController < ActionController::Base
|
|
75
75
|
render_template "Hello: <%= params[:name] %>"
|
76
76
|
end
|
77
77
|
|
78
|
+
def accessing_local_assigns_in_inline_template
|
79
|
+
name = params[:local_name]
|
80
|
+
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
81
|
+
:locals => { :local_name => name }
|
82
|
+
end
|
83
|
+
|
84
|
+
def accessing_local_assigns_in_inline_template_with_string_keys
|
85
|
+
name = params[:local_name]
|
86
|
+
ActionView::Base.local_assigns_support_string_keys = true
|
87
|
+
render :inline => "<%= 'Goodbye, ' + local_name %>",
|
88
|
+
:locals => { "local_name" => name }
|
89
|
+
ActionView::Base.local_assigns_support_string_keys = false
|
90
|
+
end
|
91
|
+
|
78
92
|
def rescue_action(e) raise end
|
79
93
|
|
80
94
|
private
|
@@ -140,17 +154,24 @@ class RenderTest < Test::Unit::TestCase
|
|
140
154
|
end
|
141
155
|
|
142
156
|
def test_access_to_request_in_view
|
157
|
+
view_internals_old_value = ActionController::Base.view_controller_internals
|
158
|
+
|
143
159
|
ActionController::Base.view_controller_internals = false
|
160
|
+
ActionController::Base.protected_variables_cache = nil
|
144
161
|
|
145
162
|
@request.action = "hello_world"
|
146
163
|
response = process_request
|
147
164
|
assert_nil response.template.assigns["request"]
|
148
165
|
|
149
166
|
ActionController::Base.view_controller_internals = true
|
167
|
+
ActionController::Base.protected_variables_cache = nil
|
150
168
|
|
151
169
|
@request.action = "hello_world"
|
152
170
|
response = process_request
|
153
|
-
assert_kind_of ActionController::AbstractRequest,
|
171
|
+
assert_kind_of ActionController::AbstractRequest, response.template.assigns["request"]
|
172
|
+
|
173
|
+
ActionController::Base.view_controller_internals = view_internals_old_value
|
174
|
+
ActionController::Base.protected_variables_cache = nil
|
154
175
|
end
|
155
176
|
|
156
177
|
def test_render_xml
|
@@ -199,6 +220,18 @@ class RenderTest < Test::Unit::TestCase
|
|
199
220
|
assert_equal "Hello: David", process_request.body
|
200
221
|
end
|
201
222
|
|
223
|
+
def test_accessing_local_assigns_in_inline_template
|
224
|
+
@request.action = "accessing_local_assigns_in_inline_template"
|
225
|
+
@request.query_parameters[:local_name] = "Local David"
|
226
|
+
assert_equal "Goodbye, Local David", process_request.body
|
227
|
+
end
|
228
|
+
|
229
|
+
def test_accessing_local_assigns_in_inline_template_with_string_keys
|
230
|
+
@request.action = "accessing_local_assigns_in_inline_template_with_string_keys"
|
231
|
+
@request.query_parameters[:local_name] = "Local David"
|
232
|
+
assert_equal "Goodbye, Local David", process_request.body
|
233
|
+
end
|
234
|
+
|
202
235
|
private
|
203
236
|
def process_request
|
204
237
|
TestController.process(@request, @response)
|
@@ -44,6 +44,12 @@ class RequestTest < Test::Unit::TestCase
|
|
44
44
|
|
45
45
|
@request.host = "www.rubyonrails.co.uk"
|
46
46
|
assert_equal "rubyonrails.co.uk", @request.domain(2)
|
47
|
+
|
48
|
+
@request.host = "192.168.1.200"
|
49
|
+
assert_nil @request.domain
|
50
|
+
|
51
|
+
@request.host = nil
|
52
|
+
assert_nil @request.domain
|
47
53
|
end
|
48
54
|
|
49
55
|
def test_subdomains
|
@@ -55,6 +61,12 @@ class RequestTest < Test::Unit::TestCase
|
|
55
61
|
|
56
62
|
@request.host = "dev.www.rubyonrails.co.uk"
|
57
63
|
assert_equal %w( dev www ), @request.subdomains(2)
|
64
|
+
|
65
|
+
@request.host = "foobar.foobar.com"
|
66
|
+
assert_equal %w( foobar ), @request.subdomains
|
67
|
+
|
68
|
+
@request.host = nil
|
69
|
+
assert_equal [], @request.subdomains
|
58
70
|
end
|
59
71
|
|
60
72
|
def test_port_string
|
@@ -66,8 +78,9 @@ class RequestTest < Test::Unit::TestCase
|
|
66
78
|
end
|
67
79
|
|
68
80
|
def test_relative_url_root
|
81
|
+
@request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
|
69
82
|
@request.env['SERVER_SOFTWARE'] = 'lighttpd/1.2.3'
|
70
|
-
|
83
|
+
assert_equal '', @request.relative_url_root, "relative_url_root should be disabled on lighttpd"
|
71
84
|
|
72
85
|
@request.env['SERVER_SOFTWARE'] = 'apache/1.2.3 some random text'
|
73
86
|
|
@@ -188,10 +201,6 @@ class RequestTest < Test::Unit::TestCase
|
|
188
201
|
|
189
202
|
|
190
203
|
def test_host_with_port
|
191
|
-
@request.env['HTTP_HOST'] = "rubyonrails.org:8080"
|
192
|
-
assert_equal "rubyonrails.org:8080", @request.host_with_port
|
193
|
-
@request.env['HTTP_HOST'] = nil
|
194
|
-
|
195
204
|
@request.host = "rubyonrails.org"
|
196
205
|
@request.port = 80
|
197
206
|
assert_equal "rubyonrails.org", @request.host_with_port
|
@@ -1,4 +1,5 @@
|
|
1
1
|
require File.dirname(__FILE__) + '/../abstract_unit'
|
2
|
+
require File.dirname(__FILE__) + '/fake_controllers'
|
2
3
|
require 'test/unit'
|
3
4
|
require 'stringio'
|
4
5
|
|
@@ -94,28 +95,6 @@ class CodeGeneratorTests < Test::Unit::TestCase
|
|
94
95
|
end
|
95
96
|
end
|
96
97
|
|
97
|
-
# XXX Extract to test/controller/fake_controllers.rb
|
98
|
-
module Object::Controllers
|
99
|
-
def self.const_available?(*args)
|
100
|
-
const_defined?(*args)
|
101
|
-
end
|
102
|
-
|
103
|
-
class ContentController
|
104
|
-
end
|
105
|
-
module Admin
|
106
|
-
def self.const_available?(*args)
|
107
|
-
const_defined?(*args)
|
108
|
-
end
|
109
|
-
|
110
|
-
class UserController
|
111
|
-
end
|
112
|
-
|
113
|
-
class NewsFeedController
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
|
119
98
|
class RecognitionTests < Test::Unit::TestCase
|
120
99
|
attr_accessor :generator
|
121
100
|
alias :g :generator
|
@@ -169,6 +148,19 @@ class RecognitionTests < Test::Unit::TestCase
|
|
169
148
|
assert_equal({:controller => ::Controllers::ContentController, :action => 'dude'}, execute('hi/dude'))
|
170
149
|
end
|
171
150
|
|
151
|
+
def test_basic_dynamic_backwards
|
152
|
+
c = [Dynamic.new(:action), Static.new("hi")]
|
153
|
+
go c
|
154
|
+
|
155
|
+
assert_nil execute('')
|
156
|
+
assert_nil execute('boo')
|
157
|
+
assert_nil execute('boo/blah')
|
158
|
+
assert_nil execute('hi')
|
159
|
+
assert_equal({:action => 'index'}, execute('index/hi'))
|
160
|
+
assert_equal({:action => 'show'}, execute('show/hi'))
|
161
|
+
assert_nil execute('hi/dude')
|
162
|
+
end
|
163
|
+
|
172
164
|
def test_dynamic_with_default
|
173
165
|
c = [Static.new("hi"), Dynamic.new(:action, :default => 'index')]
|
174
166
|
g.result :controller, "::Controllers::ContentController", true
|
@@ -186,7 +178,7 @@ class RecognitionTests < Test::Unit::TestCase
|
|
186
178
|
c = [Static.new("hi"), Dynamic.new(:action, :condition => 'index')]
|
187
179
|
g.result :controller, "::Controllers::ContentController", true
|
188
180
|
go c
|
189
|
-
|
181
|
+
|
190
182
|
assert_nil execute('boo')
|
191
183
|
assert_nil execute('boo/blah')
|
192
184
|
assert_nil execute('hi')
|
@@ -194,7 +186,21 @@ class RecognitionTests < Test::Unit::TestCase
|
|
194
186
|
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('hi/index'))
|
195
187
|
assert_nil execute('hi/dude')
|
196
188
|
end
|
197
|
-
|
189
|
+
|
190
|
+
def test_dynamic_with_string_condition_backwards
|
191
|
+
c = [Dynamic.new(:action, :condition => 'index'), Static.new("hi")]
|
192
|
+
g.result :controller, "::Controllers::ContentController", true
|
193
|
+
go c
|
194
|
+
|
195
|
+
assert_nil execute('boo')
|
196
|
+
assert_nil execute('boo/blah')
|
197
|
+
assert_nil execute('hi')
|
198
|
+
assert_nil execute('dude/what/hi')
|
199
|
+
assert_nil execute('index/what')
|
200
|
+
assert_equal({:controller => ::Controllers::ContentController, :action => 'index'}, execute('index/hi'))
|
201
|
+
assert_nil execute('dude/hi')
|
202
|
+
end
|
203
|
+
|
198
204
|
def test_dynamic_with_regexp_condition
|
199
205
|
c = [Static.new("hi"), Dynamic.new(:action, :condition => /^[a-z]+$/)]
|
200
206
|
g.result :controller, "::Controllers::ContentController", true
|
@@ -242,6 +248,32 @@ class RecognitionTests < Test::Unit::TestCase
|
|
242
248
|
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('hi/dude'))
|
243
249
|
assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
|
244
250
|
end
|
251
|
+
|
252
|
+
def test_path_with_dynamic
|
253
|
+
c = [Dynamic.new(:action), Path.new(:file)]
|
254
|
+
g.result :controller, "::Controllers::ContentController", true
|
255
|
+
|
256
|
+
go c
|
257
|
+
|
258
|
+
assert_nil execute('')
|
259
|
+
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => []}, execute('download'))
|
260
|
+
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => %w(books agile_rails_dev.pdf)},
|
261
|
+
execute('download/books/agile_rails_dev.pdf'))
|
262
|
+
assert_equal({:controller => ::Controllers::ContentController, :action => 'download', :file => ['dude']}, execute('download/dude'))
|
263
|
+
assert_equal 'dude/what', execute('hi/dude/what')[:file].to_s
|
264
|
+
end
|
265
|
+
|
266
|
+
def test_path_with_dynamic_and_default
|
267
|
+
c = [Dynamic.new(:action, :default => 'index'), Path.new(:file)]
|
268
|
+
|
269
|
+
go c
|
270
|
+
|
271
|
+
assert_equal({:action => 'index', :file => []}, execute(''))
|
272
|
+
assert_equal({:action => 'index', :file => []}, execute('index'))
|
273
|
+
assert_equal({:action => 'blarg', :file => []}, execute('blarg'))
|
274
|
+
assert_equal({:action => 'index', :file => ['content']}, execute('index/content'))
|
275
|
+
assert_equal({:action => 'show', :file => ['rails_dev.pdf']}, execute('show/rails_dev.pdf'))
|
276
|
+
end
|
245
277
|
|
246
278
|
def test_controller
|
247
279
|
c = [Static.new("hi"), Controller.new(:controller)]
|
@@ -259,6 +291,20 @@ class RecognitionTests < Test::Unit::TestCase
|
|
259
291
|
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
|
260
292
|
end
|
261
293
|
|
294
|
+
def test_controller_with_regexp
|
295
|
+
c = [Static.new("hi"), Controller.new(:controller, :condition => /^admin\/.+$/)]
|
296
|
+
g.constant_result :action, "hi"
|
297
|
+
|
298
|
+
go c
|
299
|
+
|
300
|
+
assert_nil execute('hi')
|
301
|
+
assert_nil execute('hi/x')
|
302
|
+
assert_nil execute('hi/content')
|
303
|
+
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'hi'}, execute('hi/admin/user'))
|
304
|
+
assert_equal({:controller => ::Controllers::Admin::NewsFeedController, :action => 'hi'}, execute('hi/admin/news_feed'))
|
305
|
+
assert_nil execute('hi/admin/user/foo')
|
306
|
+
end
|
307
|
+
|
262
308
|
def test_standard_route(time = ::RunTimeTests)
|
263
309
|
c = [Controller.new(:controller), Dynamic.new(:action, :default => 'index'), Dynamic.new(:id, :default => nil)]
|
264
310
|
go c
|
@@ -428,6 +474,17 @@ not_expired = true
|
|
428
474
|
assert_equal '/hi/admin/user', execute({}, {:controller => 'admin/user'})
|
429
475
|
end
|
430
476
|
|
477
|
+
def test_controller_with_regexp
|
478
|
+
c = [Static.new("hi"), Controller.new(:controller, :condition => /^admin\/.+$/)]
|
479
|
+
go c
|
480
|
+
|
481
|
+
assert_nil execute({}, {})
|
482
|
+
assert_nil execute({:controller => 'content'}, {})
|
483
|
+
assert_equal '/hi/admin/user', execute({:controller => 'admin/user'}, {})
|
484
|
+
assert_nil execute({}, {:controller => 'content'})
|
485
|
+
assert_equal '/hi/admin/user', execute({}, {:controller => 'admin/user'})
|
486
|
+
end
|
487
|
+
|
431
488
|
def test_standard_route(time = ::RunTimeTests)
|
432
489
|
c = [Controller.new(:controller), Dynamic.new(:action, :default => 'index'), Dynamic.new(:id, :default => nil)]
|
433
490
|
go c
|
@@ -504,16 +561,19 @@ class RouteTests < Test::Unit::TestCase
|
|
504
561
|
end
|
505
562
|
|
506
563
|
def test_static
|
507
|
-
route 'hello/world', :known => 'known_value'
|
564
|
+
route 'hello/world', :known => 'known_value', :controller => 'content', :action => 'index'
|
508
565
|
|
509
566
|
assert_nil rec('hello/turn')
|
510
567
|
assert_nil rec('turn/world')
|
511
|
-
assert_equal(
|
568
|
+
assert_equal(
|
569
|
+
{:known => 'known_value', :controller => ::Controllers::ContentController, :action => 'index'},
|
570
|
+
rec('hello/world')
|
571
|
+
)
|
512
572
|
|
513
573
|
assert_nil gen(:known => 'foo')
|
514
574
|
assert_nil gen({})
|
515
|
-
assert_equal '/hello/world', gen(:known => 'known_value')
|
516
|
-
assert_equal '/hello/world', gen(:known => 'known_value', :extra => 'hi')
|
575
|
+
assert_equal '/hello/world', gen(:known => 'known_value', :controller => 'content', :action => 'index')
|
576
|
+
assert_equal '/hello/world', gen(:known => 'known_value', :extra => 'hi', :controller => 'content', :action => 'index')
|
517
577
|
assert_equal [:extra], route.extra_keys(:known => 'known_value', :extra => 'hi')
|
518
578
|
end
|
519
579
|
|
@@ -563,6 +623,7 @@ class RouteSetTests < Test::Unit::TestCase
|
|
563
623
|
def setup
|
564
624
|
@rs = ::ActionController::Routing::RouteSet.new
|
565
625
|
@rs.draw {|m| m.connect ':controller/:action/:id' }
|
626
|
+
::ActionController::Routing::NamedRoutes.clear
|
566
627
|
end
|
567
628
|
|
568
629
|
def test_default_setup
|
@@ -572,13 +633,13 @@ class RouteSetTests < Test::Unit::TestCase
|
|
572
633
|
|
573
634
|
assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10)))
|
574
635
|
|
575
|
-
assert_equal ['/admin/user/show/10',
|
636
|
+
assert_equal ['/admin/user/show/10', []], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10})
|
576
637
|
|
577
|
-
assert_equal ['/admin/user/show',
|
578
|
-
assert_equal ['/admin/user/list/10',
|
638
|
+
assert_equal ['/admin/user/show', []], rs.generate({:action => 'show'}, {:controller => 'admin/user', :action => 'list', :id => '10'})
|
639
|
+
assert_equal ['/admin/user/list/10', []], rs.generate({}, {:controller => 'admin/user', :action => 'list', :id => '10'})
|
579
640
|
|
580
|
-
assert_equal ['/admin/stuff',
|
581
|
-
assert_equal ['/stuff',
|
641
|
+
assert_equal ['/admin/stuff', []], rs.generate({:controller => 'stuff'}, {:controller => 'admin/user', :action => 'list', :id => '10'})
|
642
|
+
assert_equal ['/stuff', []], rs.generate({:controller => '/stuff'}, {:controller => 'admin/user', :action => 'list', :id => '10'})
|
582
643
|
end
|
583
644
|
|
584
645
|
def test_ignores_leading_slash
|
@@ -652,6 +713,19 @@ class RouteSetTests < Test::Unit::TestCase
|
|
652
713
|
$stderr = old_stderr
|
653
714
|
end
|
654
715
|
|
716
|
+
def test_route_with_regexp_for_controller
|
717
|
+
rs.draw do |map|
|
718
|
+
map.connect ':controller/:admintoken/:action/:id', :controller => /admin\/.+/
|
719
|
+
map.connect ':controller/:action/:id'
|
720
|
+
end
|
721
|
+
assert_equal({:controller => ::Controllers::Admin::UserController, :admintoken => "foo", :action => "index"}.stringify_keys,
|
722
|
+
rs.recognize_path(%w(admin user foo)))
|
723
|
+
assert_equal({:controller => ::Controllers::ContentController, :action => "foo"}.stringify_keys,
|
724
|
+
rs.recognize_path(%w(content foo)))
|
725
|
+
assert_equal ['/admin/user/foo', []], rs.generate(:controller => "admin/user", :admintoken => "foo", :action => "index")
|
726
|
+
assert_equal ['/content/foo',[]], rs.generate(:controller => "content", :action => "foo")
|
727
|
+
end
|
728
|
+
|
655
729
|
def test_basic_named_route
|
656
730
|
rs.home '', :controller => 'content', :action => 'list'
|
657
731
|
x = setup_for_named_route
|
@@ -689,8 +763,25 @@ class RouteSetTests < Test::Unit::TestCase
|
|
689
763
|
end
|
690
764
|
end
|
691
765
|
|
766
|
+
def test_named_route_with_regexps
|
767
|
+
rs.draw do |map|
|
768
|
+
rs.article 'page/:year/:month/:day/:title', :controller => 'page', :action => 'show',
|
769
|
+
:year => /^\d+$/, :month => /^\d+$/, :day => /^\d+$/
|
770
|
+
rs.connect ':controller/:action/:id'
|
771
|
+
end
|
772
|
+
x = setup_for_named_route
|
773
|
+
assert_equal(
|
774
|
+
{:controller => '/page', :action => 'show', :title => 'hi'},
|
775
|
+
x.new.send(:article_url, :title => 'hi')
|
776
|
+
)
|
777
|
+
assert_equal(
|
778
|
+
{:controller => '/page', :action => 'show', :title => 'hi', :day => 10, :year => 2005, :month => 6},
|
779
|
+
x.new.send(:article_url, :title => 'hi', :day => 10, :year => 2005, :month => 6)
|
780
|
+
)
|
781
|
+
end
|
782
|
+
|
692
783
|
def test_changing_controller
|
693
|
-
assert_equal ['/admin/stuff/show/10',
|
784
|
+
assert_equal ['/admin/stuff/show/10', []], rs.generate(
|
694
785
|
{:controller => 'stuff', :action => 'show', :id => 10},
|
695
786
|
{:controller => 'admin/user', :action => 'index'}
|
696
787
|
)
|
@@ -731,9 +822,9 @@ class RouteSetTests < Test::Unit::TestCase
|
|
731
822
|
rs.connect ':controller/:action/:id'
|
732
823
|
end
|
733
824
|
|
734
|
-
assert_equal ['/page/20',
|
735
|
-
assert_equal ['/page/20',
|
736
|
-
assert_equal ['/pages/boo',
|
825
|
+
assert_equal ['/page/20', []], rs.generate({:id => 20}, {:controller => 'pages'})
|
826
|
+
assert_equal ['/page/20', []], rs.generate(:controller => 'pages', :id => 20, :action => 'show')
|
827
|
+
assert_equal ['/pages/boo', []], rs.generate(:controller => 'pages', :action => 'boo')
|
737
828
|
end
|
738
829
|
|
739
830
|
def test_route_with_fixnum_default
|
@@ -742,10 +833,10 @@ class RouteSetTests < Test::Unit::TestCase
|
|
742
833
|
rs.connect ':controller/:action/:id'
|
743
834
|
end
|
744
835
|
|
745
|
-
assert_equal ['/page',
|
746
|
-
assert_equal ['/page',
|
747
|
-
assert_equal ['/page',
|
748
|
-
assert_equal ['/page/10',
|
836
|
+
assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page')
|
837
|
+
assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page', :id => 1)
|
838
|
+
assert_equal ['/page', []], rs.generate(:controller => 'content', :action => 'show_page', :id => '1')
|
839
|
+
assert_equal ['/page/10', []], rs.generate(:controller => 'content', :action => 'show_page', :id => 10)
|
749
840
|
|
750
841
|
ctrl = ::Controllers::ContentController
|
751
842
|
|
@@ -755,7 +846,7 @@ class RouteSetTests < Test::Unit::TestCase
|
|
755
846
|
end
|
756
847
|
|
757
848
|
def test_action_expiry
|
758
|
-
assert_equal ['/content',
|
849
|
+
assert_equal ['/content', []], rs.generate({:controller => 'content'}, {:controller => 'content', :action => 'show'})
|
759
850
|
end
|
760
851
|
|
761
852
|
def test_recognition_with_uppercase_controller_name
|
@@ -766,6 +857,111 @@ class RouteSetTests < Test::Unit::TestCase
|
|
766
857
|
assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin NewsFeed)))
|
767
858
|
assert_equal({'controller' => ::Controllers::Admin::NewsFeedController, 'action' => 'index'}, rs.recognize_path(%w(Admin News_Feed)))
|
768
859
|
end
|
860
|
+
|
861
|
+
def test_both_requirement_and_optional
|
862
|
+
rs.draw do
|
863
|
+
rs.blog('test/:year', :controller => 'post', :action => 'show',
|
864
|
+
:defaults => { :year => nil },
|
865
|
+
:requirements => { :year => /\d{4}/ }
|
866
|
+
)
|
867
|
+
rs.connect ':controller/:action/:id'
|
868
|
+
end
|
869
|
+
|
870
|
+
assert_equal ['/test', []], rs.generate(:controller => 'post', :action => 'show')
|
871
|
+
assert_equal ['/test', []], rs.generate(:controller => 'post', :action => 'show', :year => nil)
|
872
|
+
|
873
|
+
x = setup_for_named_route
|
874
|
+
assert_equal({:controller => '/post', :action => 'show'},
|
875
|
+
x.new.send(:blog_url))
|
876
|
+
end
|
877
|
+
|
878
|
+
def test_set_to_nil_forgets
|
879
|
+
rs.draw do
|
880
|
+
rs.connect 'pages/:year/:month/:day', :controller => 'content', :action => 'list_pages', :month => nil, :day => nil
|
881
|
+
rs.connect ':controller/:action/:id'
|
882
|
+
end
|
883
|
+
|
884
|
+
assert_equal ['/pages/2005', []],
|
885
|
+
rs.generate(:controller => 'content', :action => 'list_pages', :year => 2005)
|
886
|
+
assert_equal ['/pages/2005/6', []],
|
887
|
+
rs.generate(:controller => 'content', :action => 'list_pages', :year => 2005, :month => 6)
|
888
|
+
assert_equal ['/pages/2005/6/12', []],
|
889
|
+
rs.generate(:controller => 'content', :action => 'list_pages', :year => 2005, :month => 6, :day => 12)
|
890
|
+
|
891
|
+
assert_equal ['/pages/2005/6/4', []],
|
892
|
+
rs.generate({:day => 4}, {:controller => 'content', :action => 'list_pages', :year => '2005', :month => '6', :day => '12'})
|
893
|
+
|
894
|
+
assert_equal ['/pages/2005/6', []],
|
895
|
+
rs.generate({:day => nil}, {:controller => 'content', :action => 'list_pages', :year => '2005', :month => '6', :day => '12'})
|
896
|
+
|
897
|
+
assert_equal ['/pages/2005', []],
|
898
|
+
rs.generate({:day => nil, :month => nil}, {:controller => 'content', :action => 'list_pages', :year => '2005', :month => '6', :day => '12'})
|
899
|
+
end
|
900
|
+
|
901
|
+
def test_url_with_no_action_specified
|
902
|
+
rs.draw do
|
903
|
+
rs.connect '', :controller => 'content'
|
904
|
+
rs.connect ':controller/:action/:id'
|
905
|
+
end
|
906
|
+
|
907
|
+
assert_equal ['/', []], rs.generate(:controller => 'content', :action => 'index')
|
908
|
+
assert_equal ['/', []], rs.generate(:controller => 'content')
|
909
|
+
end
|
910
|
+
|
911
|
+
def test_named_url_with_no_action_specified
|
912
|
+
rs.draw do
|
913
|
+
rs.root '', :controller => 'content'
|
914
|
+
rs.connect ':controller/:action/:id'
|
915
|
+
end
|
916
|
+
|
917
|
+
assert_equal ['/', []], rs.generate(:controller => 'content', :action => 'index')
|
918
|
+
assert_equal ['/', []], rs.generate(:controller => 'content')
|
919
|
+
|
920
|
+
x = setup_for_named_route
|
921
|
+
assert_equal({:controller => '/content', :action => 'index'},
|
922
|
+
x.new.send(:root_url))
|
923
|
+
end
|
924
|
+
|
925
|
+
def test_url_generated_when_forgetting_action
|
926
|
+
[{:controller => 'content', :action => 'index'}, {:controller => 'content'}].each do |hash|
|
927
|
+
rs.draw do
|
928
|
+
rs.root '', hash
|
929
|
+
rs.connect ':controller/:action/:id'
|
930
|
+
end
|
931
|
+
assert_equal ['/', []], rs.generate({:action => nil}, {:controller => 'content', :action => 'hello'})
|
932
|
+
assert_equal ['/', []], rs.generate({:controller => 'content'})
|
933
|
+
assert_equal ['/content/hi', []], rs.generate({:controller => 'content', :action => 'hi'})
|
934
|
+
end
|
935
|
+
end
|
936
|
+
|
937
|
+
def test_named_route_method
|
938
|
+
rs.draw do
|
939
|
+
assert_raises(ArgumentError) { rs.categories 'categories', :controller => 'content', :action => 'categories' }
|
940
|
+
|
941
|
+
rs.named_route :categories, 'categories', :controller => 'content', :action => 'categories'
|
942
|
+
rs.connect ':controller/:action/:id'
|
943
|
+
end
|
944
|
+
|
945
|
+
assert_equal ['/categories', []], rs.generate(:controller => 'content', :action => 'categories')
|
946
|
+
assert_equal ['/content/hi', []], rs.generate({:controller => 'content', :action => 'hi'})
|
947
|
+
end
|
948
|
+
|
949
|
+
def test_named_route_helper_array
|
950
|
+
test_named_route_method
|
951
|
+
assert_equal [:categories_url, :hash_for_categories_url], ::ActionController::Routing::NamedRoutes::Helpers
|
952
|
+
end
|
953
|
+
|
954
|
+
def test_nil_defaults
|
955
|
+
rs.draw do
|
956
|
+
rs.connect 'journal',
|
957
|
+
:controller => 'content',
|
958
|
+
:action => 'list_journal',
|
959
|
+
:date => nil, :user_id => nil
|
960
|
+
rs.connect ':controller/:action/:id'
|
961
|
+
end
|
962
|
+
|
963
|
+
assert_equal ['/journal', []], rs.generate(:controller => 'content', :action => 'list_journal', :date => nil, :user_id => nil)
|
964
|
+
end
|
769
965
|
end
|
770
966
|
|
771
967
|
end
|