refactoring routing tests
This commit is contained in:
parent
62456a35f1
commit
de6e92fe53
@ -78,7 +78,19 @@ class LegacyRouteSetTests < Test::Unit::TestCase
|
|||||||
attr_reader :rs
|
attr_reader :rs
|
||||||
|
|
||||||
def setup
|
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
|
end
|
||||||
|
|
||||||
def test_regexp_precidence
|
def test_regexp_precidence
|
||||||
@ -90,17 +102,8 @@ def test_regexp_precidence
|
|||||||
match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] }
|
match '/whois/:id', :to => lambda { |env| [200, {}, 'id'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
body = @rs.call({'PATH_INFO' => '/whois/example.org',
|
assert_equal 'regexp', get(URI('http://example.org/whois/example.org'))
|
||||||
'REQUEST_METHOD' => 'GET',
|
assert_equal 'id', get(URI('http://example.org/whois/123'))
|
||||||
'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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_class_and_lambda_constraints
|
def test_class_and_lambda_constraints
|
||||||
@ -117,17 +120,8 @@ def matches? request
|
|||||||
:to => lambda { |env| [200, {}, 'clients'] }
|
:to => lambda { |env| [200, {}, 'clients'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
body = @rs.call({'PATH_INFO' => '/',
|
assert_equal 'default', get(URI('http://www.example.org/'))
|
||||||
'REQUEST_METHOD' => 'GET',
|
assert_equal 'clients', get(URI('http://clients.example.org/'))
|
||||||
'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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_lambda_constraints
|
def test_lambda_constraints
|
||||||
@ -141,17 +135,8 @@ def test_lambda_constraints
|
|||||||
:to => lambda { |env| [200, {}, 'clients'] }
|
:to => lambda { |env| [200, {}, 'clients'] }
|
||||||
end
|
end
|
||||||
|
|
||||||
body = @rs.call({'PATH_INFO' => '/',
|
assert_equal 'default', get(URI('http://www.example.org/'))
|
||||||
'REQUEST_METHOD' => 'GET',
|
assert_equal 'clients', get(URI('http://clients.example.org/'))
|
||||||
'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
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_draw_with_block_arity_one_raises
|
def test_draw_with_block_arity_one_raises
|
||||||
|
Loading…
Reference in New Issue
Block a user