##// END OF EJS Templates
Merged r10245 from trunk to 1.4-stable (#11752)...
Toshi MARUYAMA -
r10065:03d6c4668ed2
parent child
Show More
@@ -1,548 +1,572
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 RepositoriesGitControllerTest < 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/git_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 PRJ_ID = 3
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 NUM_REV = 28
31 31
32 32 ## Git, Mercurial and CVS path encodings are binary.
33 33 ## Subversion supports URL encoding for path.
34 34 ## Redmine Mercurial adapter and extension use URL encoding.
35 35 ## Git accepts only binary path in command line parameter.
36 36 ## So, there is no way to use binary command line parameter in JRuby.
37 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39 39
40 40 def setup
41 41 @ruby19_non_utf8_pass =
42 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43 43
44 44 User.current = nil
45 45 @project = Project.find(PRJ_ID)
46 46 @repository = Repository::Git.create(
47 47 :project => @project,
48 48 :url => REPOSITORY_PATH,
49 49 :path_encoding => 'ISO-8859-1'
50 50 )
51 51 assert @repository
52 52 @char_1 = CHAR_1_HEX.dup
53 53 if @char_1.respond_to?(:force_encoding)
54 54 @char_1.force_encoding('UTF-8')
55 55 end
56 56
57 57 Setting.default_language = 'en'
58 58 end
59 59
60 60 def test_create_and_update
61 61 @request.session[:user_id] = 1
62 62 assert_difference 'Repository.count' do
63 63 post :create, :project_id => 'subproject1',
64 64 :repository_scm => 'Git',
65 65 :repository => {
66 66 :url => '/test',
67 67 :is_default => '0',
68 68 :identifier => 'test-create',
69 69 :extra_report_last_commit => '1',
70 70 }
71 71 end
72 72 assert_response 302
73 73 repository = Repository.first(:order => 'id DESC')
74 74 assert_kind_of Repository::Git, repository
75 75 assert_equal '/test', repository.url
76 76 assert_equal true, repository.extra_report_last_commit
77 77
78 78 put :update, :id => repository.id,
79 79 :repository => {
80 80 :extra_report_last_commit => '0',
81 81 :identifier => 'test-update',
82 82 }
83 83 assert_response 302
84 84 repo2 = Repository.find(repository.id)
85 85 assert_equal 'test-update', repo2.identifier
86 86 assert_equal false, repo2.extra_report_last_commit
87 87 end
88 88
89 89 if File.directory?(REPOSITORY_PATH)
90 90 ## Ruby uses ANSI api to fork a process on Windows.
91 91 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
92 92 ## and these are incompatible with ASCII.
93 93 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
94 94 ## http://code.google.com/p/msysgit/issues/detail?id=80
95 95 ## So, Latin-1 path tests fail on Japanese Windows
96 96 WINDOWS_PASS = (Redmine::Platform.mswin? &&
97 97 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
98 98 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
99 99
100 100 def test_get_new
101 101 @request.session[:user_id] = 1
102 102 @project.repository.destroy
103 103 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
104 104 assert_response :success
105 105 assert_template 'new'
106 106 assert_kind_of Repository::Git, assigns(:repository)
107 107 assert assigns(:repository).new_record?
108 108 end
109 109
110 110 def test_browse_root
111 111 assert_equal 0, @repository.changesets.count
112 112 @repository.fetch_changesets
113 113 @project.reload
114 114 assert_equal NUM_REV, @repository.changesets.count
115 115
116 116 get :show, :id => PRJ_ID
117 117 assert_response :success
118 118 assert_template 'show'
119 119 assert_not_nil assigns(:entries)
120 120 assert_equal 9, assigns(:entries).size
121 121 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
122 122 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
123 123 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
124 124 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
125 125 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
126 126 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
127 127 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
128 128 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
129 129 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
130 130 assert_not_nil assigns(:changesets)
131 131 assert assigns(:changesets).size > 0
132 132 end
133 133
134 134 def test_browse_branch
135 135 assert_equal 0, @repository.changesets.count
136 136 @repository.fetch_changesets
137 137 @project.reload
138 138 assert_equal NUM_REV, @repository.changesets.count
139 139 get :show, :id => PRJ_ID, :rev => 'test_branch'
140 140 assert_response :success
141 141 assert_template 'show'
142 142 assert_not_nil assigns(:entries)
143 143 assert_equal 4, assigns(:entries).size
144 144 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
145 145 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
146 146 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
147 147 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
148 148 assert_not_nil assigns(:changesets)
149 149 assert assigns(:changesets).size > 0
150 150 end
151 151
152 152 def test_browse_tag
153 153 assert_equal 0, @repository.changesets.count
154 154 @repository.fetch_changesets
155 155 @project.reload
156 156 assert_equal NUM_REV, @repository.changesets.count
157 157 [
158 158 "tag00.lightweight",
159 159 "tag01.annotated",
160 160 ].each do |t1|
161 161 get :show, :id => PRJ_ID, :rev => t1
162 162 assert_response :success
163 163 assert_template 'show'
164 164 assert_not_nil assigns(:entries)
165 165 assert assigns(:entries).size > 0
166 166 assert_not_nil assigns(:changesets)
167 167 assert assigns(:changesets).size > 0
168 168 end
169 169 end
170 170
171 171 def test_browse_directory
172 172 assert_equal 0, @repository.changesets.count
173 173 @repository.fetch_changesets
174 174 @project.reload
175 175 assert_equal NUM_REV, @repository.changesets.count
176 176 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
177 177 assert_response :success
178 178 assert_template 'show'
179 179 assert_not_nil assigns(:entries)
180 180 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
181 181 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
182 182 assert_not_nil entry
183 183 assert_equal 'file', entry.kind
184 184 assert_equal 'images/edit.png', entry.path
185 185 assert_not_nil assigns(:changesets)
186 186 assert assigns(:changesets).size > 0
187 187 end
188 188
189 189 def test_browse_at_given_revision
190 190 assert_equal 0, @repository.changesets.count
191 191 @repository.fetch_changesets
192 192 @project.reload
193 193 assert_equal NUM_REV, @repository.changesets.count
194 194 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
195 195 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
196 196 assert_response :success
197 197 assert_template 'show'
198 198 assert_not_nil assigns(:entries)
199 199 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
200 200 assert_not_nil assigns(:changesets)
201 201 assert assigns(:changesets).size > 0
202 202 end
203 203
204 204 def test_changes
205 205 get :changes, :id => PRJ_ID,
206 206 :path => repository_path_hash(['images', 'edit.png'])[:param]
207 207 assert_response :success
208 208 assert_template 'changes'
209 209 assert_tag :tag => 'h2', :content => 'edit.png'
210 210 end
211 211
212 212 def test_entry_show
213 213 get :entry, :id => PRJ_ID,
214 214 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
215 215 assert_response :success
216 216 assert_template 'entry'
217 217 # Line 19
218 218 assert_tag :tag => 'th',
219 219 :content => '11',
220 220 :attributes => { :class => 'line-num' },
221 221 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
222 222 end
223 223
224 224 def test_entry_show_latin_1
225 225 if @ruby19_non_utf8_pass
226 226 puts_ruby19_non_utf8_pass()
227 227 elsif WINDOWS_PASS
228 228 puts WINDOWS_SKIP_STR
229 229 elsif JRUBY_SKIP
230 230 puts JRUBY_SKIP_STR
231 231 else
232 232 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
233 233 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
234 234 get :entry, :id => PRJ_ID,
235 235 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
236 236 :rev => r1
237 237 assert_response :success
238 238 assert_template 'entry'
239 239 assert_tag :tag => 'th',
240 240 :content => '1',
241 241 :attributes => { :class => 'line-num' },
242 242 :sibling => { :tag => 'td',
243 243 :content => /test-#{@char_1}.txt/ }
244 244 end
245 245 end
246 246 end
247 247 end
248 248
249 249 def test_entry_download
250 250 get :entry, :id => PRJ_ID,
251 251 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
252 252 :format => 'raw'
253 253 assert_response :success
254 254 # File content
255 255 assert @response.body.include?('WITHOUT ANY WARRANTY')
256 256 end
257 257
258 258 def test_directory_entry
259 259 get :entry, :id => PRJ_ID,
260 260 :path => repository_path_hash(['sources'])[:param]
261 261 assert_response :success
262 262 assert_template 'show'
263 263 assert_not_nil assigns(:entry)
264 264 assert_equal 'sources', assigns(:entry).name
265 265 end
266 266
267 267 def test_diff
268 268 assert_equal 0, @repository.changesets.count
269 269 @repository.fetch_changesets
270 270 @project.reload
271 271 assert_equal NUM_REV, @repository.changesets.count
272 272 # Full diff of changeset 2f9c0091
273 273 ['inline', 'sbs'].each do |dt|
274 274 get :diff,
275 275 :id => PRJ_ID,
276 276 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 277 :type => dt
278 278 assert_response :success
279 279 assert_template 'diff'
280 280 # Line 22 removed
281 281 assert_tag :tag => 'th',
282 282 :content => /22/,
283 283 :sibling => { :tag => 'td',
284 284 :attributes => { :class => /diff_out/ },
285 285 :content => /def remove/ }
286 286 assert_tag :tag => 'h2', :content => /2f9c0091/
287 287 end
288 288 end
289 289
290 def test_diff_with_rev_and_path
291 assert_equal 0, @repository.changesets.count
292 @repository.fetch_changesets
293 @project.reload
294 assert_equal NUM_REV, @repository.changesets.count
295 # Full diff of changeset 2f9c0091
296 ['inline', 'sbs'].each do |dt|
297 get :diff,
298 :id => PRJ_ID,
299 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
300 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
301 :type => dt
302 assert_response :success
303 assert_template 'diff'
304 # Line 22 removed
305 assert_tag :tag => 'th',
306 :content => '22',
307 :sibling => { :tag => 'td',
308 :attributes => { :class => /diff_out/ },
309 :content => /def remove/ }
310 assert_tag :tag => 'h2', :content => /2f9c0091/
311 end
312 end
313
290 314 def test_diff_truncated
291 315 assert_equal 0, @repository.changesets.count
292 316 @repository.fetch_changesets
293 317 @project.reload
294 318 assert_equal NUM_REV, @repository.changesets.count
295 319 Setting.diff_max_lines_displayed = 5
296 320
297 321 # Truncated diff of changeset 2f9c0091
298 322 with_cache do
299 323 get :diff, :id => PRJ_ID, :type => 'inline',
300 324 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
301 325 assert_response :success
302 326 assert @response.body.include?("... This diff was truncated")
303 327
304 328 Setting.default_language = 'fr'
305 329 get :diff, :id => PRJ_ID, :type => 'inline',
306 330 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
307 331 assert_response :success
308 332 assert ! @response.body.include?("... This diff was truncated")
309 333 assert @response.body.include?("... Ce diff")
310 334 end
311 335 end
312 336
313 337 def test_diff_two_revs
314 338 assert_equal 0, @repository.changesets.count
315 339 @repository.fetch_changesets
316 340 @project.reload
317 341 assert_equal NUM_REV, @repository.changesets.count
318 342 ['inline', 'sbs'].each do |dt|
319 343 get :diff,
320 344 :id => PRJ_ID,
321 345 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
322 346 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
323 347 :type => dt
324 348 assert_response :success
325 349 assert_template 'diff'
326 350 diff = assigns(:diff)
327 351 assert_not_nil diff
328 352 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
329 353 end
330 354 end
331 355
332 356 def test_diff_latin_1
333 357 if @ruby19_non_utf8_pass
334 358 puts_ruby19_non_utf8_pass()
335 359 else
336 360 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
337 361 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
338 362 ['inline', 'sbs'].each do |dt|
339 363 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
340 364 assert_response :success
341 365 assert_template 'diff'
342 366 assert_tag :tag => 'thead',
343 367 :descendant => {
344 368 :tag => 'th',
345 369 :attributes => { :class => 'filename' } ,
346 370 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
347 371 },
348 372 :sibling => {
349 373 :tag => 'tbody',
350 374 :descendant => {
351 375 :tag => 'td',
352 376 :attributes => { :class => /diff_in/ },
353 377 :content => /test-#{@char_1}.txt/
354 378 }
355 379 }
356 380 end
357 381 end
358 382 end
359 383 end
360 384 end
361 385
362 386 def test_save_diff_type
363 387 @request.session[:user_id] = 1 # admin
364 388 user = User.find(1)
365 389 get :diff,
366 390 :id => PRJ_ID,
367 391 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
368 392 assert_response :success
369 393 assert_template 'diff'
370 394 user.reload
371 395 assert_equal "inline", user.pref[:diff_type]
372 396 get :diff,
373 397 :id => PRJ_ID,
374 398 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
375 399 :type => 'sbs'
376 400 assert_response :success
377 401 assert_template 'diff'
378 402 user.reload
379 403 assert_equal "sbs", user.pref[:diff_type]
380 404 end
381 405
382 406 def test_annotate
383 407 get :annotate, :id => PRJ_ID,
384 408 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
385 409 assert_response :success
386 410 assert_template 'annotate'
387 411 # Line 24, changeset 2f9c0091
388 412 assert_tag :tag => 'th', :content => '24',
389 413 :sibling => {
390 414 :tag => 'td',
391 415 :child => {
392 416 :tag => 'a',
393 417 :content => /2f9c0091/
394 418 }
395 419 }
396 420 assert_tag :tag => 'th', :content => '24',
397 421 :sibling => { :tag => 'td', :content => /jsmith/ }
398 422 assert_tag :tag => 'th', :content => '24',
399 423 :sibling => {
400 424 :tag => 'td',
401 425 :child => {
402 426 :tag => 'a',
403 427 :content => /2f9c0091/
404 428 }
405 429 }
406 430 assert_tag :tag => 'th', :content => '24',
407 431 :sibling => { :tag => 'td', :content => /watcher =/ }
408 432 end
409 433
410 434 def test_annotate_at_given_revision
411 435 assert_equal 0, @repository.changesets.count
412 436 @repository.fetch_changesets
413 437 @project.reload
414 438 assert_equal NUM_REV, @repository.changesets.count
415 439 get :annotate, :id => PRJ_ID, :rev => 'deff7',
416 440 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
417 441 assert_response :success
418 442 assert_template 'annotate'
419 443 assert_tag :tag => 'h2', :content => /@ deff712f/
420 444 end
421 445
422 446 def test_annotate_binary_file
423 447 get :annotate, :id => PRJ_ID,
424 448 :path => repository_path_hash(['images', 'edit.png'])[:param]
425 449 assert_response 500
426 450 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
427 451 :content => /cannot be annotated/
428 452 end
429 453
430 454 def test_annotate_error_when_too_big
431 455 with_settings :file_max_size_displayed => 1 do
432 456 get :annotate, :id => PRJ_ID,
433 457 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
434 458 :rev => 'deff712f'
435 459 assert_response 500
436 460 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
437 461 :content => /exceeds the maximum text file size/
438 462
439 463 get :annotate, :id => PRJ_ID,
440 464 :path => repository_path_hash(['README'])[:param],
441 465 :rev => '7234cb2'
442 466 assert_response :success
443 467 assert_template 'annotate'
444 468 end
445 469 end
446 470
447 471 def test_annotate_latin_1
448 472 if @ruby19_non_utf8_pass
449 473 puts_ruby19_non_utf8_pass()
450 474 elsif WINDOWS_PASS
451 475 puts WINDOWS_SKIP_STR
452 476 elsif JRUBY_SKIP
453 477 puts JRUBY_SKIP_STR
454 478 else
455 479 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
456 480 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
457 481 get :annotate, :id => PRJ_ID,
458 482 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
459 483 :rev => r1
460 484 assert_tag :tag => 'th',
461 485 :content => '1',
462 486 :attributes => { :class => 'line-num' },
463 487 :sibling => { :tag => 'td',
464 488 :content => /test-#{@char_1}.txt/ }
465 489 end
466 490 end
467 491 end
468 492 end
469 493
470 494 def test_revision
471 495 assert_equal 0, @repository.changesets.count
472 496 @repository.fetch_changesets
473 497 @project.reload
474 498 assert_equal NUM_REV, @repository.changesets.count
475 499 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
476 500 get :revision, :id => PRJ_ID, :rev => r
477 501 assert_response :success
478 502 assert_template 'revision'
479 503 end
480 504 end
481 505
482 506 def test_empty_revision
483 507 assert_equal 0, @repository.changesets.count
484 508 @repository.fetch_changesets
485 509 @project.reload
486 510 assert_equal NUM_REV, @repository.changesets.count
487 511 ['', ' ', nil].each do |r|
488 512 get :revision, :id => PRJ_ID, :rev => r
489 513 assert_response 404
490 514 assert_error_tag :content => /was not found/
491 515 end
492 516 end
493 517
494 518 def test_destroy_valid_repository
495 519 @request.session[:user_id] = 1 # admin
496 520 assert_equal 0, @repository.changesets.count
497 521 @repository.fetch_changesets
498 522 @project.reload
499 523 assert_equal NUM_REV, @repository.changesets.count
500 524
501 525 assert_difference 'Repository.count', -1 do
502 526 delete :destroy, :id => @repository.id
503 527 end
504 528 assert_response 302
505 529 @project.reload
506 530 assert_nil @project.repository
507 531 end
508 532
509 533 def test_destroy_invalid_repository
510 534 @request.session[:user_id] = 1 # admin
511 535 @project.repository.destroy
512 536 @repository = Repository::Git.create!(
513 537 :project => @project,
514 538 :url => "/invalid",
515 539 :path_encoding => 'ISO-8859-1'
516 540 )
517 541 @repository.fetch_changesets
518 542 @repository.reload
519 543 assert_equal 0, @repository.changesets.count
520 544
521 545 assert_difference 'Repository.count', -1 do
522 546 delete :destroy, :id => @repository.id
523 547 end
524 548 assert_response 302
525 549 @project.reload
526 550 assert_nil @project.repository
527 551 end
528 552
529 553 private
530 554
531 555 def puts_ruby19_non_utf8_pass
532 556 puts "TODO: This test fails in Ruby 1.9 " +
533 557 "and Encoding.default_external is not UTF-8. " +
534 558 "Current value is '#{Encoding.default_external.to_s}'"
535 559 end
536 560 else
537 561 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
538 562 def test_fake; assert true end
539 563 end
540 564
541 565 private
542 566 def with_cache(&block)
543 567 before = ActionController::Base.perform_caching
544 568 ActionController::Base.perform_caching = true
545 569 block.call
546 570 ActionController::Base.perform_caching = before
547 571 end
548 572 end
General Comments 0
You need to be logged in to leave comments. Login now