@@ -1,346 +1,352 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RoutingRepositoriesTest < ActionController::IntegrationTest |
|
21 | 21 | def setup |
|
22 | 22 | @path_hash = repository_path_hash(%w[path to file.c]) |
|
23 | 23 | assert_equal "path/to/file.c", @path_hash[:path] |
|
24 | 24 | assert_equal %w[path to file.c], @path_hash[:param] |
|
25 | 25 | end |
|
26 | 26 | |
|
27 | 27 | def test_repositories_resources |
|
28 | 28 | assert_routing( |
|
29 | 29 | { :method => 'get', |
|
30 | 30 | :path => "/projects/redmine/repositories/new" }, |
|
31 | 31 | { :controller => 'repositories', :action => 'new', :project_id => 'redmine' } |
|
32 | 32 | ) |
|
33 | 33 | assert_routing( |
|
34 | 34 | { :method => 'post', |
|
35 | 35 | :path => "/projects/redmine/repositories" }, |
|
36 | 36 | { :controller => 'repositories', :action => 'create', :project_id => 'redmine' } |
|
37 | 37 | ) |
|
38 | 38 | assert_routing( |
|
39 | 39 | { :method => 'get', |
|
40 | 40 | :path => "/repositories/1/edit" }, |
|
41 | 41 | { :controller => 'repositories', :action => 'edit', :id => '1' } |
|
42 | 42 | ) |
|
43 | 43 | assert_routing( |
|
44 | 44 | { :method => 'put', |
|
45 | 45 | :path => "/repositories/1" }, |
|
46 | 46 | { :controller => 'repositories', :action => 'update', :id => '1' } |
|
47 | 47 | ) |
|
48 | 48 | assert_routing( |
|
49 | 49 | { :method => 'delete', |
|
50 | 50 | :path => "/repositories/1" }, |
|
51 | 51 | { :controller => 'repositories', :action => 'destroy', :id => '1' } |
|
52 | 52 | ) |
|
53 | 53 | ["get", "post"].each do |method| |
|
54 | 54 | assert_routing( |
|
55 | 55 | { :method => method, |
|
56 | 56 | :path => "/repositories/1/committers" }, |
|
57 | 57 | { :controller => 'repositories', :action => 'committers', :id => '1' } |
|
58 | 58 | ) |
|
59 | 59 | end |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | def test_repositories | |
|
62 | def test_repositories_show | |
|
63 | 63 | assert_routing( |
|
64 | 64 | { :method => 'get', |
|
65 | 65 | :path => "/projects/redmine/repository" }, |
|
66 | 66 | { :controller => 'repositories', :action => 'show', :id => 'redmine' } |
|
67 | 67 | ) |
|
68 | end | |
|
69 | ||
|
70 | def test_repositories | |
|
68 | 71 | assert_routing( |
|
69 | 72 | { :method => 'get', |
|
70 | 73 | :path => "/projects/redmine/repository/statistics" }, |
|
71 | 74 | { :controller => 'repositories', :action => 'stats', :id => 'redmine' } |
|
72 | 75 | ) |
|
73 | 76 | assert_routing( |
|
74 | 77 | { :method => 'get', |
|
75 | 78 | :path => "/projects/redmine/repository/graph" }, |
|
76 | 79 | { :controller => 'repositories', :action => 'graph', :id => 'redmine' } |
|
77 | 80 | ) |
|
78 | 81 | end |
|
79 | 82 | |
|
80 | def test_repositories_with_repository_id | |
|
83 | def test_repositories_show_with_repository_id | |
|
81 | 84 | assert_routing( |
|
82 | 85 | { :method => 'get', |
|
83 | 86 | :path => "/projects/redmine/repository/foo" }, |
|
84 | 87 | { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo' } |
|
85 | 88 | ) |
|
89 | end | |
|
90 | ||
|
91 | def test_repositories_with_repository_id | |
|
86 | 92 | assert_routing( |
|
87 | 93 | { :method => 'get', |
|
88 | 94 | :path => "/projects/redmine/repository/foo/statistics" }, |
|
89 | 95 | { :controller => 'repositories', :action => 'stats', :id => 'redmine', :repository_id => 'foo' } |
|
90 | 96 | ) |
|
91 | 97 | assert_routing( |
|
92 | 98 | { :method => 'get', |
|
93 | 99 | :path => "/projects/redmine/repository/foo/graph" }, |
|
94 | 100 | { :controller => 'repositories', :action => 'graph', :id => 'redmine', :repository_id => 'foo' } |
|
95 | 101 | ) |
|
96 | 102 | end |
|
97 | 103 | |
|
98 | 104 | def test_repositories_revisions |
|
99 | 105 | empty_path_param = [] |
|
100 | 106 | assert_routing( |
|
101 | 107 | { :method => 'get', |
|
102 | 108 | :path => "/projects/redmine/repository/revisions" }, |
|
103 | 109 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine' } |
|
104 | 110 | ) |
|
105 | 111 | assert_routing( |
|
106 | 112 | { :method => 'get', |
|
107 | 113 | :path => "/projects/redmine/repository/revisions.atom" }, |
|
108 | 114 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine', |
|
109 | 115 | :format => 'atom' } |
|
110 | 116 | ) |
|
111 | 117 | assert_routing( |
|
112 | 118 | { :method => 'get', |
|
113 | 119 | :path => "/projects/redmine/repository/revisions/2457" }, |
|
114 | 120 | { :controller => 'repositories', :action => 'revision', :id => 'redmine', |
|
115 | 121 | :rev => '2457' } |
|
116 | 122 | ) |
|
117 | 123 | assert_routing( |
|
118 | 124 | { :method => 'get', |
|
119 | 125 | :path => "/projects/redmine/repository/revisions/2457/show" }, |
|
120 | 126 | { :controller => 'repositories', :action => 'show', :id => 'redmine', |
|
121 | 127 | :path => empty_path_param, :rev => '2457' } |
|
122 | 128 | ) |
|
123 | 129 | assert_routing( |
|
124 | 130 | { :method => 'get', |
|
125 | 131 | :path => "/projects/redmine/repository/revisions/2457/show/#{@path_hash[:path]}" }, |
|
126 | 132 | { :controller => 'repositories', :action => 'show', :id => 'redmine', |
|
127 | 133 | :path => @path_hash[:param] , :rev => '2457'} |
|
128 | 134 | ) |
|
129 | 135 | assert_routing( |
|
130 | 136 | { :method => 'get', |
|
131 | 137 | :path => "/projects/redmine/repository/revisions/2457/changes" }, |
|
132 | 138 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', |
|
133 | 139 | :path => empty_path_param, :rev => '2457' } |
|
134 | 140 | ) |
|
135 | 141 | assert_routing( |
|
136 | 142 | { :method => 'get', |
|
137 | 143 | :path => "/projects/redmine/repository/revisions/2457/changes/#{@path_hash[:path]}" }, |
|
138 | 144 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', |
|
139 | 145 | :path => @path_hash[:param] , :rev => '2457'} |
|
140 | 146 | ) |
|
141 | 147 | assert_routing( |
|
142 | 148 | { :method => 'get', |
|
143 | 149 | :path => "/projects/redmine/repository/revisions/2457/diff" }, |
|
144 | 150 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
145 | 151 | :rev => '2457' } |
|
146 | 152 | ) |
|
147 | 153 | assert_routing( |
|
148 | 154 | { :method => 'get', |
|
149 | 155 | :path => "/projects/redmine/repository/revisions/2457/diff.diff" }, |
|
150 | 156 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
151 | 157 | :rev => '2457', :format => 'diff' } |
|
152 | 158 | ) |
|
153 | 159 | assert_routing( |
|
154 | 160 | { :method => 'get', |
|
155 | 161 | :path => "/projects/redmine/repository/revisions/2/diff/#{@path_hash[:path]}" }, |
|
156 | 162 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
157 | 163 | :path => @path_hash[:param], :rev => '2' } |
|
158 | 164 | ) |
|
159 | 165 | assert_routing( |
|
160 | 166 | { :method => 'get', |
|
161 | 167 | :path => "/projects/redmine/repository/revisions/2/entry/#{@path_hash[:path]}" }, |
|
162 | 168 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
163 | 169 | :path => @path_hash[:param], :rev => '2' } |
|
164 | 170 | ) |
|
165 | 171 | assert_routing( |
|
166 | 172 | { :method => 'get', |
|
167 | 173 | :path => "/projects/redmine/repository/revisions/2/raw/#{@path_hash[:path]}" }, |
|
168 | 174 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
169 | 175 | :path => @path_hash[:param], :rev => '2', :format => 'raw' } |
|
170 | 176 | ) |
|
171 | 177 | assert_routing( |
|
172 | 178 | { :method => 'get', |
|
173 | 179 | :path => "/projects/redmine/repository/revisions/2/annotate/#{@path_hash[:path]}" }, |
|
174 | 180 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', |
|
175 | 181 | :path => @path_hash[:param], :rev => '2' } |
|
176 | 182 | ) |
|
177 | 183 | end |
|
178 | 184 | |
|
179 | 185 | def test_repositories_revisions_with_repository_id |
|
180 | 186 | empty_path_param = [] |
|
181 | 187 | assert_routing( |
|
182 | 188 | { :method => 'get', |
|
183 | 189 | :path => "/projects/redmine/repository/foo/revisions" }, |
|
184 | 190 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine', :repository_id => 'foo' } |
|
185 | 191 | ) |
|
186 | 192 | assert_routing( |
|
187 | 193 | { :method => 'get', |
|
188 | 194 | :path => "/projects/redmine/repository/foo/revisions.atom" }, |
|
189 | 195 | { :controller => 'repositories', :action => 'revisions', :id => 'redmine', :repository_id => 'foo', |
|
190 | 196 | :format => 'atom' } |
|
191 | 197 | ) |
|
192 | 198 | assert_routing( |
|
193 | 199 | { :method => 'get', |
|
194 | 200 | :path => "/projects/redmine/repository/foo/revisions/2457" }, |
|
195 | 201 | { :controller => 'repositories', :action => 'revision', :id => 'redmine', :repository_id => 'foo', |
|
196 | 202 | :rev => '2457' } |
|
197 | 203 | ) |
|
198 | 204 | assert_routing( |
|
199 | 205 | { :method => 'get', |
|
200 | 206 | :path => "/projects/redmine/repository/foo/revisions/2457/show" }, |
|
201 | 207 | { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo', |
|
202 | 208 | :path => empty_path_param, :rev => '2457' } |
|
203 | 209 | ) |
|
204 | 210 | assert_routing( |
|
205 | 211 | { :method => 'get', |
|
206 | 212 | :path => "/projects/redmine/repository/foo/revisions/2457/show/#{@path_hash[:path]}" }, |
|
207 | 213 | { :controller => 'repositories', :action => 'show', :id => 'redmine', :repository_id => 'foo', |
|
208 | 214 | :path => @path_hash[:param] , :rev => '2457'} |
|
209 | 215 | ) |
|
210 | 216 | assert_routing( |
|
211 | 217 | { :method => 'get', |
|
212 | 218 | :path => "/projects/redmine/repository/foo/revisions/2457/changes" }, |
|
213 | 219 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', |
|
214 | 220 | :path => empty_path_param, :rev => '2457' } |
|
215 | 221 | ) |
|
216 | 222 | assert_routing( |
|
217 | 223 | { :method => 'get', |
|
218 | 224 | :path => "/projects/redmine/repository/foo/revisions/2457/changes/#{@path_hash[:path]}" }, |
|
219 | 225 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', |
|
220 | 226 | :path => @path_hash[:param] , :rev => '2457'} |
|
221 | 227 | ) |
|
222 | 228 | assert_routing( |
|
223 | 229 | { :method => 'get', |
|
224 | 230 | :path => "/projects/redmine/repository/foo/revisions/2457/diff" }, |
|
225 | 231 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', |
|
226 | 232 | :rev => '2457' } |
|
227 | 233 | ) |
|
228 | 234 | assert_routing( |
|
229 | 235 | { :method => 'get', |
|
230 | 236 | :path => "/projects/redmine/repository/foo/revisions/2457/diff.diff" }, |
|
231 | 237 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', |
|
232 | 238 | :rev => '2457', :format => 'diff' } |
|
233 | 239 | ) |
|
234 | 240 | assert_routing( |
|
235 | 241 | { :method => 'get', |
|
236 | 242 | :path => "/projects/redmine/repository/foo/revisions/2/diff/#{@path_hash[:path]}" }, |
|
237 | 243 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', |
|
238 | 244 | :path => @path_hash[:param], :rev => '2' } |
|
239 | 245 | ) |
|
240 | 246 | assert_routing( |
|
241 | 247 | { :method => 'get', |
|
242 | 248 | :path => "/projects/redmine/repository/foo/revisions/2/entry/#{@path_hash[:path]}" }, |
|
243 | 249 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', |
|
244 | 250 | :path => @path_hash[:param], :rev => '2' } |
|
245 | 251 | ) |
|
246 | 252 | assert_routing( |
|
247 | 253 | { :method => 'get', |
|
248 | 254 | :path => "/projects/redmine/repository/foo/revisions/2/raw/#{@path_hash[:path]}" }, |
|
249 | 255 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', |
|
250 | 256 | :path => @path_hash[:param], :rev => '2', :format => 'raw' } |
|
251 | 257 | ) |
|
252 | 258 | assert_routing( |
|
253 | 259 | { :method => 'get', |
|
254 | 260 | :path => "/projects/redmine/repository/foo/revisions/2/annotate/#{@path_hash[:path]}" }, |
|
255 | 261 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', :repository_id => 'foo', |
|
256 | 262 | :path => @path_hash[:param], :rev => '2' } |
|
257 | 263 | ) |
|
258 | 264 | end |
|
259 | 265 | |
|
260 | 266 | def test_repositories_non_revisions_path |
|
261 | 267 | assert_routing( |
|
262 | 268 | { :method => 'get', |
|
263 | 269 | :path => "/projects/redmine/repository/diff/#{@path_hash[:path]}" }, |
|
264 | 270 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', |
|
265 | 271 | :path => @path_hash[:param] } |
|
266 | 272 | ) |
|
267 | 273 | assert_routing( |
|
268 | 274 | { :method => 'get', |
|
269 | 275 | :path => "/projects/redmine/repository/browse/#{@path_hash[:path]}" }, |
|
270 | 276 | { :controller => 'repositories', :action => 'browse', :id => 'redmine', |
|
271 | 277 | :path => @path_hash[:param] } |
|
272 | 278 | ) |
|
273 | 279 | assert_routing( |
|
274 | 280 | { :method => 'get', |
|
275 | 281 | :path => "/projects/redmine/repository/entry/#{@path_hash[:path]}" }, |
|
276 | 282 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
277 | 283 | :path => @path_hash[:param] } |
|
278 | 284 | ) |
|
279 | 285 | assert_routing( |
|
280 | 286 | { :method => 'get', |
|
281 | 287 | :path => "/projects/redmine/repository/raw/#{@path_hash[:path]}" }, |
|
282 | 288 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', |
|
283 | 289 | :path => @path_hash[:param], :format => 'raw' } |
|
284 | 290 | ) |
|
285 | 291 | assert_routing( |
|
286 | 292 | { :method => 'get', |
|
287 | 293 | :path => "/projects/redmine/repository/annotate/#{@path_hash[:path]}" }, |
|
288 | 294 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', |
|
289 | 295 | :path => @path_hash[:param] } |
|
290 | 296 | ) |
|
291 | 297 | assert_routing( |
|
292 | 298 | { :method => 'get', |
|
293 | 299 | :path => "/projects/redmine/repository/changes/#{@path_hash[:path]}" }, |
|
294 | 300 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', |
|
295 | 301 | :path => @path_hash[:param] } |
|
296 | 302 | ) |
|
297 | 303 | end |
|
298 | 304 | |
|
299 | 305 | def test_repositories_non_revisions_path_with_repository_id |
|
300 | 306 | assert_routing( |
|
301 | 307 | { :method => 'get', |
|
302 | 308 | :path => "/projects/redmine/repository/foo/diff/#{@path_hash[:path]}" }, |
|
303 | 309 | { :controller => 'repositories', :action => 'diff', :id => 'redmine', :repository_id => 'foo', |
|
304 | 310 | :path => @path_hash[:param] } |
|
305 | 311 | ) |
|
306 | 312 | assert_routing( |
|
307 | 313 | { :method => 'get', |
|
308 | 314 | :path => "/projects/redmine/repository/foo/browse/#{@path_hash[:path]}" }, |
|
309 | 315 | { :controller => 'repositories', :action => 'browse', :id => 'redmine', :repository_id => 'foo', |
|
310 | 316 | :path => @path_hash[:param] } |
|
311 | 317 | ) |
|
312 | 318 | assert_routing( |
|
313 | 319 | { :method => 'get', |
|
314 | 320 | :path => "/projects/redmine/repository/foo/entry/#{@path_hash[:path]}" }, |
|
315 | 321 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', |
|
316 | 322 | :path => @path_hash[:param] } |
|
317 | 323 | ) |
|
318 | 324 | assert_routing( |
|
319 | 325 | { :method => 'get', |
|
320 | 326 | :path => "/projects/redmine/repository/foo/raw/#{@path_hash[:path]}" }, |
|
321 | 327 | { :controller => 'repositories', :action => 'entry', :id => 'redmine', :repository_id => 'foo', |
|
322 | 328 | :path => @path_hash[:param], :format => 'raw' } |
|
323 | 329 | ) |
|
324 | 330 | assert_routing( |
|
325 | 331 | { :method => 'get', |
|
326 | 332 | :path => "/projects/redmine/repository/foo/annotate/#{@path_hash[:path]}" }, |
|
327 | 333 | { :controller => 'repositories', :action => 'annotate', :id => 'redmine', :repository_id => 'foo', |
|
328 | 334 | :path => @path_hash[:param] } |
|
329 | 335 | ) |
|
330 | 336 | assert_routing( |
|
331 | 337 | { :method => 'get', |
|
332 | 338 | :path => "/projects/redmine/repository/foo/changes/#{@path_hash[:path]}" }, |
|
333 | 339 | { :controller => 'repositories', :action => 'changes', :id => 'redmine', :repository_id => 'foo', |
|
334 | 340 | :path => @path_hash[:param] } |
|
335 | 341 | ) |
|
336 | 342 | end |
|
337 | 343 | |
|
338 | 344 | private |
|
339 | 345 | |
|
340 | 346 | def repository_path_hash(arr) |
|
341 | 347 | hs = {} |
|
342 | 348 | hs[:path] = arr.join("/") |
|
343 | 349 | hs[:param] = arr |
|
344 | 350 | hs |
|
345 | 351 | end |
|
346 | 352 | end |
General Comments 0
You need to be logged in to leave comments.
Login now