diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2010-03-28 11:10:38 +0100 |
---|---|---|
committer | Rizwan Reza <rizwanreza@gmail.com> | 2010-03-28 23:31:13 +0430 |
commit | e1a70faea675499d717cef7662262ceb03b23975 (patch) | |
tree | 70e1e307e8cf6e8d94aa628096033491b9ead72b /actionpack/test/dispatch | |
parent | 5c058295d1e43ea88dd4161592844263a12f02ad (diff) | |
download | rails-e1a70faea675499d717cef7662262ceb03b23975.tar.gz rails-e1a70faea675499d717cef7662262ceb03b23975.tar.bz2 rails-e1a70faea675499d717cef7662262ceb03b23975.zip |
Add constraints to resources in new routing DSL
Signed-off-by: Rizwan Reza <rizwanreza@gmail.com>
Diffstat (limited to 'actionpack/test/dispatch')
-rw-r--r-- | actionpack/test/dispatch/routing_test.rb | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/actionpack/test/dispatch/routing_test.rb b/actionpack/test/dispatch/routing_test.rb index c4e71a8689..b1de96cee5 100644 --- a/actionpack/test/dispatch/routing_test.rb +++ b/actionpack/test/dispatch/routing_test.rb @@ -171,6 +171,12 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest resources :descriptions root :to => 'projects#index' end + + resources :products, :constraints => { :id => /\d{4}/ } do + resources :images + end + + resource :dashboard, :constraints => { :ip => /192\.168\.1\.\d{1,3}/ } end end @@ -794,6 +800,26 @@ class TestRoutingMapper < ActionDispatch::IntegrationTest end end + def test_resource_constraints + with_test_routes do + assert_raise(ActionController::RoutingError) { get '/products/1' } + get '/products' + assert_equal 'products#index', @response.body + get '/products/0001' + assert_equal 'products#show', @response.body + + assert_raise(ActionController::RoutingError) { get '/products/1/images' } + get '/products/0001/images' + assert_equal 'images#index', @response.body + get '/products/0001/images/1' + assert_equal 'images#show', @response.body + + assert_raise(ActionController::RoutingError) { get '/dashboard', {}, {'REMOTE_ADDR' => '10.0.0.100'} } + get '/dashboard', {}, {'REMOTE_ADDR' => '192.168.1.100'} + assert_equal 'dashboards#show', @response.body + end + end + private def with_test_routes yield |