aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/action_dispatch/routing/mapper_test.rb
blob: 9966234f1bff58b7395570026564c635cbd02bf5 (plain) (blame)
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 'abstract_unit'

module ActionDispatch
  module Routing
    class MapperTest < ActiveSupport::TestCase
      class FakeSet
        attr_reader :routes

        def initialize
          @routes = []
        end

        def resources_path_names
          {}
        end

        def request_class
          ActionDispatch::Request
        end

        def add_route(*args)
          routes << args
        end

        def conditions
          routes.map { |x| x[1] }
        end
      end

      def test_initialize
        Mapper.new FakeSet.new
      end

      def test_map_slash
        fakeset = FakeSet.new
        mapper = Mapper.new fakeset
        mapper.match '/', :to => 'posts#index', :as => :main
        assert_equal '/', fakeset.conditions.first[:path_info]
      end

      def test_map_more_slashes
        fakeset = FakeSet.new
        mapper = Mapper.new fakeset

        # FIXME: is this a desired behavior?
        mapper.match '/one/two/', :to => 'posts#index', :as => :main
        assert_equal '/one/two(.:format)', fakeset.conditions.first[:path_info]
      end
    end
  end
end