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

Ticket #6677: routing-test.diff

File routing-test.diff, 1.3 kB (added by mhw, 2 years ago)

test case for unit test

  • actionpack/test/controller/routing_test.rb

    old new  
    410410    assert_equal '/content/hi', rs.generate({:controller => 'content', :action => 'hi'}) 
    411411  end 
    412412 
     413  class MockRecord 
     414    def to_param 
     415      @id 
     416    end 
     417 
     418    def initialize(id) 
     419      @id = id 
     420    end 
     421  end 
     422 
     423  def test_url_generated_with_object_list 
     424    rs.draw do |map| 
     425      map.with_options :action => 'show' do |show| 
     426        show.a '/as/:id', :controller => 'as' 
     427        show.b '/as/:a_id/bs/:id', :controller => 'bs' 
     428        show.c '/as/:a_id/bs/:b_id/cs/:id', :controller => 'bs' 
     429        show.d '/as/:a_id/bs/:b_id/cs/:c_id/ds/:id', :controller => 'bs' 
     430      end 
     431    end 
     432 
     433    params = { :a_id => 10, :b_id => 11, :c_id => 12, :id => 13 } 
     434    x = setup_for_named_route.new 
     435 
     436    h = x.send(:b_path, MockRecord.new(21)) 
     437    h.delete :only_path 
     438    assert_equal '/as/10/bs/21', rs.generate(h, params) 
     439 
     440    h = x.send(:d_path, MockRecord.new(22), MockRecord.new(23)) 
     441    h.delete :only_path 
     442    assert_equal '/as/10/bs/11/cs/22/ds/23', rs.generate(h, params) 
     443  end 
     444 
    413445  def test_named_routes_array 
    414446    test_named_route_method 
    415447    assert_equal [:categories], rs.named_routes.names