##// END OF EJS Templates
scm: git: add functional test of diff with revision and path (#11752)...
Toshi MARUYAMA -
r10062:6ea1bc725aad
parent child
Show More
@@ -1,534 +1,558
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 def test_diff_with_rev_and_path
289 assert_equal 0, @repository.changesets.count
290 @repository.fetch_changesets
291 @project.reload
292 assert_equal NUM_REV, @repository.changesets.count
293 # Full diff of changeset 2f9c0091
294 ['inline', 'sbs'].each do |dt|
295 get :diff,
296 :id => PRJ_ID,
297 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
298 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
299 :type => dt
300 assert_response :success
301 assert_template 'diff'
302 # Line 22 removed
303 assert_tag :tag => 'th',
304 :content => '22',
305 :sibling => { :tag => 'td',
306 :attributes => { :class => /diff_out/ },
307 :content => /def remove/ }
308 assert_tag :tag => 'h2', :content => /2f9c0091/
309 end
310 end
311
288 312 def test_diff_truncated
289 313 assert_equal 0, @repository.changesets.count
290 314 @repository.fetch_changesets
291 315 @project.reload
292 316 assert_equal NUM_REV, @repository.changesets.count
293 317
294 318 with_settings :diff_max_lines_displayed => 5 do
295 319 # Truncated diff of changeset 2f9c0091
296 320 with_cache do
297 321 get :diff, :id => PRJ_ID, :type => 'inline',
298 322 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
299 323 assert_response :success
300 324 assert @response.body.include?("... This diff was truncated")
301 325
302 326 Setting.default_language = 'fr'
303 327 get :diff, :id => PRJ_ID, :type => 'inline',
304 328 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
305 329 assert_response :success
306 330 assert ! @response.body.include?("... This diff was truncated")
307 331 assert @response.body.include?("... Ce diff")
308 332 end
309 333 end
310 334 end
311 335
312 336 def test_diff_two_revs
313 337 assert_equal 0, @repository.changesets.count
314 338 @repository.fetch_changesets
315 339 @project.reload
316 340 assert_equal NUM_REV, @repository.changesets.count
317 341 ['inline', 'sbs'].each do |dt|
318 342 get :diff,
319 343 :id => PRJ_ID,
320 344 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
321 345 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
322 346 :type => dt
323 347 assert_response :success
324 348 assert_template 'diff'
325 349 diff = assigns(:diff)
326 350 assert_not_nil diff
327 351 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
328 352 end
329 353 end
330 354
331 355 def test_diff_latin_1
332 356 if @ruby19_non_utf8_pass
333 357 puts_ruby19_non_utf8_pass()
334 358 else
335 359 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
336 360 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
337 361 ['inline', 'sbs'].each do |dt|
338 362 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
339 363 assert_response :success
340 364 assert_template 'diff'
341 365 assert_tag :tag => 'thead',
342 366 :descendant => {
343 367 :tag => 'th',
344 368 :attributes => { :class => 'filename' } ,
345 369 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
346 370 },
347 371 :sibling => {
348 372 :tag => 'tbody',
349 373 :descendant => {
350 374 :tag => 'td',
351 375 :attributes => { :class => /diff_in/ },
352 376 :content => /test-#{@char_1}.txt/
353 377 }
354 378 }
355 379 end
356 380 end
357 381 end
358 382 end
359 383 end
360 384
361 385 def test_save_diff_type
362 386 @request.session[:user_id] = 1 # admin
363 387 user = User.find(1)
364 388 get :diff,
365 389 :id => PRJ_ID,
366 390 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
367 391 assert_response :success
368 392 assert_template 'diff'
369 393 user.reload
370 394 assert_equal "inline", user.pref[:diff_type]
371 395 get :diff,
372 396 :id => PRJ_ID,
373 397 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
374 398 :type => 'sbs'
375 399 assert_response :success
376 400 assert_template 'diff'
377 401 user.reload
378 402 assert_equal "sbs", user.pref[:diff_type]
379 403 end
380 404
381 405 def test_annotate
382 406 get :annotate, :id => PRJ_ID,
383 407 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
384 408 assert_response :success
385 409 assert_template 'annotate'
386 410
387 411 # Line 23, changeset 2f9c0091
388 412 assert_select 'tr' do
389 413 assert_select 'th.line-num', :text => '23'
390 414 assert_select 'td.revision', :text => /2f9c0091/
391 415 assert_select 'td.author', :text => 'jsmith'
392 416 assert_select 'td', :text => /remove_watcher/
393 417 end
394 418 end
395 419
396 420 def test_annotate_at_given_revision
397 421 assert_equal 0, @repository.changesets.count
398 422 @repository.fetch_changesets
399 423 @project.reload
400 424 assert_equal NUM_REV, @repository.changesets.count
401 425 get :annotate, :id => PRJ_ID, :rev => 'deff7',
402 426 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
403 427 assert_response :success
404 428 assert_template 'annotate'
405 429 assert_tag :tag => 'h2', :content => /@ deff712f/
406 430 end
407 431
408 432 def test_annotate_binary_file
409 433 get :annotate, :id => PRJ_ID,
410 434 :path => repository_path_hash(['images', 'edit.png'])[:param]
411 435 assert_response 500
412 436 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
413 437 :content => /cannot be annotated/
414 438 end
415 439
416 440 def test_annotate_error_when_too_big
417 441 with_settings :file_max_size_displayed => 1 do
418 442 get :annotate, :id => PRJ_ID,
419 443 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
420 444 :rev => 'deff712f'
421 445 assert_response 500
422 446 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
423 447 :content => /exceeds the maximum text file size/
424 448
425 449 get :annotate, :id => PRJ_ID,
426 450 :path => repository_path_hash(['README'])[:param],
427 451 :rev => '7234cb2'
428 452 assert_response :success
429 453 assert_template 'annotate'
430 454 end
431 455 end
432 456
433 457 def test_annotate_latin_1
434 458 if @ruby19_non_utf8_pass
435 459 puts_ruby19_non_utf8_pass()
436 460 elsif WINDOWS_PASS
437 461 puts WINDOWS_SKIP_STR
438 462 elsif JRUBY_SKIP
439 463 puts JRUBY_SKIP_STR
440 464 else
441 465 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
442 466 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
443 467 get :annotate, :id => PRJ_ID,
444 468 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
445 469 :rev => r1
446 470 assert_tag :tag => 'th',
447 471 :content => '1',
448 472 :attributes => { :class => 'line-num' },
449 473 :sibling => { :tag => 'td',
450 474 :content => /test-#{@char_1}.txt/ }
451 475 end
452 476 end
453 477 end
454 478 end
455 479
456 480 def test_revision
457 481 assert_equal 0, @repository.changesets.count
458 482 @repository.fetch_changesets
459 483 @project.reload
460 484 assert_equal NUM_REV, @repository.changesets.count
461 485 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
462 486 get :revision, :id => PRJ_ID, :rev => r
463 487 assert_response :success
464 488 assert_template 'revision'
465 489 end
466 490 end
467 491
468 492 def test_empty_revision
469 493 assert_equal 0, @repository.changesets.count
470 494 @repository.fetch_changesets
471 495 @project.reload
472 496 assert_equal NUM_REV, @repository.changesets.count
473 497 ['', ' ', nil].each do |r|
474 498 get :revision, :id => PRJ_ID, :rev => r
475 499 assert_response 404
476 500 assert_error_tag :content => /was not found/
477 501 end
478 502 end
479 503
480 504 def test_destroy_valid_repository
481 505 @request.session[:user_id] = 1 # admin
482 506 assert_equal 0, @repository.changesets.count
483 507 @repository.fetch_changesets
484 508 @project.reload
485 509 assert_equal NUM_REV, @repository.changesets.count
486 510
487 511 assert_difference 'Repository.count', -1 do
488 512 delete :destroy, :id => @repository.id
489 513 end
490 514 assert_response 302
491 515 @project.reload
492 516 assert_nil @project.repository
493 517 end
494 518
495 519 def test_destroy_invalid_repository
496 520 @request.session[:user_id] = 1 # admin
497 521 @project.repository.destroy
498 522 @repository = Repository::Git.create!(
499 523 :project => @project,
500 524 :url => "/invalid",
501 525 :path_encoding => 'ISO-8859-1'
502 526 )
503 527 @repository.fetch_changesets
504 528 @repository.reload
505 529 assert_equal 0, @repository.changesets.count
506 530
507 531 assert_difference 'Repository.count', -1 do
508 532 delete :destroy, :id => @repository.id
509 533 end
510 534 assert_response 302
511 535 @project.reload
512 536 assert_nil @project.repository
513 537 end
514 538
515 539 private
516 540
517 541 def puts_ruby19_non_utf8_pass
518 542 puts "TODO: This test fails in Ruby 1.9 " +
519 543 "and Encoding.default_external is not UTF-8. " +
520 544 "Current value is '#{Encoding.default_external.to_s}'"
521 545 end
522 546 else
523 547 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
524 548 def test_fake; assert true end
525 549 end
526 550
527 551 private
528 552 def with_cache(&block)
529 553 before = ActionController::Base.perform_caching
530 554 ActionController::Base.perform_caching = true
531 555 block.call
532 556 ActionController::Base.perform_caching = before
533 557 end
534 558 end
General Comments 0
You need to be logged in to leave comments. Login now