diff --git a/actionpack/lib/action_dispatch/journey/formatter.rb b/actionpack/lib/action_dispatch/journey/formatter.rb index d8bb10ffabcfd5a557022bb8452ee1aebe3c5399..c19ff0f4dbc09f4df9c04c4e3780bc3e1e83b74a 100644 --- a/actionpack/lib/action_dispatch/journey/formatter.rb +++ b/actionpack/lib/action_dispatch/journey/formatter.rb @@ -155,7 +155,7 @@ def possibles(cache, options, depth = 0) def build_cache root = { ___routes: [] } - routes.each_with_index do |route, i| + routes.routes.each_with_index do |route, i| leaf = route.required_defaults.inject(root) do |h, tuple| h[tuple] ||= {} end diff --git a/actionpack/lib/action_dispatch/journey/routes.rb b/actionpack/lib/action_dispatch/journey/routes.rb index dacb0ccf48acb55c3f7415ec4ce05daee4d88340..4770b8b7cc4a98f0ebfd2b661eabfef592bccde1 100644 --- a/actionpack/lib/action_dispatch/journey/routes.rb +++ b/actionpack/lib/action_dispatch/journey/routes.rb @@ -5,11 +5,10 @@ module Journey # :nodoc: class Routes # :nodoc: include Enumerable - attr_reader :routes, :named_routes, :custom_routes, :anchored_routes + attr_reader :routes, :custom_routes, :anchored_routes def initialize @routes = [] - @named_routes = {} @ast = nil @anchored_routes = [] @custom_routes = [] @@ -37,7 +36,6 @@ def clear routes.clear anchored_routes.clear custom_routes.clear - named_routes.clear end def partition_route(route) @@ -72,7 +70,6 @@ def add_route(name, mapping) route.precedence = routes.length routes << route - named_routes[name] = route if name && !named_routes[name] partition_route(route) clear_cache! route diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 4f698c84ab130d9d13651cd836e3d56e8d90dead..30e308119d505c25f80c763d4a6fb21c8beaba73 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -143,6 +143,7 @@ def get(name) end def key?(name) + return unless name routes.key? name.to_sym end @@ -356,7 +357,7 @@ def initialize(config = DEFAULT_CONFIG) @set = Journey::Routes.new @router = Journey::Router.new @set - @formatter = Journey::Formatter.new @set + @formatter = Journey::Formatter.new self @dispatcher_class = Routing::RouteSet::Dispatcher end diff --git a/actionpack/test/journey/router_test.rb b/actionpack/test/journey/router_test.rb index bddfbe7ef0a8867ceccd2d807961086e4a9f5427..8a1414de8eaef92969846382985f9fb56aae73c8 100644 --- a/actionpack/test/journey/router_test.rb +++ b/actionpack/test/journey/router_test.rb @@ -8,9 +8,10 @@ class TestRouter < ActiveSupport::TestCase def setup @app = Routing::RouteSet::Dispatcher.new({}) - @routes = Routes.new - @router = Router.new(@routes) - @formatter = Formatter.new(@routes) + @route_set = ActionDispatch::Routing::RouteSet.new + @routes = @route_set.router.routes + @router = @route_set.router + @formatter = @route_set.formatter end class FakeRequestFeeler < ActionDispatch::Request @@ -184,8 +185,8 @@ def test_only_required_parts_are_verified def test_knows_what_parts_are_missing_from_named_route route_name = "gorby_thunderhorse" - path = Path::Pattern.build("/foo/:id", { :id => /\d+/ }, ['/', '.', '?'], false) - add_route nil, path, {}, [], {}, route_name + mapper = ActionDispatch::Routing::Mapper.new @route_set + mapper.get "/foo/:id", :as => route_name, :id => /\d+/, :to => "foo#bar" error = assert_raises(ActionController::UrlGenerationError) do @formatter.generate(route_name, { }, { }) diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index 01566f01487ecaa2882afd72fb015cecef7bfb31..bbe3228bf2b2e3fbf9238f91b37fbd2e592d38b8 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -6,7 +6,9 @@ class TestRoutes < ActiveSupport::TestCase attr_reader :routes def setup - @routes = Routes.new + @route_set = ActionDispatch::Routing::RouteSet.new + @routes = @route_set.router.routes + @router = @route_set.router super end @@ -64,13 +66,11 @@ def test_partition_route end def test_first_name_wins - one = Path::Pattern.from_string '/hello' - two = Path::Pattern.from_string '/aaron' - - add_route nil, one, {}, [], {}, 'aaron' - add_route nil, two, {}, [], {}, 'aaron' - - assert_equal '/hello', routes.named_routes['aaron'].path.spec.to_s + mapper = ActionDispatch::Routing::Mapper.new @route_set + mapper.get "/hello", to: "foo#bar", as: 'aaron' + assert_raise(ArgumentError) do + mapper.get "/aaron", to: "foo#bar", as: 'aaron' + end end end end