Changeset 1557
- Timestamp:
- 06/29/05 02:41:00 (3 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_controller/assertions.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/code_generation.rb (modified) (1 diff)
- trunk/actionpack/lib/action_controller/test_process.rb (modified) (3 diffs)
- trunk/actionpack/lib/action_controller/url_rewriter.rb (modified) (1 diff)
- trunk/actionpack/test/controller/routing_test.rb (modified) (14 diffs)
- trunk/actionpack/test/controller/test_test.rb (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r1555 r1557 1 1 *SVN* 2 3 * Directly generate paths with a leading slash instead of tacking it on later. #1543 [Nicholas Seckar] 4 5 * Fixed errant parameter modification in functional tests. #1542 [Nicholas Seckar] 2 6 3 7 * Routes fail with leading slash #1540 [Nicholas Seckar] trunk/actionpack/lib/action_controller/assertions.rb
r1533 r1557 124 124 # Asserts that the provided options can be used to generate the provided path. 125 125 def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) 126 expected_path = "/#{expected_path}" unless expected_path[0] == ?/ 126 127 # Load routes.rb if it hasn't been loaded. 127 128 ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty? trunk/actionpack/lib/action_controller/code_generation.rb
r1502 r1557 218 218 219 219 def finish 220 line %(" #{segments.join('/')}")220 line %("/#{segments.join('/')}") 221 221 end 222 222 trunk/actionpack/lib/action_controller/test_process.rb
r1527 r1557 67 67 @path || super() 68 68 end 69 70 def assign_parameters(parameters) 71 path, extras = ActionController::Routing::Routes.generate(parameters.symbolize_keys) 72 non_path_parameters = (get? ? query_parameters : request_parameters) 69 70 def generate_route_and_assign_parameters(controller_path, action, parameters) 71 parameters = parameters.symbolize_keys.merge(:controller => controller_path, :action => action) 72 path, extras = ActionController::Routing::Routes.generate(parameters) 73 non_path_parameters = get? ? query_parameters : request_parameters 73 74 parameters.each do |key, value| 74 75 (extras.key?(key.to_sym) ? non_path_parameters : path_parameters)[key] = value … … 249 250 250 251 parameters ||= {} 251 parameters[:controller] = @controller.class.controller_path 252 parameters[:action] = action.to_s 253 @request.assign_parameters(parameters) 252 @request.generate_route_and_assign_parameters(@controller.class.controller_path, action.to_s, parameters) 254 253 255 254 @request.session = ActionController::TestSession.new(session) unless session.nil? … … 308 307 309 308 def build_request_uri(action, parameters) 310 return if @request.env['REQUEST_URI'] 311 url = ActionController::UrlRewriter.new(@request, parameters) 312 @request.set_REQUEST_URI( 313 url.rewrite(@controller.send(:rewrite_options, 314 (parameters||{}).update(:only_path => true, :action=>action)))) 309 unless @request.env['REQUEST_URI'] 310 options = @controller.send(:rewrite_options, parameters) 311 options.update(:only_path => true, :action => action) 312 313 url = ActionController::UrlRewriter.new(@request, parameters) 314 @request.set_REQUEST_URI(url.rewrite(options)) 315 end 315 316 end 316 317 trunk/actionpack/lib/action_controller/url_rewriter.rb
r1496 r1557 45 45 end 46 46 47 path = "/#{path}"48 47 path << build_query_string(extras) unless extras.empty? 49 48 trunk/actionpack/test/controller/routing_test.rb
r1555 r1557 355 355 go c 356 356 357 assert_equal " hello/world", execute({}, {})357 assert_equal "/hello/world", execute({}, {}) 358 358 end 359 359 … … 362 362 go c 363 363 364 assert_equal ' hi/index', execute({:action => 'index'}, {:action => 'index'})365 assert_equal ' hi/show', execute({:action => 'show'}, {:action => 'index'})366 assert_equal ' hi/list+people', execute({}, {:action => 'list people'})364 assert_equal '/hi/index', execute({:action => 'index'}, {:action => 'index'}) 365 assert_equal '/hi/show', execute({:action => 'show'}, {:action => 'index'}) 366 assert_equal '/hi/list+people', execute({}, {:action => 'list people'}) 367 367 assert_nil execute({},{}) 368 368 end … … 372 372 go c 373 373 374 assert_equal ' hi', execute({:action => 'index'}, {:action => 'index'})375 assert_equal ' hi/show', execute({:action => 'show'}, {:action => 'index'})376 assert_equal ' hi/list+people', execute({}, {:action => 'list people'})377 assert_equal ' hi', execute({}, {})374 assert_equal '/hi', execute({:action => 'index'}, {:action => 'index'}) 375 assert_equal '/hi/show', execute({:action => 'show'}, {:action => 'index'}) 376 assert_equal '/hi/list+people', execute({}, {:action => 'list people'}) 377 assert_equal '/hi', execute({}, {}) 378 378 end 379 379 … … 382 382 go c 383 383 384 assert_equal ' hi/index', execute({:action => 'index'}, {:action => 'index'})384 assert_equal '/hi/index', execute({:action => 'index'}, {:action => 'index'}) 385 385 assert_nil execute({:action => 'fox5'}, {:action => 'index'}) 386 386 assert_nil execute({:action => 'something_is_up'}, {:action => 'index'}) 387 387 assert_nil execute({}, {:action => 'list people'}) 388 assert_equal ' hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {})388 assert_equal '/hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {}) 389 389 assert_nil execute({}, {}) 390 390 end … … 394 394 go c 395 395 396 assert_equal ' hi', execute({:action => 'index'}, {:action => 'index'})396 assert_equal '/hi', execute({:action => 'index'}, {:action => 'index'}) 397 397 assert_nil execute({:action => 'fox5'}, {:action => 'index'}) 398 398 assert_nil execute({:action => 'something_is_up'}, {:action => 'index'}) 399 399 assert_nil execute({}, {:action => 'list people'}) 400 assert_equal ' hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {})401 assert_equal ' hi', execute({}, {})400 assert_equal '/hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {}) 401 assert_equal '/hi', execute({}, {}) 402 402 end 403 403 … … 406 406 go c 407 407 408 assert_equal ' hi', execute({:file => []}, {})409 assert_equal ' hi/books/agile_rails_dev.pdf', execute({:file => %w(books agile_rails_dev.pdf)}, {})410 assert_equal ' hi/books/development%26whatever/agile_rails_dev.pdf', execute({:file => %w(books development&whatever agile_rails_dev.pdf)}, {})411 412 assert_equal ' hi', execute({:file => ''}, {})413 assert_equal ' hi/books/agile_rails_dev.pdf', execute({:file => 'books/agile_rails_dev.pdf'}, {})414 assert_equal ' hi/books/development%26whatever/agile_rails_dev.pdf', execute({:file => 'books/development&whatever/agile_rails_dev.pdf'}, {})408 assert_equal '/hi', execute({:file => []}, {}) 409 assert_equal '/hi/books/agile_rails_dev.pdf', execute({:file => %w(books agile_rails_dev.pdf)}, {}) 410 assert_equal '/hi/books/development%26whatever/agile_rails_dev.pdf', execute({:file => %w(books development&whatever agile_rails_dev.pdf)}, {}) 411 412 assert_equal '/hi', execute({:file => ''}, {}) 413 assert_equal '/hi/books/agile_rails_dev.pdf', execute({:file => 'books/agile_rails_dev.pdf'}, {}) 414 assert_equal '/hi/books/development%26whatever/agile_rails_dev.pdf', execute({:file => 'books/development&whatever/agile_rails_dev.pdf'}, {}) 415 415 end 416 416 … … 420 420 421 421 assert_nil execute({}, {}) 422 assert_equal ' hi/content', execute({:controller => 'content'}, {})423 assert_equal ' hi/admin/user', execute({:controller => 'admin/user'}, {})424 assert_equal ' hi/content', execute({}, {:controller => 'content'})425 assert_equal ' hi/admin/user', execute({}, {:controller => 'admin/user'})422 assert_equal '/hi/content', execute({:controller => 'content'}, {}) 423 assert_equal '/hi/admin/user', execute({:controller => 'admin/user'}, {}) 424 assert_equal '/hi/content', execute({}, {:controller => 'content'}) 425 assert_equal '/hi/admin/user', execute({}, {:controller => 'admin/user'}) 426 426 end 427 427 … … 431 431 432 432 # Make sure we get the right answers 433 assert_equal(' content', execute({:action => 'index'}, {:controller => 'content', :action => 'list'}))434 assert_equal(' content/list', execute({:action => 'list'}, {:controller => 'content', :action => 'index'}))435 assert_equal(' content/show/10', execute({:action => 'show', :id => '10'}, {:controller => 'content', :action => 'list'}))436 437 assert_equal(' admin/user', execute({:action => 'index'}, {:controller => 'admin/user', :action => 'list'}))438 assert_equal(' admin/user/list', execute({:action => 'list'}, {:controller => 'admin/user', :action => 'index'}))439 assert_equal(' admin/user/show/10', execute({:action => 'show', :id => '10'}, {:controller => 'admin/user', :action => 'list'}))433 assert_equal('/content', execute({:action => 'index'}, {:controller => 'content', :action => 'list'})) 434 assert_equal('/content/list', execute({:action => 'list'}, {:controller => 'content', :action => 'index'})) 435 assert_equal('/content/show/10', execute({:action => 'show', :id => '10'}, {:controller => 'content', :action => 'list'})) 436 437 assert_equal('/admin/user', execute({:action => 'index'}, {:controller => 'admin/user', :action => 'list'})) 438 assert_equal('/admin/user/list', execute({:action => 'list'}, {:controller => 'admin/user', :action => 'index'})) 439 assert_equal('/admin/user/show/10', execute({:action => 'show', :id => '10'}, {:controller => 'admin/user', :action => 'list'})) 440 440 441 441 if time … … 468 468 assert_nil execute({:action => 'elcome'}, {:controller => 'content'}) 469 469 470 assert_equal ' ', execute({:controller => 'content', :action => 'welcome'}, {})471 assert_equal ' ', execute({:action => 'welcome'}, {:controller => 'content'})472 assert_equal ' ', execute({:action => 'welcome', :id => '10'}, {:controller => 'content'})470 assert_equal '/', execute({:controller => 'content', :action => 'welcome'}, {}) 471 assert_equal '/', execute({:action => 'welcome'}, {:controller => 'content'}) 472 assert_equal '/', execute({:action => 'welcome', :id => '10'}, {:controller => 'content'}) 473 473 end 474 474 end … … 510 510 assert_nil gen(:known => 'foo') 511 511 assert_nil gen({}) 512 assert_equal ' hello/world', gen(:known => 'known_value')513 assert_equal ' hello/world', gen(:known => 'known_value', :extra => 'hi')512 assert_equal '/hello/world', gen(:known => 'known_value') 513 assert_equal '/hello/world', gen(:known => 'known_value', :extra => 'hi') 514 514 assert_equal [:extra], route.extra_keys(:known => 'known_value', :extra => 'hi') 515 515 end … … 526 526 assert_nil gen(:controller => 'content', :action => 'show_person') 527 527 assert_nil gen(:controller => 'admin/user', :action => 'show_person', :name => 'rails') 528 assert_equal ' hello/rails', gen(:controller => 'content', :action => 'show_person', :name => 'rails')529 assert_equal ' hello/Nicholas+Seckar', gen(:controller => 'content', :action => 'show_person', :name => 'Nicholas Seckar')528 assert_equal '/hello/rails', gen(:controller => 'content', :action => 'show_person', :name => 'rails') 529 assert_equal '/hello/Nicholas+Seckar', gen(:controller => 'content', :action => 'show_person', :name => 'Nicholas Seckar') 530 530 end 531 531 … … 545 545 546 546 547 assert_equal ' content', gen(:controller => 'content', :action => 'index')548 assert_equal ' content/list', gen(:controller => 'content', :action => 'list')549 assert_equal ' content/show/10', gen(:controller => 'content', :action => 'show', :id => '10')550 551 assert_equal ' admin/user', gen(:controller => 'admin/user', :action => 'index')552 assert_equal ' admin/user', gen(:controller => 'admin/user')553 assert_equal ' admin/user', gen({:controller => 'admin/user'}, {:controller => 'content', :action => 'list', :id => '10'})554 assert_equal ' admin/user/show/10', gen(:controller => 'admin/user', :action => 'show', :id => '10')547 assert_equal '/content', gen(:controller => 'content', :action => 'index') 548 assert_equal '/content/list', gen(:controller => 'content', :action => 'list') 549 assert_equal '/content/show/10', gen(:controller => 'content', :action => 'show', :id => '10') 550 551 assert_equal '/admin/user', gen(:controller => 'admin/user', :action => 'index') 552 assert_equal '/admin/user', gen(:controller => 'admin/user') 553 assert_equal '/admin/user', gen({:controller => 'admin/user'}, {:controller => 'content', :action => 'list', :id => '10'}) 554 assert_equal '/admin/user/show/10', gen(:controller => 'admin/user', :action => 'show', :id => '10') 555 555 end 556 556 end … … 570 570 assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10))) 571 571 572 assert_equal [' admin/user/show/10', {}], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10})573 574 assert_equal [' admin/user/show', {}], rs.generate({:action => 'show'}, {:controller => 'admin/user', :action => 'list', :id => '10'})575 assert_equal [' admin/user/list/10', {}], rs.generate({}, {:controller => 'admin/user', :action => 'list', :id => '10'})572 assert_equal ['/admin/user/show/10', {}], rs.generate({:controller => 'admin/user', :action => 'show', :id => 10}) 573 574 assert_equal ['/admin/user/show', {}], rs.generate({:action => 'show'}, {:controller => 'admin/user', :action => 'list', :id => '10'}) 575 assert_equal ['/admin/user/list/10', {}], rs.generate({}, {:controller => 'admin/user', :action => 'list', :id => '10'}) 576 576 end 577 577 … … 675 675 676 676 def test_changing_controller 677 assert_equal [' admin/stuff/show/10', {}], rs.generate(677 assert_equal ['/admin/stuff/show/10', {}], rs.generate( 678 678 {:controller => 'stuff', :action => 'show', :id => 10}, 679 679 {:controller => 'admin/user', :action => 'index'} trunk/actionpack/test/controller/test_test.rb
r1505 r1557 8 8 9 9 def test_uri 10 render _text @request.request_uri10 render :text => request.request_uri 11 11 end 12 12 13 13 def test_html_output 14 render _text<<HTML14 render :text => <<HTML 15 15 <html> 16 16 <body> … … 55 55 def test_process_with_request_uri_with_no_params 56 56 process :test_uri 57 assert_equal @response.body, "/test_test/test/test_uri"57 assert_equal "/test_test/test/test_uri", @response.body 58 58 end 59 59 60 60 def test_process_with_request_uri_with_params 61 61 process :test_uri, :id => 7 62 assert_equal @response.body, "/test_test/test/test_uri/7"62 assert_equal "/test_test/test/test_uri/7", @response.body 63 63 end 64 64 … … 66 66 @request.set_REQUEST_URI "/explicit/uri" 67 67 process :test_uri, :id => 7 68 assert_equal @response.body, "/explicit/uri"68 assert_equal "/explicit/uri", @response.body 69 69 end 70 70