test_routes.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. require 'helper'
  2. module Journey
  3. class TestRoutes < MiniTest::Unit::TestCase
  4. def test_clear
  5. routes = Routes.new
  6. exp = Router::Strexp.new '/foo(/:id)', {}, ['/.?']
  7. path = Path::Pattern.new exp
  8. requirements = { :hello => /world/ }
  9. routes.add_route nil, path, requirements, {:id => nil}, {}
  10. assert_equal 1, routes.length
  11. routes.clear
  12. assert_equal 0, routes.length
  13. end
  14. def test_ast
  15. routes = Routes.new
  16. path = Path::Pattern.new '/hello'
  17. routes.add_route nil, path, {}, {}, {}
  18. ast = routes.ast
  19. routes.add_route nil, path, {}, {}, {}
  20. refute_equal ast, routes.ast
  21. end
  22. def test_simulator_changes
  23. routes = Routes.new
  24. path = Path::Pattern.new '/hello'
  25. routes.add_route nil, path, {}, {}, {}
  26. sim = routes.simulator
  27. routes.add_route nil, path, {}, {}, {}
  28. refute_equal sim, routes.simulator
  29. end
  30. # FIXME: first name *should* win, revert this after Rails 3.2 release
  31. def test_last_name_wins
  32. routes = Routes.new
  33. one = Path::Pattern.new '/hello'
  34. two = Path::Pattern.new '/aaron'
  35. routes.add_route nil, one, {}, {}, 'aaron'
  36. routes.add_route nil, two, {}, {}, 'aaron'
  37. assert_equal '/aaron', routes.named_routes['aaron'].path.spec.to_s
  38. end
  39. end
  40. end