aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--actionpack/test/controller/routing_test.rb65
1 files changed, 25 insertions, 40 deletions
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb
index a931222bbc..715cc229e1 100644
--- a/actionpack/test/controller/routing_test.rb
+++ b/actionpack/test/controller/routing_test.rb
@@ -78,29 +78,32 @@ class LegacyRouteSetTests < Test::Unit::TestCase
attr_reader :rs
def setup
- @rs = ::ActionDispatch::Routing::RouteSet.new
+ @rs = ::ActionDispatch::Routing::RouteSet.new
+ @response = nil
+ end
+
+ def get(uri_or_host, path = nil, port = nil)
+ host = uri_or_host.host unless path
+ path ||= uri_or_host.path
+
+ params = {'PATH_INFO' => path,
+ 'REQUEST_METHOD' => 'GET',
+ 'HTTP_HOST' => host}
+
+ @rs.call(params)[2].join
end
def test_regexp_precidence
@rs.draw do
match '/whois/:domain', :constraints => {
:domain => /\w+\.[\w\.]+/ },
- :to => lambda { |env| [200, {}, 'regexp'] }
+ :to => lambda { |env| [200, {}, %w{regexp}] }
- match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] }
+ match '/whois/:id', :to => lambda { |env| [200, {}, %w{id}] }
end
- body = @rs.call({'PATH_INFO' => '/whois/example.org',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'www.example.org'})[2]
-
- assert_equal 'regexp', body
-
- body = @rs.call({'PATH_INFO' => '/whois/123',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'clients.example.org'})[2]
-
- assert_equal 'id', body
+ assert_equal 'regexp', get(URI('http://example.org/whois/example.org'))
+ assert_equal 'id', get(URI('http://example.org/whois/123'))
end
def test_class_and_lambda_constraints
@@ -112,46 +115,28 @@ class LegacyRouteSetTests < Test::Unit::TestCase
@rs.draw do
match '/', :constraints => subdomain.new,
- :to => lambda { |env| [200, {}, 'default'] }
+ :to => lambda { |env| [200, {}, %w{default}] }
match '/', :constraints => { :subdomain => 'clients' },
- :to => lambda { |env| [200, {}, 'clients'] }
+ :to => lambda { |env| [200, {}, %w{clients}] }
end
- body = @rs.call({'PATH_INFO' => '/',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'www.example.org'})[2]
-
- assert_equal 'default', body
-
- body = @rs.call({'PATH_INFO' => '/',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'clients.example.org'})[2]
-
- assert_equal 'clients', body
+ assert_equal 'default', get(URI('http://www.example.org/'))
+ assert_equal 'clients', get(URI('http://clients.example.org/'))
end
def test_lambda_constraints
@rs.draw do
match '/', :constraints => lambda { |req|
req.subdomain.present? and req.subdomain != "clients" },
- :to => lambda { |env| [200, {}, 'default'] }
+ :to => lambda { |env| [200, {}, %w{default}] }
match '/', :constraints => lambda { |req|
req.subdomain.present? && req.subdomain == "clients" },
- :to => lambda { |env| [200, {}, 'clients'] }
+ :to => lambda { |env| [200, {}, %w{clients}] }
end
- body = @rs.call({'PATH_INFO' => '/',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'www.example.org'})[2]
-
- assert_equal 'default', body
-
- body = @rs.call({'PATH_INFO' => '/',
- 'REQUEST_METHOD' => 'GET',
- 'HTTP_HOST' => 'clients.example.org'})[2]
-
- assert_equal 'clients', body
+ assert_equal 'default', get(URI('http://www.example.org/'))
+ assert_equal 'clients', get(URI('http://clients.example.org/'))
end
def test_draw_with_block_arity_one_raises