Methods
D
R
S
T
Included Modules
Instance Public methods
default_route_set()
# File actionpack/test/controller/routing_test.rb, line 847
def default_route_set
  @default_route_set ||= begin
    set = ROUTING::RouteSet.new
    set.draw do
      match '/:controller(/:action(/:id))'
    end
    set
  end
end
request()
# File actionpack/test/controller/routing_test.rb, line 843
def request
  @request ||= ActionController::TestRequest.new
end
set()
# File actionpack/test/controller/routing_test.rb, line 839
def set
  @set ||= ROUTING::RouteSet.new
end
setup_named_route_test()
# File actionpack/test/controller/routing_test.rb, line 932
def setup_named_route_test
  set.draw do
    match '/people(/:id)' => 'people#show', :as => 'show'
    match '/people' => 'people#index', :as => 'index'
    match '/people/go/:foo/:bar/joe(/:id)' => 'people#multi', :as => 'multi'
    match '/admin/users' => 'admin/users#index', :as => "users"
  end

  MockController.build(set.url_helpers).new
end
test_action_left_off_when_id_is_recalled()
# File actionpack/test/controller/routing_test.rb, line 1357
def test_action_left_off_when_id_is_recalled
  set.draw do
    match ':controller(/:action(/:id))'
  end
  assert_equal '/books', url_for(set,
    {:controller => 'books', :action => 'index'},
    {:controller => 'books', :action => 'show', :id => '10'}
  )
end
test_assign_route_options_with_anchor_chars()
# File actionpack/test/controller/routing_test.rb, line 1551
def test_assign_route_options_with_anchor_chars
  set.draw do
    match '/cars/:action/:person/:car/', :controller => 'cars'
  end

  assert_equal '/cars/buy/1/2', url_for(set, { :controller => 'cars', :action => 'buy', :person => '1', :car => '2' })

  assert_equal({:controller => "cars", :action => "buy", :person => "1", :car => "2"}, set.recognize_path('/cars/buy/1/2'))
end
test_build_empty_query_string()
# File actionpack/test/controller/routing_test.rb, line 1644
def test_build_empty_query_string
  assert_uri_equal '/foo', url_for(default_route_set, { :controller => 'foo' })
end
test_build_query_string_with_nil_value()
# File actionpack/test/controller/routing_test.rb, line 1648
def test_build_query_string_with_nil_value
  assert_uri_equal '/foo', url_for(default_route_set, { :controller => 'foo', :x => nil })
end
test_convert_ints_build_query_string()
# File actionpack/test/controller/routing_test.rb, line 1656
def test_convert_ints_build_query_string
  assert_uri_equal '/foo?x=1&y=2', url_for(default_route_set, { :controller => 'foo', :x => 1, :y => 2 })
end
test_default_route_recognition()
# File actionpack/test/controller/routing_test.rb, line 1601
def test_default_route_recognition
  expected = {:controller => 'pages', :action => 'show', :id => '10'}
  assert_equal expected, default_route_set.recognize_path('/pages/show/10')
  assert_equal expected, default_route_set.recognize_path('/pages/show/10/')

  expected[:id] = 'jamis'
  assert_equal expected, default_route_set.recognize_path('/pages/show/jamis/')

  expected.delete :id
  assert_equal expected, default_route_set.recognize_path('/pages/show')
  assert_equal expected, default_route_set.recognize_path('/pages/show/')

  expected[:action] = 'index'
  assert_equal expected, default_route_set.recognize_path('/pages/')
  assert_equal expected, default_route_set.recognize_path('/pages')

  assert_raise(ActionController::RoutingError) { default_route_set.recognize_path('/') }
  assert_raise(ActionController::RoutingError) { default_route_set.recognize_path('/pages/how/goood/it/is/to/be/free') }
end
test_default_route_should_include_default_action_when_id_present()
# File actionpack/test/controller/routing_test.rb, line 1625
def test_default_route_should_include_default_action_when_id_present
  assert_equal '/accounts/index/20', url_for(default_route_set, { :controller => 'accounts', :action => 'index', :id => '20' })
end
test_default_route_should_omit_default_action()
# File actionpack/test/controller/routing_test.rb, line 1621
def test_default_route_should_omit_default_action
  assert_equal '/accounts', url_for(default_route_set, { :controller => 'accounts', :action => 'index' })
end
test_default_route_should_uri_escape_pluses()
# File actionpack/test/controller/routing_test.rb, line 1633
def test_default_route_should_uri_escape_pluses
  expected = { :controller => 'pages', :action => 'show', :id => 'hello world' }
  assert_equal expected, default_route_set.recognize_path('/pages/show/hello%20world')
  assert_equal '/pages/show/hello%20world', url_for(default_route_set, expected)

  expected[:id] = 'hello+world'
  assert_equal expected, default_route_set.recognize_path('/pages/show/hello+world')
  assert_equal expected, default_route_set.recognize_path('/pages/show/hello%2Bworld')
  assert_equal '/pages/show/hello+world', url_for(default_route_set, expected)
end
test_default_route_should_work_with_action_but_no_id()
# File actionpack/test/controller/routing_test.rb, line 1629
def test_default_route_should_work_with_action_but_no_id
  assert_equal '/accounts/list_all', url_for(default_route_set, { :controller => 'accounts', :action => 'list_all' })
end
test_draw()
# File actionpack/test/controller/routing_test.rb, line 898
def test_draw
  assert_equal 0, set.routes.size
  set.draw do
    match '/hello/world' => 'a#b'
  end
  assert_equal 1, set.routes.size
end
test_draw_default_route()
# File actionpack/test/controller/routing_test.rb, line 1035
def test_draw_default_route
  set.draw do
    match '/:controller/:action/:id'
  end

  assert_equal 1, set.routes.size

  assert_equal '/users/show/10',  url_for(set, { :controller => 'users', :action => 'show', :id => 10 })
  assert_equal '/users/index/10', url_for(set, { :controller => 'users', :id => 10 })

  assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10'))
  assert_equal({:controller => 'users', :action => 'index', :id => '10'}, set.recognize_path('/users/index/10/'))
end
test_draw_symbol_controller_name()
# File actionpack/test/controller/routing_test.rb, line 906
def test_draw_symbol_controller_name
  assert_equal 0, set.routes.size
  set.draw do
    match '/users/index' => 'users#index'
  end
  set.recognize_path('/users/index', :method => :get)
  assert_equal 1, set.routes.size
end
test_escape_spaces_build_query_string()
# File actionpack/test/controller/routing_test.rb, line 1660
def test_escape_spaces_build_query_string
  assert_uri_equal '/foo?x=hello+world&y=goodbye+world', url_for(default_route_set, { :controller => 'foo', :x => 'hello world', :y => 'goodbye world' })
end
test_escape_spaces_build_query_string_selected_keys()
# File actionpack/test/controller/routing_test.rb, line 1668
def test_escape_spaces_build_query_string_selected_keys
  assert_uri_equal '/foo?x=hello+world', url_for(default_route_set, { :controller => 'foo', :x => 'hello world' })
end
test_expand_array_build_query_string()
# File actionpack/test/controller/routing_test.rb, line 1664
def test_expand_array_build_query_string
  assert_uri_equal '/foo?x%5B%5D=1&x%5B%5D=2', url_for(default_route_set, { :controller => 'foo', :x => [1, 2] })
end
test_expiry_determination_should_consider_values_with_to_param()
# File actionpack/test/controller/routing_test.rb, line 1394
def test_expiry_determination_should_consider_values_with_to_param
  set.draw { match 'projects/:project_id/:controller/:action' }
  assert_equal '/projects/1/weblog/show', url_for(set,
    { :action => 'show', :project_id => 1 },
    { :controller => 'weblog', :action => 'show', :project_id => '1' })
end
test_extra_keys()
# File actionpack/test/controller/routing_test.rb, line 864
def test_extra_keys
  set.draw { match ':controller/:action/:id' }
  extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  assert_equal %w(that this), extras.map { |e| e.to_s }.sort
end
test_extra_keys_not_first()
# File actionpack/test/controller/routing_test.rb, line 889
def test_extra_keys_not_first
  set.draw do
    match ':controller/:action/:id.:format'
    match ':controller/:action/:id'
  end
  extras = set.extra_keys(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  assert_equal %w(that this), extras.map { |e| e.to_s }.sort
end
test_format_is_not_inherit()
# File actionpack/test/controller/routing_test.rb, line 1378
def test_format_is_not_inherit
  set.draw do
    match '/posts(.:format)' => 'posts#index'
  end

  assert_equal '/posts', url_for(set,
    {:controller => 'posts'},
    {:controller => 'posts', :action => 'index', :format => 'xml'}
  )

  assert_equal '/posts.xml', url_for(set,
    {:controller => 'posts', :format => 'xml'},
    {:controller => 'posts', :action => 'index', :format => 'xml'}
  )
end
test_generate()
# File actionpack/test/controller/routing_test.rb, line 1312
def test_generate
  set.draw { match ':controller/:action/:id' }

  args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" }
  assert_equal "/foo/bar/7?x=y",     url_for(set, args)
  assert_equal ["/foo/bar/7", [:x]], set.generate_extras(args)
  assert_equal [:x], set.extra_keys(args)
end
test_generate_changes_controller_module()
# File actionpack/test/controller/routing_test.rb, line 1283
def test_generate_changes_controller_module
  set.draw { match ':controller/:action/:id' }
  current = { :controller => "bling/bloop", :action => "bap", :id => 9 }

  assert_equal "/foo/bar/baz/7",
      url_for(set, { :controller => "foo/bar", :action => "baz", :id => 7 }, current)
end
test_generate_extras()
# File actionpack/test/controller/routing_test.rb, line 857
def test_generate_extras
  set.draw { match ':controller/(:action(/:id))' }
  path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  assert_equal "/foo/bar/15", path
  assert_equal %w(that this), extras.map { |e| e.to_s }.sort
end
test_generate_extras_not_first()
# File actionpack/test/controller/routing_test.rb, line 870
def test_generate_extras_not_first
  set.draw do
    match ':controller/:action/:id.:format'
    match ':controller/:action/:id'
  end
  path, extras = set.generate_extras(:controller => "foo", :action => "bar", :id => 15, :this => "hello", :that => "world")
  assert_equal "/foo/bar/15", path
  assert_equal %w(that this), extras.map { |e| e.to_s }.sort
end
test_generate_not_first()
# File actionpack/test/controller/routing_test.rb, line 880
def test_generate_not_first
  set.draw do
    match ':controller/:action/:id.:format'
    match ':controller/:action/:id'
  end
  assert_equal "/foo/bar/15?this=hello",
      url_for(set, { :controller => "foo", :action => "bar", :id => 15, :this => "hello" })
end
test_generate_with_blank_path_prefix()
# File actionpack/test/controller/routing_test.rb, line 1332
def test_generate_with_blank_path_prefix
  set.draw do
    scope "" do
      match ':controller(/:action(/:id))'
    end
  end

  args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" }
  assert_equal "/foo/bar/7?x=y", url_for(set, args)
end
test_generate_with_default_action()
# File actionpack/test/controller/routing_test.rb, line 1215
def test_generate_with_default_action
  set.draw do
    match "/people", :controller => "people", :action => "index"
    match "/people/list", :controller => "people", :action => "list"
  end

  url = url_for(set, { :controller => "people", :action => "list" })
  assert_equal "/people/list", url
end
test_generate_with_default_params()
# File actionpack/test/controller/routing_test.rb, line 1672
def test_generate_with_default_params
  set.draw do
    match 'dummy/page/:page' => 'dummy#show'
    match 'dummy/dots/page.:page' => 'dummy#dots'
    match 'ibocorp(/:page)' => 'ibocorp#show',
                           :constraints => { :page => /\d+/ },
                           :defaults => { :page => 1 }

    match ':controller/:action/:id'
  end

  assert_equal '/ibocorp', url_for(set, { :controller => 'ibocorp', :action => "show", :page => 1 })
end
test_generate_with_optional_params_recalls_last_request()
# File actionpack/test/controller/routing_test.rb, line 1686
def test_generate_with_optional_params_recalls_last_request
  set.draw do
    match "blog/", :controller => "blog", :action => "index"

    match "blog(/:year(/:month(/:day)))",
          :controller => "blog",
          :action => "show_date",
          :constraints => { :year => /(19|20)\d\d/, :month => /[01]?\d/, :day => /[0-3]?\d/ },
          :day => nil, :month => nil

    match "blog/show/:id", :controller => "blog", :action => "show", :id => /\d+/
    match "blog/:controller/:action(/:id)"
    match "*anything", :controller => "blog", :action => "unknown_request"
  end

  assert_equal({:controller => "blog", :action => "index"}, set.recognize_path("/blog"))
  assert_equal({:controller => "blog", :action => "show", :id => "123"}, set.recognize_path("/blog/show/123"))
  assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :day => nil, :month => nil }, set.recognize_path("/blog/2004"))
  assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :month => "12", :day => nil }, set.recognize_path("/blog/2004/12"))
  assert_equal({:controller => "blog", :action => "show_date", :year => "2004", :month => "12", :day => "25"}, set.recognize_path("/blog/2004/12/25"))
  assert_equal({:controller => "articles", :action => "edit", :id => "123"}, set.recognize_path("/blog/articles/edit/123"))
  assert_equal({:controller => "articles", :action => "show_stats"}, set.recognize_path("/blog/articles/show_stats"))
  assert_equal({:controller => "blog", :action => "unknown_request", :anything => "blog/wibble"}, set.recognize_path("/blog/wibble"))
  assert_equal({:controller => "blog", :action => "unknown_request", :anything => "junk"}, set.recognize_path("/junk"))

  last_request = set.recognize_path("/blog/2006/07/28").freeze
  assert_equal({:controller => "blog",  :action => "show_date", :year => "2006", :month => "07", :day => "28"}, last_request)
  assert_equal("/blog/2006/07/25", url_for(set, { :day => 25 }, last_request))
  assert_equal("/blog/2005",       url_for(set, { :year => 2005 }, last_request))
  assert_equal("/blog/show/123",   url_for(set, { :action => "show" , :id => 123 }, last_request))
  assert_equal("/blog/2006",       url_for(set, { :year => 2006 }, last_request))
  assert_equal("/blog/2006",       url_for(set, { :year => 2006, :month => nil }, last_request))
end
test_generate_with_path_prefix()
# File actionpack/test/controller/routing_test.rb, line 1321
def test_generate_with_path_prefix
  set.draw do
    scope "my" do
      match ':controller(/:action(/:id))'
    end
  end

  args = { :controller => "foo", :action => "bar", :id => "7", :x => "y" }
  assert_equal "/my/foo/bar/7?x=y", url_for(set, args)
end
test_id_is_sticky_when_it_ought_to_be()
# File actionpack/test/controller/routing_test.rb, line 1291
def test_id_is_sticky_when_it_ought_to_be
  set.draw do
    match ':controller/:id/:action'
  end

  url = url_for(set, { :action => "destroy" }, { :controller => "people", :action => "show", :id => "7" })
  assert_equal "/people/7/destroy", url
end
test_later_named_routes_take_precedence()
# File actionpack/test/controller/routing_test.rb, line 924
def test_later_named_routes_take_precedence
  set.draw do
    match '/hello/world' => 'a#b', :as => 'hello'
    match '/hello'       => 'a#b', :as => 'hello'
  end
  assert_equal set.routes.last, set.named_routes[:hello]
end
test_named_draw()
# File actionpack/test/controller/routing_test.rb, line 915
def test_named_draw
  assert_equal 0, set.routes.size
  set.draw do
    match '/hello/world' => 'a#b', :as => 'hello'
  end
  assert_equal 1, set.routes.size
  assert_equal set.routes.first, set.named_routes[:hello]
end
test_named_route_hash_access_method()
# File actionpack/test/controller/routing_test.rb, line 943
def test_named_route_hash_access_method
  controller = setup_named_route_test

  assert_equal(
    { :controller => 'people', :action => 'show', :id => 5, :use_route => "show", :only_path => false },
    controller.send(:hash_for_show_url, :id => 5))

  assert_equal(
    { :controller => 'people', :action => 'index', :use_route => "index", :only_path => false },
    controller.send(:hash_for_index_url))

  assert_equal(
    { :controller => 'people', :action => 'show', :id => 5, :use_route => "show", :only_path => true },
    controller.send(:hash_for_show_path, :id => 5)
  )
end
test_named_route_in_nested_resource()
# File actionpack/test/controller/routing_test.rb, line 1401
def test_named_route_in_nested_resource
  set.draw do
    resources :projects do
      member do
        match 'milestones' => 'milestones#index', :as => 'milestones'
      end
    end
  end

  params = set.recognize_path("/projects/1/milestones", :method => :get)
  assert_equal("milestones", params[:controller])
  assert_equal("index", params[:action])
end
test_named_route_url_method()
# File actionpack/test/controller/routing_test.rb, line 960
def test_named_route_url_method
  controller = setup_named_route_test

  assert_equal "http://test.host/people/5", controller.send(:show_url, :id => 5)
  assert_equal "/people/5", controller.send(:show_path, :id => 5)

  assert_equal "http://test.host/people", controller.send(:index_url)
  assert_equal "/people", controller.send(:index_path)

  assert_equal "http://test.host/admin/users", controller.send(:users_url)
  assert_equal '/admin/users', controller.send(:users_path)
  assert_equal '/admin/users', url_for(set, controller.send(:hash_for_users_url), { :controller => 'users', :action => 'index' })
end
test_named_route_url_method_with_anchor()
# File actionpack/test/controller/routing_test.rb, line 974
def test_named_route_url_method_with_anchor
  controller = setup_named_route_test

  assert_equal "http://test.host/people/5#location", controller.send(:show_url, :id => 5, :anchor => 'location')
  assert_equal "/people/5#location", controller.send(:show_path, :id => 5, :anchor => 'location')

  assert_equal "http://test.host/people#location", controller.send(:index_url, :anchor => 'location')
  assert_equal "/people#location", controller.send(:index_path, :anchor => 'location')

  assert_equal "http://test.host/admin/users#location", controller.send(:users_url, :anchor => 'location')
  assert_equal '/admin/users#location', controller.send(:users_path, :anchor => 'location')

  assert_equal "http://test.host/people/go/7/hello/joe/5#location",
    controller.send(:multi_url, 7, "hello", 5, :anchor => 'location')

  assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar#location",
    controller.send(:multi_url, 7, "hello", 5, :baz => "bar", :anchor => 'location')

  assert_equal "http://test.host/people?baz=bar#location",
    controller.send(:index_url, :baz => "bar", :anchor => 'location')
end
test_named_route_url_method_with_host()
# File actionpack/test/controller/routing_test.rb, line 1001
def test_named_route_url_method_with_host
  controller = setup_named_route_test
  assert_equal "http://some.example.com/people/5", controller.send(:show_url, 5, :host=>"some.example.com")
end
test_named_route_url_method_with_no_positional_arguments()
# File actionpack/test/controller/routing_test.rb, line 1029
def test_named_route_url_method_with_no_positional_arguments
  controller = setup_named_route_test
  assert_equal "http://test.host/people?baz=bar",
    controller.send(:index_url, :baz => "bar")
end
test_named_route_url_method_with_ordered_parameters()
# File actionpack/test/controller/routing_test.rb, line 1011
def test_named_route_url_method_with_ordered_parameters
  controller = setup_named_route_test
  assert_equal "http://test.host/people/go/7/hello/joe/5",
    controller.send(:multi_url, 7, "hello", 5)
end
test_named_route_url_method_with_ordered_parameters_and_empty_hash()
# File actionpack/test/controller/routing_test.rb, line 1023
def test_named_route_url_method_with_ordered_parameters_and_empty_hash
  controller = setup_named_route_test
  assert_equal "http://test.host/people/go/7/hello/joe/5",
    controller.send(:multi_url, 7, "hello", 5, {})
end
test_named_route_url_method_with_ordered_parameters_and_hash()
# File actionpack/test/controller/routing_test.rb, line 1017
def test_named_route_url_method_with_ordered_parameters_and_hash
  controller = setup_named_route_test
  assert_equal "http://test.host/people/go/7/hello/joe/5?baz=bar",
    controller.send(:multi_url, 7, "hello", 5, :baz => "bar")
end
test_named_route_url_method_with_port()
# File actionpack/test/controller/routing_test.rb, line 996
def test_named_route_url_method_with_port
  controller = setup_named_route_test
  assert_equal "http://test.host:8080/people/5", controller.send(:show_url, 5, :port=>8080)
end
test_named_route_url_method_with_protocol()
# File actionpack/test/controller/routing_test.rb, line 1006
def test_named_route_url_method_with_protocol
  controller = setup_named_route_test
  assert_equal "https://test.host/people/5", controller.send(:show_url, 5, :protocol => "https")
end
test_named_routes_are_never_relative_to_modules()
# File actionpack/test/controller/routing_test.rb, line 1343
def test_named_routes_are_never_relative_to_modules
  set.draw do
    match "/connection/manage(/:action)" => 'connection/manage#index'
    match "/connection/connection" => "connection/connection#index"
    match '/connection' => 'connection#index', :as => 'family_connection'
  end

  url = url_for(set, { :controller => "connection" }, { :controller => 'connection/manage' })
  assert_equal "/connection/connection", url

  url = url_for(set, { :use_route => :family_connection, :controller => "connection" }, { :controller => 'connection/manage' })
  assert_equal "/connection", url
end
test_namespace()
# File actionpack/test/controller/routing_test.rb, line 1233
def test_namespace
  set.draw do

    namespace 'api' do
      match 'inventory' => 'products#inventory'
    end

  end

  params = set.recognize_path("/api/inventory", :method => :get)
  assert_equal("api/products", params[:controller])
  assert_equal("inventory", params[:action])
end
test_namespace_with_blank_path_prefix()
# File actionpack/test/controller/routing_test.rb, line 1271
def test_namespace_with_blank_path_prefix
  set.draw do
    scope :module => "api", :path => "" do
      match 'inventory' => 'products#inventory'
    end
  end

  params = set.recognize_path("/inventory", :method => :get)
  assert_equal("api/products", params[:controller])
  assert_equal("inventory", params[:action])
end
test_namespace_with_path_prefix()
# File actionpack/test/controller/routing_test.rb, line 1259
def test_namespace_with_path_prefix
  set.draw do
    scope :module => "api", :path => "prefix" do
      match 'inventory' => 'products#inventory'
    end
  end

  params = set.recognize_path("/prefix/inventory", :method => :get)
  assert_equal("api/products", params[:controller])
  assert_equal("inventory", params[:action])
end
test_namespaced_root_map()
# File actionpack/test/controller/routing_test.rb, line 1247
def test_namespaced_root_map
  set.draw do
    namespace 'api' do
      root :to => 'products#index'
    end
  end

  params = set.recognize_path("/api", :method => :get)
  assert_equal("api/products", params[:controller])
  assert_equal("index", params[:action])
end
test_query_params_will_be_shown_when_recalled()
# File actionpack/test/controller/routing_test.rb, line 1367
def test_query_params_will_be_shown_when_recalled
  set.draw do
    match 'show_weblog/:parameter' => 'weblog#show'
    match ':controller(/:action(/:id))'
  end
  assert_equal '/weblog/edit?parameter=1', url_for(set,
    {:action => 'edit', :parameter => 1},
    {:controller => 'weblog', :action => 'show', :parameter => 1}
  )
end
test_recognize_with_alias_in_conditions()
# File actionpack/test/controller/routing_test.rb, line 1155
def test_recognize_with_alias_in_conditions
  set.draw do
    match "/people" => 'people#index', :as => 'people', :via => :get
    root :to => "people#index"
  end

  params = set.recognize_path("/people", :method => :get)
  assert_equal("people", params[:controller])
  assert_equal("index", params[:action])

  params = set.recognize_path("/", :method => :get)
  assert_equal("people", params[:controller])
  assert_equal("index", params[:action])
end
test_recognize_with_conditions_and_format()
# File actionpack/test/controller/routing_test.rb, line 1195
def test_recognize_with_conditions_and_format
  set.draw do
    get "people/:id" => "people#show", :as => "person"
    put "people/:id" => "people#update"
    get "people/:id(.:format)" => "people#show"
  end

  params = set.recognize_path("/people/5", :method => :get)
  assert_equal("show", params[:action])
  assert_equal("5", params[:id])

  params = set.recognize_path("/people/5", :method => :put)
  assert_equal("update", params[:action])

  params = set.recognize_path("/people/5.png", :method => :get)
  assert_equal("show", params[:action])
  assert_equal("5", params[:id])
  assert_equal("png", params[:format])
end
test_recognize_with_encoded_id_and_regex()
# File actionpack/test/controller/routing_test.rb, line 1107
def test_recognize_with_encoded_id_and_regex
  set.draw do
    match 'page/:id' => 'pages#show', :id => /[a-zA-Z0-9\+]+/
  end

  assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10'))
  assert_equal({:controller => 'pages', :action => 'show', :id => 'hello+world'}, set.recognize_path('/page/hello+world'))
end
test_recognize_with_http_methods()
# File actionpack/test/controller/routing_test.rb, line 1116
def test_recognize_with_http_methods
  set.draw do
    get    "/people"     => "people#index", :as => "people"
    post   "/people"     => "people#create"
    get    "/people/:id" => "people#show",  :as => "person"
    put    "/people/:id" => "people#update"
    delete "/people/:id" => "people#destroy"
  end

  params = set.recognize_path("/people", :method => :get)
  assert_equal("index", params[:action])

  params = set.recognize_path("/people", :method => :post)
  assert_equal("create", params[:action])

  params = set.recognize_path("/people/5", :method => :put)
  assert_equal("update", params[:action])

  assert_raise(ActionController::UnknownHttpMethod) {
    set.recognize_path("/people", :method => :bacon)
  }

  params = set.recognize_path("/people/5", :method => :get)
  assert_equal("show", params[:action])
  assert_equal("5", params[:id])

  params = set.recognize_path("/people/5", :method => :put)
  assert_equal("update", params[:action])
  assert_equal("5", params[:id])

  params = set.recognize_path("/people/5", :method => :delete)
  assert_equal("destroy", params[:action])
  assert_equal("5", params[:id])

  assert_raise(ActionController::RoutingError) {
    set.recognize_path("/people/5", :method => :post)
  }
end
test_regexp_chunk_should_add_question_mark_for_optionals()
# File actionpack/test/controller/routing_test.rb, line 1538
def test_regexp_chunk_should_add_question_mark_for_optionals
  set.draw do
    match '/' => 'foo#index'
    match '/hello' => 'bar#index'
  end

  assert_equal '/',      url_for(set, { :controller => 'foo' })
  assert_equal '/hello', url_for(set, { :controller => 'bar' })

  assert_equal({:controller => "foo", :action => "index"}, set.recognize_path('/'))
  assert_equal({:controller => "bar", :action => "index"}, set.recognize_path('/hello'))
end
test_root_map()
# File actionpack/test/controller/routing_test.rb, line 1225
def test_root_map
  set.draw { root :to => 'people#index' }

  params = set.recognize_path("", :method => :get)
  assert_equal("people", params[:controller])
  assert_equal("index", params[:action])
end
test_route_constraints_on_request_object_with_anchors_are_valid()
# File actionpack/test/controller/routing_test.rb, line 1063
def test_route_constraints_on_request_object_with_anchors_are_valid
  assert_nothing_raised do
    set.draw do
      match 'page/:id' => 'pages#show', :constraints => { :host => /^foo$/ }
    end
  end
end
test_route_constraints_with_anchor_chars_are_invalid()
# File actionpack/test/controller/routing_test.rb, line 1071
def test_route_constraints_with_anchor_chars_are_invalid
  assert_raise ArgumentError do
    set.draw do
      match 'page/:id' => 'pages#show', :id => /^\d+/
    end
  end
  assert_raise ArgumentError do
    set.draw do
      match 'page/:id' => 'pages#show', :id => /\A\d+/
    end
  end
  assert_raise ArgumentError do
    set.draw do
      match 'page/:id' => 'pages#show', :id => /\d+$/
    end
  end
  assert_raise ArgumentError do
    set.draw do
      match 'page/:id' => 'pages#show', :id => /\d+\Z/
    end
  end
  assert_raise ArgumentError do
    set.draw do
      match 'page/:id' => 'pages#show', :id => /\d+\z/
    end
  end
end
test_route_constraints_with_options_method_condition_is_valid()
# File actionpack/test/controller/routing_test.rb, line 1099
def test_route_constraints_with_options_method_condition_is_valid
  assert_nothing_raised do
    set.draw do
      match 'valid/route' => 'pages#show', :via => :options
    end
  end
end
test_route_constraints_with_supported_options_must_not_error()
# File actionpack/test/controller/routing_test.rb, line 1444
def test_route_constraints_with_supported_options_must_not_error
  assert_nothing_raised do
    set.draw do
      match 'page/:name' => 'pages#show',
        :constraints => { :name => /(david|jamis)/i }
    end
  end
  assert_nothing_raised do
    set.draw do
      match 'page/:name' => 'pages#show',
        :constraints => { :name => / # Desperately overcommented regexp
                                    ( #Either
                                     david #The Creator
                                    | #Or
                                      jamis #The Deployer
                                    )/x }
    end
  end
end
test_route_constraints_with_unsupported_regexp_options_must_error()
# File actionpack/test/controller/routing_test.rb, line 1435
def test_route_constraints_with_unsupported_regexp_options_must_error
  assert_raise ArgumentError do
    set.draw do
      match 'page/:name' => 'pages#show',
        :constraints => { :name => /(david|jamis)/m }
    end
  end
end
test_route_requirement_generate_with_ignore_case()
# File actionpack/test/controller/routing_test.rb, line 1476
def test_route_requirement_generate_with_ignore_case
  set.draw do
    match 'page/:name' => 'pages#show',
      :constraints => {:name => /(david|jamis)/i}
  end

  url = url_for(set, { :controller => 'pages', :action => 'show', :name => 'david' })
  assert_equal "/page/david", url
  assert_raise ActionController::RoutingError do
    url_for(set, { :controller => 'pages', :action => 'show', :name => 'davidjamis' })
  end
  url = url_for(set, { :controller => 'pages', :action => 'show', :name => 'JAMIS' })
  assert_equal "/page/JAMIS", url
end
test_route_requirement_recognize_with_extended_syntax()
# File actionpack/test/controller/routing_test.rb, line 1491
def test_route_requirement_recognize_with_extended_syntax
  set.draw do
    match 'page/:name' => 'pages#show',
      :constraints => {:name => / # Desperately overcommented regexp
                                  ( #Either
                                   david #The Creator
                                  | #Or
                                    jamis #The Deployer
                                  )/x}
  end
  assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
  assert_equal({:controller => 'pages', :action => 'show', :name => 'david'}, set.recognize_path('/page/david'))
  assert_raise ActionController::RoutingError do
    set.recognize_path('/page/david #The Creator')
  end
  assert_raise ActionController::RoutingError do
    set.recognize_path('/page/David')
  end
end
test_route_requirement_recognize_with_ignore_case()
# File actionpack/test/controller/routing_test.rb, line 1464
def test_route_requirement_recognize_with_ignore_case
  set.draw do
    match 'page/:name' => 'pages#show',
      :constraints => {:name => /(david|jamis)/i}
  end
  assert_equal({:controller => 'pages', :action => 'show', :name => 'jamis'}, set.recognize_path('/page/jamis'))
  assert_raise ActionController::RoutingError do
    set.recognize_path('/page/davidjamis')
  end
  assert_equal({:controller => 'pages', :action => 'show', :name => 'DAVID'}, set.recognize_path('/page/DAVID'))
end
test_route_requirement_with_xi_modifiers()
# File actionpack/test/controller/routing_test.rb, line 1511
def test_route_requirement_with_xi_modifiers
  set.draw do
    match 'page/:name' => 'pages#show',
      :constraints => {:name => / # Desperately overcommented regexp
                                  ( #Either
                                   david #The Creator
                                  | #Or
                                    jamis #The Deployer
                                  )/xi}
  end

  assert_equal({:controller => 'pages', :action => 'show', :name => 'JAMIS'},
      set.recognize_path('/page/JAMIS'))

  assert_equal "/page/JAMIS",
      url_for(set, { :controller => 'pages', :action => 'show', :name => 'JAMIS' })
end
test_route_with_parameter_shell()
# File actionpack/test/controller/routing_test.rb, line 1049
def test_route_with_parameter_shell
  set.draw do
    match 'page/:id' => 'pages#show', :id => /\d+/
    match '/:controller(/:action(/:id))'
  end

  assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages'))
  assert_equal({:controller => 'pages', :action => 'index'}, set.recognize_path('/pages/index'))
  assert_equal({:controller => 'pages', :action => 'list'}, set.recognize_path('/pages/list'))

  assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/pages/show/10'))
  assert_equal({:controller => 'pages', :action => 'show', :id => '10'}, set.recognize_path('/page/10'))
end
test_routes_with_symbols()
# File actionpack/test/controller/routing_test.rb, line 1529
def test_routes_with_symbols
  set.draw do
    match 'unnamed', :controller => :pages, :action => :show, :name => :as_symbol
    match 'named'  , :controller => :pages, :action => :show, :name => :as_symbol, :as => :named
  end
  assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/unnamed'))
  assert_equal({:controller => 'pages', :action => 'show', :name => :as_symbol}, set.recognize_path('/named'))
end
test_routing_traversal_does_not_load_extra_classes()
# File actionpack/test/controller/routing_test.rb, line 1184
def test_routing_traversal_does_not_load_extra_classes
  assert !Object.const_defined?("Profiler__"), "Profiler should not be loaded"
  set.draw do
    match '/profile' => 'profile#index'
  end

  set.recognize_path("/profile") rescue nil

  assert !Object.const_defined?("Profiler__"), "Profiler should not be loaded"
end
test_segmentation_of_dot_path()
# File actionpack/test/controller/routing_test.rb, line 1561
def test_segmentation_of_dot_path
  set.draw do
    match '/books/:action.rss', :controller => 'books'
  end

  assert_equal '/books/list.rss', url_for(set, { :controller => 'books', :action => 'list' })

  assert_equal({:controller => "books", :action => "list"}, set.recognize_path('/books/list.rss'))
end
test_segmentation_of_dynamic_dot_path()
# File actionpack/test/controller/routing_test.rb, line 1571
def test_segmentation_of_dynamic_dot_path
  set.draw do
    match '/books(/:action(.:format))', :controller => 'books'
  end

  assert_equal '/books/list.rss', url_for(set, { :controller => 'books', :action => 'list', :format => 'rss' })
  assert_equal '/books/list.xml', url_for(set, { :controller => 'books', :action => 'list', :format => 'xml' })
  assert_equal '/books/list',     url_for(set, { :controller => 'books', :action => 'list' })
  assert_equal '/books',          url_for(set, { :controller => 'books', :action => 'index' })

  assert_equal({:controller => "books", :action => "list", :format => "rss"}, set.recognize_path('/books/list.rss'))
  assert_equal({:controller => "books", :action => "list", :format => "xml"}, set.recognize_path('/books/list.xml'))
  assert_equal({:controller => "books", :action => "list"},  set.recognize_path('/books/list'))
  assert_equal({:controller => "books", :action => "index"}, set.recognize_path('/books'))
end
test_setting_root_in_namespace_using_string()
# File actionpack/test/controller/routing_test.rb, line 1425
def test_setting_root_in_namespace_using_string
  assert_nothing_raised do
    set.draw do
      namespace 'admin' do
        root :to => "home#index"
      end
    end
  end
end
test_setting_root_in_namespace_using_symbol()
# File actionpack/test/controller/routing_test.rb, line 1415
def test_setting_root_in_namespace_using_symbol
  assert_nothing_raised do
    set.draw do
      namespace :admin do
        root :to => "home#index"
      end
    end
  end
end
test_simple_build_query_string()
# File actionpack/test/controller/routing_test.rb, line 1652
def test_simple_build_query_string
  assert_uri_equal '/foo?x=1&y=2', url_for(default_route_set, { :controller => 'foo', :x => '1', :y => '2' })
end
test_slashes_are_implied()
# File actionpack/test/controller/routing_test.rb, line 1587
def test_slashes_are_implied
  @set = nil
  set.draw { match("/:controller(/:action(/:id))") }

  assert_equal '/content',        url_for(set, { :controller => 'content', :action => 'index' })
  assert_equal '/content/list',   url_for(set, { :controller => 'content', :action => 'list' })
  assert_equal '/content/show/1', url_for(set, { :controller => 'content', :action => 'show', :id => '1' })

  assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content'))
  assert_equal({:controller => "content", :action => "index"}, set.recognize_path('/content/index'))
  assert_equal({:controller => "content", :action => "list"},  set.recognize_path('/content/list'))
  assert_equal({:controller => "content", :action => "show", :id => "1"}, set.recognize_path('/content/show/1'))
end
test_typo_recognition()
# File actionpack/test/controller/routing_test.rb, line 1170
def test_typo_recognition
  set.draw do
    match 'articles/:year/:month/:day/:title' => 'articles#permalink',
           :year => /\d{4}/, :day => /\d{1,2}/, :month => /\d{1,2}/
  end

  params = set.recognize_path("/articles/2005/11/05/a-very-interesting-article", :method => :get)
  assert_equal("permalink", params[:action])
  assert_equal("2005", params[:year])
  assert_equal("11", params[:month])
  assert_equal("05", params[:day])
  assert_equal("a-very-interesting-article", params[:title])
end
test_use_static_path_when_possible()
# File actionpack/test/controller/routing_test.rb, line 1300
def test_use_static_path_when_possible
  set.draw do
    match 'about' => "welcome#about"
    match ':controller/:action/:id'
  end

  url = url_for(set, { :controller => "welcome", :action => "about" },
    { :controller => "welcome", :action => "get", :id => "7" })

  assert_equal "/about", url
end