diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-15 14:31:53 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-15 14:32:04 -0700 |
commit | 703275ba70efbefb3358052b6ba750443eff1a28 (patch) | |
tree | 162e50fd7538df691b25ee23285b09e2503ca20e /actionpack/test/journey/routes_test.rb | |
parent | 05eea6a2c3fc4a2eeec04819abedc0c5a909d63c (diff) | |
download | rails-703275ba70efbefb3358052b6ba750443eff1a28.tar.gz rails-703275ba70efbefb3358052b6ba750443eff1a28.tar.bz2 rails-703275ba70efbefb3358052b6ba750443eff1a28.zip |
use the mapper to build the routing table
We should build the routes using the user facing API which is `Mapper`.
This frees up the library internals to change as we see fit. IOW we
shouldn't be testing internals.
Diffstat (limited to 'actionpack/test/journey/routes_test.rb')
-rw-r--r-- | actionpack/test/journey/routes_test.rb | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/actionpack/test/journey/routes_test.rb b/actionpack/test/journey/routes_test.rb index bbe3228bf2..f8293dfc5f 100644 --- a/actionpack/test/journey/routes_test.rb +++ b/actionpack/test/journey/routes_test.rb @@ -3,27 +3,19 @@ require 'abstract_unit' module ActionDispatch module Journey class TestRoutes < ActiveSupport::TestCase - attr_reader :routes + attr_reader :routes, :mapper def setup @route_set = ActionDispatch::Routing::RouteSet.new @routes = @route_set.router.routes @router = @route_set.router + @mapper = ActionDispatch::Routing::Mapper.new @route_set super end - MyMapping = Struct.new(:application, :path, :conditions, :required_defaults, :defaults) - - def add_route(app, path, conditions, required_defaults, defaults, name = nil) - @routes.add_route(name, MyMapping.new(app, path, conditions, required_defaults, defaults)) - end - def test_clear - path = Path::Pattern.build '/foo(/:id)', {}, ['/.?'], true - requirements = { :hello => /world/ } - - add_route nil, path, requirements, [], {:id => nil}, {} - assert_not routes.empty? + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' + assert_not_predicate routes, :empty? assert_equal 1, routes.length routes.clear @@ -32,41 +24,32 @@ module ActionDispatch end def test_ast - path = Path::Pattern.from_string '/hello' - - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' ast = routes.ast - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby' assert_not_equal ast, routes.ast end def test_simulator_changes - path = Path::Pattern.from_string '/hello' - - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' sim = routes.simulator - add_route nil, path, {}, [], {}, {} + mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby' assert_not_equal sim, routes.simulator end def test_partition_route - path = Path::Pattern.from_string '/hello' + mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron' - anchored_route = add_route nil, path, {}, [], {}, {} - assert_equal [anchored_route], @routes.anchored_routes - assert_equal [], @routes.custom_routes + assert_equal 1, @routes.anchored_routes.length + assert_predicate @routes.custom_routes, :empty? - path = Path::Pattern.build( - "/hello/:who", { who: /\d/ }, ['/', '.', '?'], false - ) + mapper.get "/hello/:who", to: "foo#bar", as: 'bar', who: /\d/ - custom_route = add_route nil, path, {}, [], {}, {} - assert_equal [custom_route], @routes.custom_routes - assert_equal [anchored_route], @routes.anchored_routes + assert_equal 1, @routes.custom_routes.length + assert_equal 1, @routes.anchored_routes.length end def test_first_name_wins - 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' |