diff options
author | Pratik Naik <pratiknaik@gmail.com> | 2009-02-22 23:52:02 +0100 |
---|---|---|
committer | Pratik Naik <pratiknaik@gmail.com> | 2009-02-22 23:52:02 +0100 |
commit | 21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd (patch) | |
tree | bfec5946303ceb582674904c5f9927e9b4020272 /actionpack/test/controller/routing_test.rb | |
parent | 91ab75373f13054485f5d804d7e2c80d466ff5e0 (diff) | |
parent | 441e4e22352c8805a882f6a661ab3982dd7eda12 (diff) | |
download | rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.gz rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.tar.bz2 rails-21b80f8144f8f05a105b2989c79d3ed2f2d0d4cd.zip |
Merge commit 'mainstream/master'
Diffstat (limited to 'actionpack/test/controller/routing_test.rb')
-rw-r--r-- | actionpack/test/controller/routing_test.rb | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/actionpack/test/controller/routing_test.rb b/actionpack/test/controller/routing_test.rb index d6fc6fddb2..13ba0c30dd 100644 --- a/actionpack/test/controller/routing_test.rb +++ b/actionpack/test/controller/routing_test.rb @@ -340,6 +340,30 @@ class ControllerSegmentTest < Test::Unit::TestCase end end +class PathSegmentTest < Test::Unit::TestCase + def segment(options = {}) + unless @segment + @segment = ROUTING::PathSegment.new(:path, options) + end + @segment + end + + def test_regexp_chunk_should_return_string + segment = segment(:regexp => /[a-z]+/) + assert_kind_of String, segment.regexp_chunk + end + + def test_regexp_chunk_should_be_wrapped_with_parenthesis + segment = segment(:regexp => /[a-z]+/) + assert_equal "([a-z]+)", segment.regexp_chunk + end + + def test_regexp_chunk_should_respect_options + segment = segment(:regexp => /[a-z]+/i) + assert_equal "((?i-mx:[a-z]+))", segment.regexp_chunk + end +end + class RouteBuilderTest < Test::Unit::TestCase def builder @builder ||= ROUTING::RouteBuilder.new @@ -852,6 +876,15 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal '/content/foo', rs.generate(:controller => "content", :action => "foo") end + def test_route_with_regexp_and_captures_for_controller + rs.draw do |map| + map.connect ':controller/:action/:id', :controller => /admin\/(accounts|users)/ + end + assert_equal({:controller => "admin/accounts", :action => "index"}, rs.recognize_path("/admin/accounts")) + assert_equal({:controller => "admin/users", :action => "index"}, rs.recognize_path("/admin/users")) + assert_raises(ActionController::RoutingError) { rs.recognize_path("/admin/products") } + end + def test_route_with_regexp_and_dot rs.draw do |map| map.connect ':controller/:action/:file', @@ -1134,6 +1167,7 @@ class LegacyRouteSetTests < Test::Unit::TestCase assert_equal({:controller => "content", :action => 'show_page', :id => 'foo'}, rs.recognize_path("/page/foo")) token = "\321\202\320\265\320\272\321\201\321\202" # 'text' in russian + token.force_encoding("UTF-8") if token.respond_to?(:force_encoding) escaped_token = CGI::escape(token) assert_equal '/page/' + escaped_token, rs.generate(:controller => 'content', :action => 'show_page', :id => token) |