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