Permalink
Browse files

refactoring routing tests

Conflicts:

	actionpack/test/controller/routing_test.rb
  • Loading branch information...
1 parent 040b794 commit 3e00e1f6e31941dadd885a6844de997d7dc33a10 @tenderlove tenderlove committed Dec 22, 2011
Showing with 30 additions and 23 deletions.
  1. +30 −23 actionpack/test/controller/routing_test.rb
@@ -85,13 +85,38 @@ 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]
end
def teardown
@rs.clear!
end
+ def test_regexp_precidence
+ @rs.draw do
+ match '/whois/:domain', :constraints => {
+ :domain => /\w+\.[\w\.]+/ },
+ :to => lambda { |env| [200, {}, 'regexp'] }
+
+ match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] }
+ end
+
+ 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
subdomain = Class.new {
def matches? request
@@ -106,17 +131,8 @@ def matches? request
:to => lambda { |env| [200, {}, '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
@@ -130,17 +146,8 @@ def test_lambda_constraints
:to => lambda { |env| [200, {}, '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

0 comments on commit 3e00e1f

Please sign in to comment.