@@ -1,144 +1,175 | |||||
1 | # Redmine - project management software |
|
1 | # Redmine - project management software | |
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
2 | # Copyright (C) 2006-2011 Jean-Philippe Lang | |
3 | # |
|
3 | # | |
4 | # This program is free software; you can redistribute it and/or |
|
4 | # This program is free software; you can redistribute it and/or | |
5 | # modify it under the terms of the GNU General Public License |
|
5 | # modify it under the terms of the GNU General Public License | |
6 | # as published by the Free Software Foundation; either version 2 |
|
6 | # as published by the Free Software Foundation; either version 2 | |
7 | # of the License, or (at your option) any later version. |
|
7 | # of the License, or (at your option) any later version. | |
8 | # |
|
8 | # | |
9 | # This program is distributed in the hope that it will be useful, |
|
9 | # This program is distributed in the hope that it will be useful, | |
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
12 | # GNU General Public License for more details. |
|
12 | # GNU General Public License for more details. | |
13 | # |
|
13 | # | |
14 | # You should have received a copy of the GNU General Public License |
|
14 | # You should have received a copy of the GNU General Public License | |
15 | # along with this program; if not, write to the Free Software |
|
15 | # along with this program; if not, write to the Free Software | |
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
17 |
|
17 | |||
18 | require File.expand_path('../../../test_helper', __FILE__) |
|
18 | require File.expand_path('../../../test_helper', __FILE__) | |
19 |
|
19 | |||
20 | class RoutingRepositoriesTest < ActionController::IntegrationTest |
|
20 | class RoutingRepositoriesTest < ActionController::IntegrationTest | |
21 | def setup |
|
21 | def setup | |
22 | @path_hash = repository_path_hash(%w[path to file.c]) |
|
22 | @path_hash = repository_path_hash(%w[path to file.c]) | |
23 | assert_equal "path/to/file.c", @path_hash[:path] |
|
23 | assert_equal "path/to/file.c", @path_hash[:path] | |
24 | assert_equal %w[path to file.c], @path_hash[:param] |
|
24 | assert_equal %w[path to file.c], @path_hash[:param] | |
25 | end |
|
25 | end | |
26 |
|
26 | |||
27 | def test_repositories |
|
27 | def test_repositories | |
28 | assert_routing( |
|
28 | assert_routing( | |
29 | { :method => 'get', |
|
29 | { :method => 'get', | |
30 | :path => "/projects/redmine/repository" }, |
|
30 | :path => "/projects/redmine/repository" }, | |
31 | { :controller => 'repositories', :action => 'show', :id => 'redmine' } |
|
31 | { :controller => 'repositories', :action => 'show', :id => 'redmine' } | |
32 | ) |
|
32 | ) | |
33 | ["get", "post"].each do |method| |
|
33 | ["get", "post"].each do |method| | |
34 | assert_routing( |
|
34 | assert_routing( | |
35 | { :method => method, |
|
35 | { :method => method, | |
36 | :path => "/projects/redmine/repository/edit" }, |
|
36 | :path => "/projects/redmine/repository/edit" }, | |
37 | { :controller => 'repositories', :action => 'edit', :id => 'redmine' } |
|
37 | { :controller => 'repositories', :action => 'edit', :id => 'redmine' } | |
38 | ) |
|
38 | ) | |
39 | end |
|
39 | end | |
40 | assert_routing( |
|
40 | assert_routing( | |
41 | { :method => 'get', |
|
41 | { :method => 'get', | |
42 | :path => "/projects/redmine/repository/statistics" }, |
|
42 | :path => "/projects/redmine/repository/statistics" }, | |
43 | { :controller => 'repositories', :action => 'stats', :id => 'redmine' } |
|
43 | { :controller => 'repositories', :action => 'stats', :id => 'redmine' } | |
44 | ) |
|
44 | ) | |
45 | end |
|
45 | end | |
46 |
|
46 | |||
47 | def test_repositories_revisions |
|
47 | def test_repositories_revisions | |
|
48 | empty_path_param = [] | |||
48 | assert_routing( |
|
49 | assert_routing( | |
49 | { :method => 'get', |
|
50 | { :method => 'get', | |
50 | :path => "/projects/redmine/repository/revisions" }, |
|
51 | :path => "/projects/redmine/repository/revisions" }, | |
51 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine' } |
|
52 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine' } | |
52 | ) |
|
53 | ) | |
53 | assert_routing( |
|
54 | assert_routing( | |
54 | { :method => 'get', |
|
55 | { :method => 'get', | |
55 | :path => "/projects/redmine/repository/revisions.atom" }, |
|
56 | :path => "/projects/redmine/repository/revisions.atom" }, | |
56 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine', |
|
57 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine', | |
57 | :format => 'atom' } |
|
58 | :format => 'atom' } | |
58 | ) |
|
59 | ) | |
59 | assert_routing( |
|
60 | assert_routing( | |
60 | { :method => 'get', |
|
61 | { :method => 'get', | |
61 | :path => "/projects/redmine/repository/revisions/2457" }, |
|
62 | :path => "/projects/redmine/repository/revisions/2457" }, | |
62 | { :controller => 'repositories', :action => 'revision', :id => 'redmine', |
|
63 | { :controller => 'repositories', :action => 'revision', :id => 'redmine', | |
63 | :rev => '2457' } |
|
64 | :rev => '2457' } | |
64 | ) |
|
65 | ) | |
65 | assert_routing( |
|
66 | assert_routing( | |
66 | { :method => 'get', |
|
67 | { :method => 'get', | |
|
68 | :path => "/projects/redmine/repository/revisions/2457/show" }, | |||
|
69 | { :controller => 'repositories', :action => 'show', :id => 'redmine', | |||
|
70 | :path => empty_path_param, :rev => '2457' } | |||
|
71 | ) | |||
|
72 | assert_routing( | |||
|
73 | { :method => 'get', | |||
|
74 | :path => "/projects/redmine/repository/revisions/2457/show/#{@path_hash[:path]}" }, | |||
|
75 | { :controller => 'repositories', :action => 'show', :id => 'redmine', | |||
|
76 | :path => @path_hash[:param] , :rev => '2457'} | |||
|
77 | ) | |||
|
78 | assert_routing( | |||
|
79 | { :method => 'get', | |||
|
80 | :path => "/projects/redmine/repository/revisions/2457/changes" }, | |||
|
81 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', | |||
|
82 | :path => empty_path_param, :rev => '2457' } | |||
|
83 | ) | |||
|
84 | assert_routing( | |||
|
85 | { :method => 'get', | |||
|
86 | :path => "/projects/redmine/repository/revisions/2457/changes/#{@path_hash[:path]}" }, | |||
|
87 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', | |||
|
88 | :path => @path_hash[:param] , :rev => '2457'} | |||
|
89 | ) | |||
|
90 | assert_routing( | |||
|
91 | { :method => 'get', | |||
67 | :path => "/projects/redmine/repository/revisions/2457/diff" }, |
|
92 | :path => "/projects/redmine/repository/revisions/2457/diff" }, | |
68 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
93 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', | |
69 | :rev => '2457' } |
|
94 | :rev => '2457' } | |
70 | ) |
|
95 | ) | |
71 | assert_routing( |
|
96 | assert_routing( | |
72 | { :method => 'get', |
|
97 | { :method => 'get', | |
73 | :path => "/projects/redmine/repository/revisions/2457/diff.diff" }, |
|
98 | :path => "/projects/redmine/repository/revisions/2457/diff.diff" }, | |
74 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
99 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', | |
75 | :rev => '2457', :format => 'diff' } |
|
100 | :rev => '2457', :format => 'diff' } | |
76 | ) |
|
101 | ) | |
77 | assert_routing( |
|
102 | assert_routing( | |
78 | { :method => 'get', |
|
103 | { :method => 'get', | |
79 | :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" }, |
|
104 | :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" }, | |
80 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
105 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', | |
81 | :path => @path_hash[:param], :rev => '2' } |
|
106 | :path => @path_hash[:param], :rev => '2' } | |
82 | ) |
|
107 | ) | |
83 | assert_routing( |
|
108 | assert_routing( | |
84 | { :method => 'get', |
|
109 | { :method => 'get', | |
85 | :path => "/projects/redmine/repository/revisions/2/entry/#{@path_hash[:path]}" }, |
|
110 | :path => "/projects/redmine/repository/revisions/2/entry/#{@path_hash[:path]}" }, | |
86 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
111 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', | |
87 | :path => @path_hash[:param], :rev => '2' } |
|
112 | :path => @path_hash[:param], :rev => '2' } | |
88 | ) |
|
113 | ) | |
89 | assert_routing( |
|
114 | assert_routing( | |
90 | { :method => 'get', |
|
115 | { :method => 'get', | |
91 | :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, |
|
116 | :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, | |
92 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
117 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', | |
93 | :path => @path_hash[:param], :rev => '2', :format => 'raw' } |
|
118 | :path => @path_hash[:param], :rev => '2', :format => 'raw' } | |
94 | ) |
|
119 | ) | |
|
120 | assert_routing( | |||
|
121 | { :method => 'get', | |||
|
122 | :path => "/projects/redmine/repository/revisions/2/annotate/#{@path_hash[:path]}" }, | |||
|
123 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', | |||
|
124 | :path => @path_hash[:param], :rev => '2' } | |||
|
125 | ) | |||
95 | end |
|
126 | end | |
96 |
|
127 | |||
97 | def test_repositories_non_revisions_path |
|
128 | def test_repositories_non_revisions_path | |
98 | assert_routing( |
|
129 | assert_routing( | |
99 | { :method => 'get', |
|
130 | { :method => 'get', | |
100 | :path => "/projects/redmine/repository/diff/#{@path_hash[:path]}" }, |
|
131 | :path => "/projects/redmine/repository/diff/#{@path_hash[:path]}" }, | |
101 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
132 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', | |
102 | :path => @path_hash[:param] } |
|
133 | :path => @path_hash[:param] } | |
103 | ) |
|
134 | ) | |
104 | assert_routing( |
|
135 | assert_routing( | |
105 | { :method => 'get', |
|
136 | { :method => 'get', | |
106 | :path => "/projects/redmine/repository/browse/#{@path_hash[:path]}" }, |
|
137 | :path => "/projects/redmine/repository/browse/#{@path_hash[:path]}" }, | |
107 | { :controller => 'repositories', :action => 'browse', :id => 'redmine', |
|
138 | { :controller => 'repositories', :action => 'browse', :id => 'redmine', | |
108 | :path => @path_hash[:param] } |
|
139 | :path => @path_hash[:param] } | |
109 | ) |
|
140 | ) | |
110 | assert_routing( |
|
141 | assert_routing( | |
111 | { :method => 'get', |
|
142 | { :method => 'get', | |
112 | :path => "/projects/redmine/repository/entry/#{@path_hash[:path]}" }, |
|
143 | :path => "/projects/redmine/repository/entry/#{@path_hash[:path]}" }, | |
113 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
144 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', | |
114 | :path => @path_hash[:param] } |
|
145 | :path => @path_hash[:param] } | |
115 | ) |
|
146 | ) | |
116 | assert_routing( |
|
147 | assert_routing( | |
117 | { :method => 'get', |
|
148 | { :method => 'get', | |
118 | :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, |
|
149 | :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, | |
119 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
150 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', | |
120 | :path => @path_hash[:param], :format => 'raw' } |
|
151 | :path => @path_hash[:param], :format => 'raw' } | |
121 | ) |
|
152 | ) | |
122 | assert_routing( |
|
153 | assert_routing( | |
123 | { :method => 'get', |
|
154 | { :method => 'get', | |
124 | :path => "/projects/redmine/repository/annotate/#{@path_hash[:path]}" }, |
|
155 | :path => "/projects/redmine/repository/annotate/#{@path_hash[:path]}" }, | |
125 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', |
|
156 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', | |
126 | :path => @path_hash[:param] } |
|
157 | :path => @path_hash[:param] } | |
127 | ) |
|
158 | ) | |
128 | assert_routing( |
|
159 | assert_routing( | |
129 | { :method => 'get', |
|
160 | { :method => 'get', | |
130 | :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, |
|
161 | :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, | |
131 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', |
|
162 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', | |
132 | :path => @path_hash[:param] } |
|
163 | :path => @path_hash[:param] } | |
133 | ) |
|
164 | ) | |
134 | end |
|
165 | end | |
135 |
|
166 | |||
136 | private |
|
167 | private | |
137 |
|
168 | |||
138 | def repository_path_hash(arr) |
|
169 | def repository_path_hash(arr) | |
139 | hs = {} |
|
170 | hs = {} | |
140 | hs[:path] = arr.join("/") |
|
171 | hs[:path] = arr.join("/") | |
141 | hs[:param] = arr |
|
172 | hs[:param] = arr | |
142 | hs |
|
173 | hs | |
143 | end |
|
174 | end | |
144 | end |
|
175 | end |
General Comments 0
You need to be logged in to leave comments.
Login now