Permalink
Browse files

adding tests for #4029

  • Loading branch information...
1 parent 2ddedac commit 040b7946d2c0b539f71909198cc0a3656d6ac9f8 @tenderlove tenderlove committed Dec 19, 2011
Showing with 52 additions and 1 deletion.
  1. +51 −0 actionpack/test/controller/routing_test.rb
  2. +1 −1 actionpack/test/dispatch/mount_test.rb
@@ -92,6 +92,57 @@ def teardown
@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))' }
@@ -51,4 +51,4 @@ def test_with_fake_engine_does_not_call_invalid_method
get "/fakeengine"
assert_equal "OK", response.body
end
-end
+end

0 comments on commit 040b794

Please sign in to comment.