diff options
Diffstat (limited to 'actionpack/test')
-rw-r--r-- | actionpack/test/dispatch/mapper_test.rb | 11 | ||||
-rw-r--r-- | actionpack/test/journey/path/pattern_test.rb | 68 | ||||
-rw-r--r-- | actionpack/test/journey/route_test.rb | 3 | ||||
-rw-r--r-- | actionpack/test/journey/router_test.rb | 45 | ||||
-rw-r--r-- | actionpack/test/journey/routes_test.rb | 8 |
5 files changed, 65 insertions, 70 deletions
diff --git a/actionpack/test/dispatch/mapper_test.rb b/actionpack/test/dispatch/mapper_test.rb index 6ce0e34ec3..7ba946aa7f 100644 --- a/actionpack/test/dispatch/mapper_test.rb +++ b/actionpack/test/dispatch/mapper_test.rb @@ -44,6 +44,15 @@ module ActionDispatch Mapper.new FakeSet.new end + def test_scope_raises_on_anchor + fakeset = FakeSet.new + mapper = Mapper.new fakeset + assert_raises(ArgumentError) do + mapper.scope(anchor: false) do + end + end + end + def test_blows_up_without_via fakeset = FakeSet.new mapper = Mapper.new fakeset @@ -86,7 +95,7 @@ module ActionDispatch def test_mapping_requirements options = { } scope = Mapper::Scope.new({}) - m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', nil, 'foo', 'bar', nil, [:get], nil, options) + m = Mapper::Mapping.build(scope, FakeSet.new, '/store/:name(*rest)', 'foo', 'bar', nil, [:get], nil, {}, options) _, _, requirements, _ = m.to_route assert_equal(/.+?/, requirements[:rest]) end diff --git a/actionpack/test/journey/path/pattern_test.rb b/actionpack/test/journey/path/pattern_test.rb index 6939b426f6..7b97379bd5 100644 --- a/actionpack/test/journey/path/pattern_test.rb +++ b/actionpack/test/journey/path/pattern_test.rb @@ -19,12 +19,12 @@ module ActionDispatch '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))\Z}, }.each do |path, expected| define_method(:"test_to_regexp_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_equal(expected, path.to_regexp) end end @@ -43,13 +43,12 @@ module ActionDispatch '/:foo|*bar' => %r{\A/(?:([^/.?]+)|(.+))}, }.each do |path, expected| define_method(:"test_to_non_anchored_regexp_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, ["/", ".", "?"], false ) - path = Pattern.new strexp assert_equal(expected, path.to_regexp) end end @@ -67,27 +66,27 @@ module ActionDispatch '/:controller/*foo/bar' => %w{ controller foo }, }.each do |path, expected| define_method(:"test_names_#{path}") do - strexp = Router::Strexp.build( + path = Pattern.build( path, { :controller => /.+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_equal(expected, path.names) end end def test_to_regexp_with_extended_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => / #ROFL (tender|love #MAO )/x }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -105,23 +104,23 @@ module ActionDispatch end def test_to_regexp_match_non_optional - strexp = Router::Strexp.build( + path = Pattern.build( '/:name', { :name => /\d+/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_match(path, '/123') assert_no_match(path, '/') end def test_to_regexp_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_match(path, '/page/tender') assert_match(path, '/page/love') assert_no_match(path, '/page/loving') @@ -129,15 +128,13 @@ module ActionDispatch def test_ast_sets_regular_expressions requirements = { :name => /(tender|love)/, :value => /./ } - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/:value', requirements, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - assert_equal requirements, strexp.requirements - - path = Pattern.new strexp nodes = path.ast.grep(Nodes::Symbol) assert_equal 2, nodes.length nodes.each do |node| @@ -146,24 +143,24 @@ module ActionDispatch end def test_match_data_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name', { :name => /(tender|love)/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp match = path.match '/page/tender' assert_equal 'tender', match[1] assert_equal 2, match.length end def test_match_data_with_multi_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/:id', { :name => /t(((ender|love)))()/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp match = path.match '/page/tender/10' assert_equal 'tender', match[1] assert_equal '10', match[2] @@ -173,30 +170,29 @@ module ActionDispatch def test_star_with_custom_re z = /\d+/ - strexp = Router::Strexp.build( + path = Pattern.build( '/page/*foo', { :foo => z }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_equal(%r{\A/page/(#{z})\Z}, path.to_regexp) end def test_insensitive_regexp_with_group - strexp = Router::Strexp.build( + path = Pattern.build( '/page/:name/aaron', { :name => /(tender|love)/i }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Pattern.new strexp assert_match(path, '/page/TENDER/aaron') assert_match(path, '/page/loVE/aaron') assert_no_match(path, '/page/loVE/AAron') end def test_to_regexp_with_strexp - strexp = Router::Strexp.build('/:controller', { }, ["/", ".", "?"]) - path = Pattern.new strexp + path = Pattern.build('/:controller', { }, ["/", ".", "?"], true) x = %r{\A/([^/.?]+)\Z} assert_equal(x.source, path.source) diff --git a/actionpack/test/journey/route_test.rb b/actionpack/test/journey/route_test.rb index eff96a0abc..cdd59a3316 100644 --- a/actionpack/test/journey/route_test.rb +++ b/actionpack/test/journey/route_test.rb @@ -26,8 +26,7 @@ module ActionDispatch end def test_path_requirements_override_defaults - strexp = Router::Strexp.build(':name', { name: /love/ }, ['/']) - path = Path::Pattern.new strexp + path = Path::Pattern.build(':name', { name: /love/ }, ['/'], true) defaults = { name: 'tender' } route = Route.new('name', nil, path, nil, [], defaults) assert_equal(/love/, route.requirements[:name]) diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index 802fb93c69..5c6d9645fb 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -32,8 +32,7 @@ module ActionDispatch def test_dashes router = Router.new(routes) - exp = Router::Strexp.build '/foo-bar-baz', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/foo-bar-baz', {}, ['/.?'], true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -49,8 +48,7 @@ module ActionDispatch router = Router.new(routes) #match the escaped version of /ほげ - exp = Router::Strexp.build '/%E3%81%BB%E3%81%92', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/%E3%81%BB%E3%81%92', {}, ['/.?'], true routes.add_route nil, path, {}, [], {:id => nil}, {} @@ -68,8 +66,7 @@ module ActionDispatch requirements = { :hello => /world/ } - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -88,8 +85,7 @@ module ActionDispatch requirements = { :hello => /mom/ } - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true router.routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -115,8 +111,7 @@ module ActionDispatch def test_request_class_overrides_path_info router = Router.new(routes) - exp = Router::Strexp.build '/bar', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/bar', {}, ['/.?'], true routes.add_route nil, path, {}, [], {}, {} @@ -133,8 +128,8 @@ module ActionDispatch def test_regexp_first_precedence add_routes @router, [ - Router::Strexp.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?']), - Router::Strexp.build("/whois/:id(.:format)", {}, ['/', '.', '?']) + Path::Pattern.build("/whois/:domain", {:domain => /\w+\.[\w\.]+/}, ['/', '.', '?'], true), + Path::Pattern.build("/whois/:id(.:format)", {}, ['/', '.', '?'], true) ] env = rails_env 'PATH_INFO' => '/whois/example.com' @@ -152,7 +147,7 @@ module ActionDispatch def test_required_parts_verified_are_anchored add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false) + Path::Pattern.build("/foo/:id", { :id => /\d/ }, ['/', '.', '?'], false) ] assert_raises(ActionController::UrlGenerationError) do @@ -162,7 +157,7 @@ module ActionDispatch def test_required_parts_are_verified_when_building add_routes @router, [ - Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) + Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) ] path, _ = @formatter.generate(nil, { :id => '10' }, { }) @@ -175,7 +170,7 @@ module ActionDispatch def test_only_required_parts_are_verified add_routes @router, [ - Router::Strexp.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false) + Path::Pattern.build("/foo(/:id)", {:id => /\d/}, ['/', '.', '?'], false) ] path, _ = @formatter.generate(nil, { :id => '10' }, { }) @@ -190,8 +185,7 @@ module ActionDispatch def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - pattern = Router::Strexp.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - path = Path::Pattern.new pattern + path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) @router.routes.add_route nil, path, {}, [], {}, route_name error = assert_raises(ActionController::UrlGenerationError) do @@ -249,7 +243,7 @@ module ActionDispatch def test_recognize_with_unbound_regexp add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?'], false) + Path::Pattern.build("/foo", { }, ['/', '.', '?'], false) ] env = rails_env 'PATH_INFO' => '/foo/bar' @@ -262,7 +256,7 @@ module ActionDispatch def test_bound_regexp_keeps_path_info add_routes @router, [ - Router::Strexp.build("/foo", { }, ['/', '.', '?'], true) + Path::Pattern.build("/foo", { }, ['/', '.', '?'], true) ] env = rails_env 'PATH_INFO' => '/foo' @@ -329,8 +323,7 @@ module ActionDispatch def test_generate_slash params = [ [:controller, "tasks"], [:action, "show"] ] - str = Router::Strexp.build("/", Hash[params], ['/', '.', '?'], true) - path = Path::Pattern.new str + path = Path::Pattern.build("/", Hash[params], ['/', '.', '?'], true) @router.routes.add_route @app, path, {}, [], {}, {} @@ -498,12 +491,12 @@ module ActionDispatch end def test_namespaced_controller - strexp = Router::Strexp.build( + path = Path::Pattern.build( "/:controller(/:action(/:id))", { :controller => /.+?/ }, - ["/", ".", "?"] + ["/", ".", "?"], + true ) - path = Path::Pattern.new strexp app = Object.new route = @router.routes.add_route(app, path, {}, [], {}, {}) @@ -610,12 +603,12 @@ module ActionDispatch private - def add_routes router, paths + def add_routes router, paths, anchor = true paths.each do |path| if String === path path = Path::Pattern.from_string path else - path = Path::Pattern.new path + path end router.routes.add_route @app, path, {}, [], {}, {} end diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index b9dac8751c..6853cefc01 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -9,8 +9,7 @@ module ActionDispatch def test_clear routes = Routes.new - exp = Router::Strexp.build '/foo(/:id)', {}, ['/.?'] - path = Path::Pattern.new exp + path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true requirements = { :hello => /world/ } routes.add_route nil, path, requirements, [], {:id => nil}, {} @@ -49,10 +48,9 @@ module ActionDispatch assert_equal [anchored_route], @routes.anchored_routes assert_equal [], @routes.custom_routes - strexp = Router::Strexp.build( - "/hello/:who", { who: /\d/ }, ['/', '.', '?'] + path = Path::Pattern.build( + "/hello/:who", { who: /\d/ }, ['/', '.', '?'], false ) - path = Path::Pattern.new strexp custom_route = @routes.add_route nil, path, {}, [], {}, {} assert_equal [custom_route], @routes.custom_routes |