2012-12-19 15:54:47 -05:00
|
|
|
require 'abstract_unit'
|
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Journey
|
2012-12-31 12:36:30 -05:00
|
|
|
class TestRoutes < ActiveSupport::TestCase
|
2015-08-15 17:31:53 -04:00
|
|
|
attr_reader :routes, :mapper
|
2015-08-14 19:25:03 -04:00
|
|
|
|
|
|
|
def setup
|
2015-08-14 21:04:49 -04:00
|
|
|
@route_set = ActionDispatch::Routing::RouteSet.new
|
|
|
|
@routes = @route_set.router.routes
|
|
|
|
@router = @route_set.router
|
2015-08-15 17:31:53 -04:00
|
|
|
@mapper = ActionDispatch::Routing::Mapper.new @route_set
|
2015-08-14 19:25:03 -04:00
|
|
|
super
|
|
|
|
end
|
|
|
|
|
2012-12-19 15:54:47 -05:00
|
|
|
def test_clear
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron'
|
|
|
|
assert_not_predicate routes, :empty?
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal 1, routes.length
|
|
|
|
|
|
|
|
routes.clear
|
2015-05-18 18:21:20 -04:00
|
|
|
assert routes.empty?
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal 0, routes.length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_ast
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron'
|
2012-12-19 15:54:47 -05:00
|
|
|
ast = routes.ast
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby'
|
2012-12-28 18:49:41 -05:00
|
|
|
assert_not_equal ast, routes.ast
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_simulator_changes
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron'
|
2012-12-19 15:54:47 -05:00
|
|
|
sim = routes.simulator
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'gorby'
|
2012-12-28 18:49:41 -05:00
|
|
|
assert_not_equal sim, routes.simulator
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
2014-06-18 22:16:30 -04:00
|
|
|
def test_partition_route
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/foo(/:id)", to: "foo#bar", as: 'aaron'
|
2014-06-18 22:16:30 -04:00
|
|
|
|
2015-08-15 17:31:53 -04:00
|
|
|
assert_equal 1, @routes.anchored_routes.length
|
|
|
|
assert_predicate @routes.custom_routes, :empty?
|
2014-06-18 22:16:30 -04:00
|
|
|
|
2015-08-15 17:31:53 -04:00
|
|
|
mapper.get "/hello/:who", to: "foo#bar", as: 'bar', who: /\d/
|
2014-06-18 22:16:30 -04:00
|
|
|
|
2015-08-15 17:31:53 -04:00
|
|
|
assert_equal 1, @routes.custom_routes.length
|
|
|
|
assert_equal 1, @routes.anchored_routes.length
|
2014-06-18 22:16:30 -04:00
|
|
|
end
|
|
|
|
|
2012-12-19 15:54:47 -05:00
|
|
|
def test_first_name_wins
|
2015-08-14 21:04:49 -04:00
|
|
|
mapper.get "/hello", to: "foo#bar", as: 'aaron'
|
|
|
|
assert_raise(ArgumentError) do
|
|
|
|
mapper.get "/aaron", to: "foo#bar", as: 'aaron'
|
|
|
|
end
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|