diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-19 13:34:54 -0800 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2011-12-19 13:34:54 -0800 |
commit | 9d0789c415111a3b3e85bdb5ed16d10f1f749d89 (patch) | |
tree | 89e27ef034ad7a774ef9d6ded3246abf575e75f5 /actionpack/test/controller | |
parent | 3c1884e7dd77d8f33f86e96fd7e4190c4a301133 (diff) | |
download | rails-9d0789c415111a3b3e85bdb5ed16d10f1f749d89.tar.gz rails-9d0789c415111a3b3e85bdb5ed16d10f1f749d89.tar.bz2 rails-9d0789c415111a3b3e85bdb5ed16d10f1f749d89.zip |
adding tests for #4029
Diffstat (limited to 'actionpack/test/controller')
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index 062fc1f94e..f40d663ae8 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -85,6 +85,57 @@ class LegacyRouteSetTests < Test::Unit::TestCase @rs.clear! end + def test_class_and_lambda_constraints + subdomain = Class.new { + def matches? request + request.subdomain.present? and request.subdomain != 'clients' + end + } + + @rs.draw do + match '/', :constraints => subdomain.new, + :to => lambda { |env| [200, {}, 'default'] } + match '/', :constraints => { :subdomain => 'clients' }, + :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 + end + + def test_lambda_constraints + @rs.draw do + match '/', :constraints => lambda { |req| + req.subdomain.present? and req.subdomain != "clients" }, + :to => lambda { |env| [200, {}, 'default'] } + + match '/', :constraints => lambda { |req| + req.subdomain.present? && req.subdomain == "clients" }, + :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 + end + def test_draw_with_block_arity_one_raises assert_raise(RuntimeError) do @rs.draw { |map| map.match '/:controller(/:action(/:id))' } |