##// END OF EJS Templates
Rails3: test: scm: mercurial: use "repository_path_hash" for path param...
Toshi MARUYAMA -
r8816:9774782cab72
parent child
Show More
@@ -1,513 +1,526
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 RepositoriesMercurialControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28 PRJ_ID = 3
29 29 NUM_REV = 32
30 30
31 31 ruby19_non_utf8_pass =
32 32 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
33 33
34 34 def setup
35 35 User.current = nil
36 36 @project = Project.find(PRJ_ID)
37 37 @repository = Repository::Mercurial.create(
38 38 :project => @project,
39 39 :url => REPOSITORY_PATH,
40 40 :path_encoding => 'ISO-8859-1'
41 41 )
42 42 assert @repository
43 43 @diff_c_support = true
44 44 @char_1 = CHAR_1_HEX.dup
45 45 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 46 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 47 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 48 if @char_1.respond_to?(:force_encoding)
49 49 @char_1.force_encoding('UTF-8')
50 50 @tag_char_1.force_encoding('UTF-8')
51 51 @branch_char_0.force_encoding('UTF-8')
52 52 @branch_char_1.force_encoding('UTF-8')
53 53 end
54 54 end
55 55
56 56 if ruby19_non_utf8_pass
57 57 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 58 "and Encoding.default_external is not UTF-8. " +
59 59 "Current value is '#{Encoding.default_external.to_s}'"
60 60 def test_fake; assert true end
61 61 elsif File.directory?(REPOSITORY_PATH)
62 62
63 63 def test_get_new
64 64 @request.session[:user_id] = 1
65 65 @project.repository.destroy
66 66 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
67 67 assert_response :success
68 68 assert_template 'new'
69 69 assert_kind_of Repository::Mercurial, assigns(:repository)
70 70 assert assigns(:repository).new_record?
71 71 end
72 72
73 73 def test_show_root
74 74 assert_equal 0, @repository.changesets.count
75 75 @repository.fetch_changesets
76 76 @project.reload
77 77 assert_equal NUM_REV, @repository.changesets.count
78 78 get :show, :id => PRJ_ID
79 79 assert_response :success
80 80 assert_template 'show'
81 81 assert_not_nil assigns(:entries)
82 82 assert_equal 4, assigns(:entries).size
83 83 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
84 84 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
85 85 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
86 86 assert_not_nil assigns(:changesets)
87 87 assert assigns(:changesets).size > 0
88 88 end
89 89
90 90 def test_show_directory
91 91 assert_equal 0, @repository.changesets.count
92 92 @repository.fetch_changesets
93 93 @project.reload
94 94 assert_equal NUM_REV, @repository.changesets.count
95 get :show, :id => PRJ_ID, :path => ['images']
95 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
96 96 assert_response :success
97 97 assert_template 'show'
98 98 assert_not_nil assigns(:entries)
99 99 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
100 100 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
101 101 assert_not_nil entry
102 102 assert_equal 'file', entry.kind
103 103 assert_equal 'images/edit.png', entry.path
104 104 assert_not_nil assigns(:changesets)
105 105 assert assigns(:changesets).size > 0
106 106 end
107 107
108 108 def test_show_at_given_revision
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 [0, '0', '0885933ad4f6'].each do |r1|
114 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
114 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
115 :rev => r1
115 116 assert_response :success
116 117 assert_template 'show'
117 118 assert_not_nil assigns(:entries)
118 119 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
119 120 assert_not_nil assigns(:changesets)
120 121 assert assigns(:changesets).size > 0
121 122 end
122 123 end
123 124
124 125 def test_show_directory_sql_escape_percent
125 126 assert_equal 0, @repository.changesets.count
126 127 @repository.fetch_changesets
127 128 @project.reload
128 129 assert_equal NUM_REV, @repository.changesets.count
129 130 [13, '13', '3a330eb32958'].each do |r1|
130 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
131 get :show, :id => PRJ_ID,
132 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
131 133 :rev => r1
132 134 assert_response :success
133 135 assert_template 'show'
134 136
135 137 assert_not_nil assigns(:entries)
136 138 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
137 139 assigns(:entries).collect(&:name)
138 140 changesets = assigns(:changesets)
139 141 assert_not_nil changesets
140 142 assert assigns(:changesets).size > 0
141 143 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
142 144 end
143 145 end
144 146
145 147 def test_show_directory_latin_1_path
146 148 assert_equal 0, @repository.changesets.count
147 149 @repository.fetch_changesets
148 150 @project.reload
149 151 assert_equal NUM_REV, @repository.changesets.count
150 152 [21, '21', 'adf805632193'].each do |r1|
151 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
153 get :show, :id => PRJ_ID,
154 :path => repository_path_hash(['latin-1-dir'])[:param],
155 :rev => r1
152 156 assert_response :success
153 157 assert_template 'show'
154 158
155 159 assert_not_nil assigns(:entries)
156 160 assert_equal ["make-latin-1-file.rb",
157 161 "test-#{@char_1}-1.txt",
158 162 "test-#{@char_1}-2.txt",
159 163 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
160 164 changesets = assigns(:changesets)
161 165 assert_not_nil changesets
162 166 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
163 167 end
164 168 end
165 169
166 170 def show_should_show_branch_selection_form
167 171 @repository.fetch_changesets
168 172 @project.reload
169 173 get :show, :id => PRJ_ID
170 174 assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'}
171 175 assert_tag 'select', :attributes => {:name => 'branch'},
172 176 :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}},
173 177 :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}}
174 178 end
175 179
176 180 def test_show_branch
177 181 assert_equal 0, @repository.changesets.count
178 182 @repository.fetch_changesets
179 183 @project.reload
180 184 assert_equal NUM_REV, @repository.changesets.count
181 185 [
182 186 'default',
183 187 @branch_char_1,
184 188 'branch (1)[2]&,%.-3_4',
185 189 @branch_char_0,
186 190 'test_branch.latin-1',
187 191 'test-branch-00',
188 192 ].each do |bra|
189 193 get :show, :id => PRJ_ID, :rev => bra
190 194 assert_response :success
191 195 assert_template 'show'
192 196 assert_not_nil assigns(:entries)
193 197 assert assigns(:entries).size > 0
194 198 assert_not_nil assigns(:changesets)
195 199 assert assigns(:changesets).size > 0
196 200 end
197 201 end
198 202
199 203 def test_show_tag
200 204 assert_equal 0, @repository.changesets.count
201 205 @repository.fetch_changesets
202 206 @project.reload
203 207 assert_equal NUM_REV, @repository.changesets.count
204 208 [
205 209 @tag_char_1,
206 210 'tag_test.00',
207 211 'tag-init-revision'
208 212 ].each do |tag|
209 213 get :show, :id => PRJ_ID, :rev => tag
210 214 assert_response :success
211 215 assert_template 'show'
212 216 assert_not_nil assigns(:entries)
213 217 assert assigns(:entries).size > 0
214 218 assert_not_nil assigns(:changesets)
215 219 assert assigns(:changesets).size > 0
216 220 end
217 221 end
218 222
219 223 def test_changes
220 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
224 get :changes, :id => PRJ_ID,
225 :path => repository_path_hash(['images', 'edit.png'])[:param]
221 226 assert_response :success
222 227 assert_template 'changes'
223 228 assert_tag :tag => 'h2', :content => 'edit.png'
224 229 end
225 230
226 231 def test_entry_show
227 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
232 get :entry, :id => PRJ_ID,
233 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
228 234 assert_response :success
229 235 assert_template 'entry'
230 236 # Line 10
231 237 assert_tag :tag => 'th',
232 238 :content => '10',
233 239 :attributes => { :class => 'line-num' },
234 240 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
235 241 end
236 242
237 243 def test_entry_show_latin_1_path
238 244 [21, '21', 'adf805632193'].each do |r1|
239 245 get :entry, :id => PRJ_ID,
240 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
246 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
247 :rev => r1
241 248 assert_response :success
242 249 assert_template 'entry'
243 250 assert_tag :tag => 'th',
244 251 :content => '1',
245 252 :attributes => { :class => 'line-num' },
246 253 :sibling => { :tag => 'td',
247 254 :content => /Mercurial is a distributed version control system/ }
248 255 end
249 256 end
250 257
251 258 def test_entry_show_latin_1_contents
252 259 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
253 260 [27, '27', '7bbf4c738e71'].each do |r1|
254 261 get :entry, :id => PRJ_ID,
255 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
262 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
263 :rev => r1
256 264 assert_response :success
257 265 assert_template 'entry'
258 266 assert_tag :tag => 'th',
259 267 :content => '1',
260 268 :attributes => { :class => 'line-num' },
261 269 :sibling => { :tag => 'td',
262 270 :content => /test-#{@char_1}.txt/ }
263 271 end
264 272 end
265 273 end
266 274
267 275 def test_entry_download
268 276 get :entry, :id => PRJ_ID,
269 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
277 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
278 :format => 'raw'
270 279 assert_response :success
271 280 # File content
272 281 assert @response.body.include?('WITHOUT ANY WARRANTY')
273 282 end
274 283
275 284 def test_entry_binary_force_download
276 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
285 get :entry, :id => PRJ_ID, :rev => 1,
286 :path => repository_path_hash(['images', 'edit.png'])[:param]
277 287 assert_response :success
278 288 assert_equal 'image/png', @response.content_type
279 289 end
280 290
281 291 def test_directory_entry
282 get :entry, :id => PRJ_ID, :path => ['sources']
292 get :entry, :id => PRJ_ID,
293 :path => repository_path_hash(['sources'])[:param]
283 294 assert_response :success
284 295 assert_template 'show'
285 296 assert_not_nil assigns(:entry)
286 297 assert_equal 'sources', assigns(:entry).name
287 298 end
288 299
289 300 def test_diff
290 301 assert_equal 0, @repository.changesets.count
291 302 @repository.fetch_changesets
292 303 @project.reload
293 304 assert_equal NUM_REV, @repository.changesets.count
294 305 [4, '4', 'def6d2f1254a'].each do |r1|
295 306 # Full diff of changeset 4
296 307 ['inline', 'sbs'].each do |dt|
297 308 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
298 309 assert_response :success
299 310 assert_template 'diff'
300 311 if @diff_c_support
301 312 # Line 22 removed
302 313 assert_tag :tag => 'th',
303 314 :content => '22',
304 315 :sibling => { :tag => 'td',
305 316 :attributes => { :class => /diff_out/ },
306 317 :content => /def remove/ }
307 318 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
308 319 end
309 320 end
310 321 end
311 322 end
312 323
313 324 def test_diff_two_revs
314 325 assert_equal 0, @repository.changesets.count
315 326 @repository.fetch_changesets
316 327 @project.reload
317 328 assert_equal NUM_REV, @repository.changesets.count
318 329 [2, '400bb8672109', '400', 400].each do |r1|
319 330 [4, 'def6d2f1254a'].each do |r2|
320 331 ['inline', 'sbs'].each do |dt|
321 332 get :diff,
322 333 :id => PRJ_ID,
323 334 :rev => r1,
324 335 :rev_to => r2,
325 336 :type => dt
326 337 assert_response :success
327 338 assert_template 'diff'
328 339 diff = assigns(:diff)
329 340 assert_not_nil diff
330 341 assert_tag :tag => 'h2',
331 342 :content => /4:def6d2f1254a 2:400bb8672109/
332 343 end
333 344 end
334 345 end
335 346 end
336 347
337 348 def test_diff_latin_1_path
338 349 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
339 350 [21, 'adf805632193'].each do |r1|
340 351 ['inline', 'sbs'].each do |dt|
341 352 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
342 353 assert_response :success
343 354 assert_template 'diff'
344 355 assert_tag :tag => 'thead',
345 356 :descendant => {
346 357 :tag => 'th',
347 358 :attributes => { :class => 'filename' } ,
348 359 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
349 360 },
350 361 :sibling => {
351 362 :tag => 'tbody',
352 363 :descendant => {
353 364 :tag => 'td',
354 365 :attributes => { :class => /diff_in/ },
355 366 :content => /It is written in Python/
356 367 }
357 368 }
358 369 end
359 370 end
360 371 end
361 372 end
362 373
363 374 def test_annotate
364 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
375 get :annotate, :id => PRJ_ID,
376 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
365 377 assert_response :success
366 378 assert_template 'annotate'
367 379 # Line 23, revision 4:def6d2f1254a
368 380 assert_tag :tag => 'th',
369 381 :content => '23',
370 382 :attributes => { :class => 'line-num' },
371 383 :sibling =>
372 384 {
373 385 :tag => 'td',
374 386 :attributes => { :class => 'revision' },
375 387 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
376 388 }
377 389 assert_tag :tag => 'th',
378 390 :content => '23',
379 391 :attributes => { :class => 'line-num' },
380 392 :sibling =>
381 393 {
382 394 :tag => 'td' ,
383 395 :content => 'jsmith' ,
384 396 :attributes => { :class => 'author' },
385 397 }
386 398 assert_tag :tag => 'th',
387 399 :content => '23',
388 400 :attributes => { :class => 'line-num' },
389 401 :sibling => { :tag => 'td', :content => /watcher =/ }
390 402 end
391 403
392 404 def test_annotate_not_in_tip
393 405 assert_equal 0, @repository.changesets.count
394 406 @repository.fetch_changesets
395 407 @project.reload
396 408 assert_equal NUM_REV, @repository.changesets.count
397
398 409 get :annotate, :id => PRJ_ID,
399 :path => ['sources', 'welcome_controller.rb']
410 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
400 411 assert_response 404
401 412 assert_error_tag :content => /was not found/
402 413 end
403 414
404 415 def test_annotate_at_given_revision
405 416 assert_equal 0, @repository.changesets.count
406 417 @repository.fetch_changesets
407 418 @project.reload
408 419 assert_equal NUM_REV, @repository.changesets.count
409 420 [2, '400bb8672109', '400', 400].each do |r1|
410 421 get :annotate, :id => PRJ_ID, :rev => r1,
411 :path => ['sources', 'watchers_controller.rb']
422 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
412 423 assert_response :success
413 424 assert_template 'annotate'
414 425 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
415 426 end
416 427 end
417 428
418 429 def test_annotate_latin_1_path
419 430 [21, '21', 'adf805632193'].each do |r1|
420 431 get :annotate, :id => PRJ_ID,
421 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
432 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
433 :rev => r1
422 434 assert_response :success
423 435 assert_template 'annotate'
424 436 assert_tag :tag => 'th',
425 437 :content => '1',
426 438 :attributes => { :class => 'line-num' },
427 439 :sibling =>
428 440 {
429 441 :tag => 'td',
430 442 :attributes => { :class => 'revision' },
431 443 :child => { :tag => 'a', :content => '20:709858aafd1b' }
432 444 }
433 445 assert_tag :tag => 'th',
434 446 :content => '1',
435 447 :attributes => { :class => 'line-num' },
436 448 :sibling =>
437 449 {
438 450 :tag => 'td' ,
439 451 :content => 'jsmith' ,
440 452 :attributes => { :class => 'author' },
441 453 }
442 454 assert_tag :tag => 'th',
443 455 :content => '1',
444 456 :attributes => { :class => 'line-num' },
445 457 :sibling => { :tag => 'td',
446 458 :content => /Mercurial is a distributed version control system/ }
447 459
448 460 end
449 461 end
450 462
451 463 def test_annotate_latin_1_contents
452 464 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
453 465 [27, '7bbf4c738e71'].each do |r1|
454 466 get :annotate, :id => PRJ_ID,
455 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
467 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
468 :rev => r1
456 469 assert_tag :tag => 'th',
457 470 :content => '1',
458 471 :attributes => { :class => 'line-num' },
459 472 :sibling => { :tag => 'td',
460 473 :content => /test-#{@char_1}.txt/ }
461 474 end
462 475 end
463 476 end
464 477
465 478 def test_empty_revision
466 479 assert_equal 0, @repository.changesets.count
467 480 @repository.fetch_changesets
468 481 @project.reload
469 482 assert_equal NUM_REV, @repository.changesets.count
470 483 ['', ' ', nil].each do |r|
471 484 get :revision, :id => PRJ_ID, :rev => r
472 485 assert_response 404
473 486 assert_error_tag :content => /was not found/
474 487 end
475 488 end
476 489
477 490 def test_destroy_valid_repository
478 491 @request.session[:user_id] = 1 # admin
479 492 assert_equal 0, @repository.changesets.count
480 493 @repository.fetch_changesets
481 494 assert_equal NUM_REV, @repository.changesets.count
482 495
483 496 assert_difference 'Repository.count', -1 do
484 497 delete :destroy, :id => @repository.id
485 498 end
486 499 assert_response 302
487 500 @project.reload
488 501 assert_nil @project.repository
489 502 end
490 503
491 504 def test_destroy_invalid_repository
492 505 @request.session[:user_id] = 1 # admin
493 506 @project.repository.destroy
494 507 @repository = Repository::Mercurial.create!(
495 508 :project => Project.find(PRJ_ID),
496 509 :url => "/invalid",
497 510 :path_encoding => 'ISO-8859-1'
498 511 )
499 512 @repository.fetch_changesets
500 513 assert_equal 0, @repository.changesets.count
501 514
502 515 assert_difference 'Repository.count', -1 do
503 516 delete :destroy, :id => @repository.id
504 517 end
505 518 assert_response 302
506 519 @project.reload
507 520 assert_nil @project.repository
508 521 end
509 522 else
510 523 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
511 524 def test_fake; assert true end
512 525 end
513 526 end
General Comments 0
You need to be logged in to leave comments. Login now