Methods
S
T
U
Instance Public methods
setup()
# File actionpack/test/controller/base_test.rb, line 216
def setup
  super
  @request.host = 'www.example.com'
end
test_last_named_route_wins()

When generating routes, the last defined named route wins. This is in contrast to route recognition where the first recognized route wins. This behavior will not exist in Rails 4.0.

See:

https://github.com/rails/rails/issues/4245
https://github.com/rails/rails/issues/4164
# File actionpack/test/controller/base_test.rb, line 230
def test_last_named_route_wins
  rs = ActionDispatch::Routing::RouteSet.new
  rs.draw do
    resources :purchases
    match 'purchase/:product_id' => 'purchases#new', :as => :new_purchase
    match 'purchase/:product_id' => 'purchases#new', :as => :correct_new_purchase
  end

  x = Struct.new(:rs, :tc) {
    include rs.named_routes.module
    public :correct_new_purchase_url
    public :new_purchase_url

    def url_for(options)
      options[:host] = 'example.org'
      rs.url_for(options)
    end
  }.new(rs, self)

  assert_equal "http://example.org/purchase/1", x.correct_new_purchase_url(1)
  assert_equal "http://example.org/purchase/1", x.new_purchase_url(1)
end
test_url_for_params_priority()
# File actionpack/test/controller/base_test.rb, line 253
def test_url_for_params_priority
  rs = ActionDispatch::Routing::RouteSet.new
  rs.draw do
    resources :models
    match 'special' => 'model#new', :as => :new_model
  end

  url_params = {
     :action     => "new",
     :controller => "model",
     :use_route  => "new_model",
     :only_path  => true }

  assert_equal '/special', rs.url_for(url_params)
end
test_url_for_query_params_included()
# File actionpack/test/controller/base_test.rb, line 269
def test_url_for_query_params_included
  rs = ActionDispatch::Routing::RouteSet.new
  rs.draw do
    match 'home' => 'pages#home'
  end

  options = {
    :action     => "home",
    :controller => "pages",
    :only_path  => true,
    :params     => { "token" => "secret" }
  }

  assert_equal '/home?token=secret', rs.url_for(options)
end
test_url_helpers_does_not_become_actions()
# File actionpack/test/controller/base_test.rb, line 300
def test_url_helpers_does_not_become_actions
  with_routing do |set|
    set.draw do
      match "account/overview"
    end

    @controller.class.send(:include, set.url_helpers)
    assert !@controller.class.action_methods.include?("account_overview_path")
  end
end
test_url_options_override()
# File actionpack/test/controller/base_test.rb, line 285
def test_url_options_override
  with_routing do |set|
    set.draw do
      match 'from_view', :to => 'url_options#from_view', :as => :from_view
      match ':controller/:action'
    end

    get :from_view, :route => "from_view_url"

    assert_equal 'http://www.override.com/from_view?locale=en', @response.body
    assert_equal 'http://www.override.com/from_view?locale=en', @controller.send(:from_view_url)
    assert_equal 'http://www.override.com/default_url_options/new?locale=en', @controller.url_for(:controller => 'default_url_options')
  end
end
url_for(options)
# File actionpack/test/controller/base_test.rb, line 243
def url_for(options)
  options[:host] = 'example.org'
  rs.url_for(options)
end