Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 1557

Show
Ignore:
Timestamp:
06/29/05 02:41:00 (3 years ago)
Author:
bitsweat
Message:

r1475@iwill: jeremy | 2005-06-28 23:19:51 -0700
Ticket 1543 - Fix test_process
r1476@iwill: jeremy | 2005-06-29 00:20:53 -0700
Correct expected, actual order for assert_equal. Use new render method in TestController.
r1477@iwill: jeremy | 2005-06-29 00:23:45 -0700
Generate route and assign parameters without modifying the user's params.
r1480@iwill: jeremy | 2005-06-29 00:28:52 -0700
Update changelog.
r1481@iwill: jeremy | 2005-06-29 00:34:02 -0700
Directly generate paths with a leading slash instead of tacking it on later.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/CHANGELOG

    r1555 r1557  
    11*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] 
    26 
    37* Routes fail with leading slash #1540 [Nicholas Seckar] 
  • trunk/actionpack/lib/action_controller/assertions.rb

    r1533 r1557  
    124124      # Asserts that the provided options can be used to generate the provided path. 
    125125      def assert_generates(expected_path, options, defaults={}, extras = {}, message=nil) 
     126        expected_path = "/#{expected_path}" unless expected_path[0] == ?/ 
    126127        # Load routes.rb if it hasn't been loaded. 
    127128        ActionController::Routing::Routes.reload if ActionController::Routing::Routes.empty?  
  • trunk/actionpack/lib/action_controller/code_generation.rb

    r1502 r1557  
    218218     
    219219      def finish 
    220         line %("#{segments.join('/')}") 
     220        line %("/#{segments.join('/')}") 
    221221      end 
    222222 
  • trunk/actionpack/lib/action_controller/test_process.rb

    r1527 r1557  
    6767      @path || super() 
    6868    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 
    7374      parameters.each do |key, value| 
    7475        (extras.key?(key.to_sym) ? non_path_parameters : path_parameters)[key] = value 
     
    249250 
    250251          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) 
    254253 
    255254          @request.session = ActionController::TestSession.new(session) unless session.nil? 
     
    308307 
    309308        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 
    315316        end 
    316317 
  • trunk/actionpack/lib/action_controller/url_rewriter.rb

    r1496 r1557  
    4545        end 
    4646 
    47         path  = "/#{path}" 
    4847        path <<  build_query_string(extras) unless extras.empty? 
    4948         
  • trunk/actionpack/test/controller/routing_test.rb

    r1555 r1557  
    355355    go c 
    356356     
    357     assert_equal "hello/world", execute({}, {}) 
     357    assert_equal "/hello/world", execute({}, {}) 
    358358  end 
    359359   
     
    362362    go c 
    363363     
    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'}) 
    367367    assert_nil execute({},{}) 
    368368  end 
     
    372372    go c 
    373373     
    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({}, {}) 
    378378  end 
    379379   
     
    382382    go c 
    383383     
    384     assert_equal 'hi/index', execute({:action => 'index'}, {:action => 'index'}) 
     384    assert_equal '/hi/index', execute({:action => 'index'}, {:action => 'index'}) 
    385385    assert_nil execute({:action => 'fox5'}, {:action => 'index'}) 
    386386    assert_nil execute({:action => 'something_is_up'}, {:action => 'index'}) 
    387387    assert_nil execute({}, {:action => 'list people'}) 
    388     assert_equal 'hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {}) 
     388    assert_equal '/hi/abunchofcharacter', execute({:action => 'abunchofcharacter'}, {}) 
    389389    assert_nil execute({}, {}) 
    390390  end 
     
    394394    go c 
    395395     
    396     assert_equal 'hi', execute({:action => 'index'}, {:action => 'index'}) 
     396    assert_equal '/hi', execute({:action => 'index'}, {:action => 'index'}) 
    397397    assert_nil execute({:action => 'fox5'}, {:action => 'index'}) 
    398398    assert_nil execute({:action => 'something_is_up'}, {:action => 'index'}) 
    399399    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({}, {}) 
    402402  end 
    403403 
     
    406406    go c 
    407407     
    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'}, {}) 
    415415  end 
    416416   
     
    420420     
    421421    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'}) 
    426426  end 
    427427   
     
    431431     
    432432    # 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'})) 
    440440 
    441441    if time 
     
    468468    assert_nil execute({:action => 'elcome'}, {:controller => 'content'}) 
    469469 
    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'}) 
    473473  end 
    474474end 
     
    510510    assert_nil gen(:known => 'foo') 
    511511    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') 
    514514    assert_equal [:extra], route.extra_keys(:known => 'known_value', :extra => 'hi') 
    515515  end 
     
    526526    assert_nil gen(:controller => 'content', :action => 'show_person') 
    527527    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') 
    530530  end 
    531531   
     
    545545     
    546546     
    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') 
    555555  end 
    556556end 
     
    570570    assert_equal({:controller => ::Controllers::Admin::UserController, :action => 'show', :id => '10'}.stringify_keys, rs.recognize_path(%w(admin user show 10))) 
    571571     
    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'}) 
    576576  end 
    577577 
     
    675675 
    676676  def test_changing_controller 
    677     assert_equal ['admin/stuff/show/10', {}], rs.generate( 
     677    assert_equal ['/admin/stuff/show/10', {}], rs.generate( 
    678678      {:controller => 'stuff', :action => 'show', :id => 10}, 
    679679      {:controller => 'admin/user', :action => 'index'} 
  • trunk/actionpack/test/controller/test_test.rb

    r1505 r1557  
    88 
    99    def test_uri 
    10       render_text @request.request_uri 
     10      render :text => request.request_uri 
    1111    end 
    1212 
    1313    def test_html_output 
    14       render_text <<HTML 
     14      render :text => <<HTML 
    1515<html> 
    1616  <body> 
     
    5555  def test_process_with_request_uri_with_no_params 
    5656    process :test_uri 
    57     assert_equal @response.body, "/test_test/test/test_uri" 
     57    assert_equal "/test_test/test/test_uri", @response.body 
    5858  end 
    5959 
    6060  def test_process_with_request_uri_with_params 
    6161    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 
    6363  end 
    6464 
     
    6666    @request.set_REQUEST_URI "/explicit/uri" 
    6767    process :test_uri, :id => 7 
    68     assert_equal @response.body, "/explicit/uri" 
     68    assert_equal "/explicit/uri", @response.body 
    6969  end 
    7070