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