File: test_routes.rb

package info (click to toggle)
ruby-journey 1.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 288 kB
  • sloc: ruby: 2,817; yacc: 42; makefile: 2
file content (51 lines) | stat: -rw-r--r-- 1,345 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'helper'

module Journey
  class TestRoutes < MiniTest::Unit::TestCase
    def test_clear
      routes = Routes.new
      exp    = Router::Strexp.new '/foo(/:id)', {}, ['/.?']
      path   = Path::Pattern.new exp
      requirements = { :hello => /world/ }

      routes.add_route nil, path, requirements, {:id => nil}, {}
      assert_equal 1, routes.length

      routes.clear
      assert_equal 0, routes.length
    end

    def test_ast
      routes = Routes.new
      path   = Path::Pattern.new '/hello'

      routes.add_route nil, path, {}, {}, {}
      ast = routes.ast
      routes.add_route nil, path, {}, {}, {}
      refute_equal ast, routes.ast
    end

    def test_simulator_changes
      routes = Routes.new
      path   = Path::Pattern.new '/hello'

      routes.add_route nil, path, {}, {}, {}
      sim = routes.simulator
      routes.add_route nil, path, {}, {}, {}
      refute_equal sim, routes.simulator
    end

    # FIXME: first name *should* win, revert this after Rails 3.2 release
    def test_last_name_wins
      routes = Routes.new

      one   = Path::Pattern.new '/hello'
      two   = Path::Pattern.new '/aaron'

      routes.add_route nil, one, {}, {}, 'aaron'
      routes.add_route nil, two, {}, {}, 'aaron'

      assert_equal '/aaron', routes.named_routes['aaron'].path.spec.to_s
    end
  end
end