##// END OF EJS Templates
Merged r9861 from trunk....
Jean-Philippe Lang -
r9679:32e3d6e1b11a
parent child
Show More
@@ -1,548 +1,548
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 ## Ruby uses ANSI api to fork a process on Windows.
33 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
34 ## and these are incompatible with ASCII.
35 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
36 ## http://code.google.com/p/msysgit/issues/detail?id=80
37 ## So, Latin-1 path tests fail on Japanese Windows
38 WINDOWS_PASS = (Redmine::Platform.mswin? &&
39 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
40 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
41
42 32 ## Git, Mercurial and CVS path encodings are binary.
43 33 ## Subversion supports URL encoding for path.
44 34 ## Redmine Mercurial adapter and extension use URL encoding.
45 35 ## Git accepts only binary path in command line parameter.
46 36 ## So, there is no way to use binary command line parameter in JRuby.
47 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
48 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
49 39
50 40 def setup
51 41 @ruby19_non_utf8_pass =
52 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
53 43
54 44 User.current = nil
55 45 @project = Project.find(PRJ_ID)
56 46 @repository = Repository::Git.create(
57 47 :project => @project,
58 48 :url => REPOSITORY_PATH,
59 49 :path_encoding => 'ISO-8859-1'
60 50 )
61 51 assert @repository
62 52 @char_1 = CHAR_1_HEX.dup
63 53 if @char_1.respond_to?(:force_encoding)
64 54 @char_1.force_encoding('UTF-8')
65 55 end
66 56
67 57 Setting.default_language = 'en'
68 58 end
69 59
70 60 def test_create_and_update
71 61 @request.session[:user_id] = 1
72 62 assert_difference 'Repository.count' do
73 63 post :create, :project_id => 'subproject1',
74 64 :repository_scm => 'Git',
75 65 :repository => {
76 66 :url => '/test',
77 67 :is_default => '0',
78 68 :identifier => 'test-create',
79 69 :extra_report_last_commit => '1',
80 70 }
81 71 end
82 72 assert_response 302
83 73 repository = Repository.first(:order => 'id DESC')
84 74 assert_kind_of Repository::Git, repository
85 75 assert_equal '/test', repository.url
86 76 assert_equal true, repository.extra_report_last_commit
87 77
88 78 put :update, :id => repository.id,
89 79 :repository => {
90 80 :extra_report_last_commit => '0',
91 81 :identifier => 'test-update',
92 82 }
93 83 assert_response 302
94 84 repo2 = Repository.find(repository.id)
95 85 assert_equal 'test-update', repo2.identifier
96 86 assert_equal false, repo2.extra_report_last_commit
97 87 end
98 88
99 89 if File.directory?(REPOSITORY_PATH)
90 ## Ruby uses ANSI api to fork a process on Windows.
91 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
92 ## and these are incompatible with ASCII.
93 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
94 ## http://code.google.com/p/msysgit/issues/detail?id=80
95 ## So, Latin-1 path tests fail on Japanese Windows
96 WINDOWS_PASS = (Redmine::Platform.mswin? &&
97 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
98 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
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 290 def test_diff_truncated
291 291 assert_equal 0, @repository.changesets.count
292 292 @repository.fetch_changesets
293 293 @project.reload
294 294 assert_equal NUM_REV, @repository.changesets.count
295 295 Setting.diff_max_lines_displayed = 5
296 296
297 297 # Truncated diff of changeset 2f9c0091
298 298 with_cache do
299 299 get :diff, :id => PRJ_ID, :type => 'inline',
300 300 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
301 301 assert_response :success
302 302 assert @response.body.include?("... This diff was truncated")
303 303
304 304 Setting.default_language = 'fr'
305 305 get :diff, :id => PRJ_ID, :type => 'inline',
306 306 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
307 307 assert_response :success
308 308 assert ! @response.body.include?("... This diff was truncated")
309 309 assert @response.body.include?("... Ce diff")
310 310 end
311 311 end
312 312
313 313 def test_diff_two_revs
314 314 assert_equal 0, @repository.changesets.count
315 315 @repository.fetch_changesets
316 316 @project.reload
317 317 assert_equal NUM_REV, @repository.changesets.count
318 318 ['inline', 'sbs'].each do |dt|
319 319 get :diff,
320 320 :id => PRJ_ID,
321 321 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
322 322 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
323 323 :type => dt
324 324 assert_response :success
325 325 assert_template 'diff'
326 326 diff = assigns(:diff)
327 327 assert_not_nil diff
328 328 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
329 329 end
330 330 end
331 331
332 332 def test_diff_latin_1
333 333 if @ruby19_non_utf8_pass
334 334 puts_ruby19_non_utf8_pass()
335 335 else
336 336 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
337 337 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
338 338 ['inline', 'sbs'].each do |dt|
339 339 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
340 340 assert_response :success
341 341 assert_template 'diff'
342 342 assert_tag :tag => 'thead',
343 343 :descendant => {
344 344 :tag => 'th',
345 345 :attributes => { :class => 'filename' } ,
346 346 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
347 347 },
348 348 :sibling => {
349 349 :tag => 'tbody',
350 350 :descendant => {
351 351 :tag => 'td',
352 352 :attributes => { :class => /diff_in/ },
353 353 :content => /test-#{@char_1}.txt/
354 354 }
355 355 }
356 356 end
357 357 end
358 358 end
359 359 end
360 360 end
361 361
362 362 def test_save_diff_type
363 363 @request.session[:user_id] = 1 # admin
364 364 user = User.find(1)
365 365 get :diff,
366 366 :id => PRJ_ID,
367 367 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
368 368 assert_response :success
369 369 assert_template 'diff'
370 370 user.reload
371 371 assert_equal "inline", user.pref[:diff_type]
372 372 get :diff,
373 373 :id => PRJ_ID,
374 374 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
375 375 :type => 'sbs'
376 376 assert_response :success
377 377 assert_template 'diff'
378 378 user.reload
379 379 assert_equal "sbs", user.pref[:diff_type]
380 380 end
381 381
382 382 def test_annotate
383 383 get :annotate, :id => PRJ_ID,
384 384 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
385 385 assert_response :success
386 386 assert_template 'annotate'
387 387 # Line 24, changeset 2f9c0091
388 388 assert_tag :tag => 'th', :content => '24',
389 389 :sibling => {
390 390 :tag => 'td',
391 391 :child => {
392 392 :tag => 'a',
393 393 :content => /2f9c0091/
394 394 }
395 395 }
396 396 assert_tag :tag => 'th', :content => '24',
397 397 :sibling => { :tag => 'td', :content => /jsmith/ }
398 398 assert_tag :tag => 'th', :content => '24',
399 399 :sibling => {
400 400 :tag => 'td',
401 401 :child => {
402 402 :tag => 'a',
403 403 :content => /2f9c0091/
404 404 }
405 405 }
406 406 assert_tag :tag => 'th', :content => '24',
407 407 :sibling => { :tag => 'td', :content => /watcher =/ }
408 408 end
409 409
410 410 def test_annotate_at_given_revision
411 411 assert_equal 0, @repository.changesets.count
412 412 @repository.fetch_changesets
413 413 @project.reload
414 414 assert_equal NUM_REV, @repository.changesets.count
415 415 get :annotate, :id => PRJ_ID, :rev => 'deff7',
416 416 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
417 417 assert_response :success
418 418 assert_template 'annotate'
419 419 assert_tag :tag => 'h2', :content => /@ deff712f/
420 420 end
421 421
422 422 def test_annotate_binary_file
423 423 get :annotate, :id => PRJ_ID,
424 424 :path => repository_path_hash(['images', 'edit.png'])[:param]
425 425 assert_response 500
426 426 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
427 427 :content => /cannot be annotated/
428 428 end
429 429
430 430 def test_annotate_error_when_too_big
431 431 with_settings :file_max_size_displayed => 1 do
432 432 get :annotate, :id => PRJ_ID,
433 433 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
434 434 :rev => 'deff712f'
435 435 assert_response 500
436 436 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
437 437 :content => /exceeds the maximum text file size/
438 438
439 439 get :annotate, :id => PRJ_ID,
440 440 :path => repository_path_hash(['README'])[:param],
441 441 :rev => '7234cb2'
442 442 assert_response :success
443 443 assert_template 'annotate'
444 444 end
445 445 end
446 446
447 447 def test_annotate_latin_1
448 448 if @ruby19_non_utf8_pass
449 449 puts_ruby19_non_utf8_pass()
450 450 elsif WINDOWS_PASS
451 451 puts WINDOWS_SKIP_STR
452 452 elsif JRUBY_SKIP
453 453 puts JRUBY_SKIP_STR
454 454 else
455 455 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
456 456 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
457 457 get :annotate, :id => PRJ_ID,
458 458 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
459 459 :rev => r1
460 460 assert_tag :tag => 'th',
461 461 :content => '1',
462 462 :attributes => { :class => 'line-num' },
463 463 :sibling => { :tag => 'td',
464 464 :content => /test-#{@char_1}.txt/ }
465 465 end
466 466 end
467 467 end
468 468 end
469 469
470 470 def test_revision
471 471 assert_equal 0, @repository.changesets.count
472 472 @repository.fetch_changesets
473 473 @project.reload
474 474 assert_equal NUM_REV, @repository.changesets.count
475 475 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
476 476 get :revision, :id => PRJ_ID, :rev => r
477 477 assert_response :success
478 478 assert_template 'revision'
479 479 end
480 480 end
481 481
482 482 def test_empty_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 ['', ' ', nil].each do |r|
488 488 get :revision, :id => PRJ_ID, :rev => r
489 489 assert_response 404
490 490 assert_error_tag :content => /was not found/
491 491 end
492 492 end
493 493
494 494 def test_destroy_valid_repository
495 495 @request.session[:user_id] = 1 # admin
496 496 assert_equal 0, @repository.changesets.count
497 497 @repository.fetch_changesets
498 498 @project.reload
499 499 assert_equal NUM_REV, @repository.changesets.count
500 500
501 501 assert_difference 'Repository.count', -1 do
502 502 delete :destroy, :id => @repository.id
503 503 end
504 504 assert_response 302
505 505 @project.reload
506 506 assert_nil @project.repository
507 507 end
508 508
509 509 def test_destroy_invalid_repository
510 510 @request.session[:user_id] = 1 # admin
511 511 @project.repository.destroy
512 512 @repository = Repository::Git.create!(
513 513 :project => @project,
514 514 :url => "/invalid",
515 515 :path_encoding => 'ISO-8859-1'
516 516 )
517 517 @repository.fetch_changesets
518 518 @repository.reload
519 519 assert_equal 0, @repository.changesets.count
520 520
521 521 assert_difference 'Repository.count', -1 do
522 522 delete :destroy, :id => @repository.id
523 523 end
524 524 assert_response 302
525 525 @project.reload
526 526 assert_nil @project.repository
527 527 end
528 528
529 529 private
530 530
531 531 def puts_ruby19_non_utf8_pass
532 532 puts "TODO: This test fails in Ruby 1.9 " +
533 533 "and Encoding.default_external is not UTF-8. " +
534 534 "Current value is '#{Encoding.default_external.to_s}'"
535 535 end
536 536 else
537 537 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
538 538 def test_fake; assert true end
539 539 end
540 540
541 541 private
542 542 def with_cache(&block)
543 543 before = ActionController::Base.perform_caching
544 544 ActionController::Base.perform_caching = true
545 545 block.call
546 546 ActionController::Base.perform_caching = before
547 547 end
548 548 end
@@ -1,562 +1,562
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 RepositoryGitTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 include Redmine::I18n
24 24
25 25 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
26 26 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
27 27
28 28 NUM_REV = 28
29 29 NUM_HEAD = 6
30 30
31 31 FELIX_HEX = "Felix Sch\xC3\xA4fer"
32 32 CHAR_1_HEX = "\xc3\x9c"
33 33
34 ## Ruby uses ANSI api to fork a process on Windows.
35 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
36 ## and these are incompatible with ASCII.
37 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
38 ## http://code.google.com/p/msysgit/issues/detail?id=80
39 ## So, Latin-1 path tests fail on Japanese Windows
40 WINDOWS_PASS = (Redmine::Platform.mswin? &&
41 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
42 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
43
44 34 ## Git, Mercurial and CVS path encodings are binary.
45 35 ## Subversion supports URL encoding for path.
46 36 ## Redmine Mercurial adapter and extension use URL encoding.
47 37 ## Git accepts only binary path in command line parameter.
48 38 ## So, there is no way to use binary command line parameter in JRuby.
49 39 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
50 40 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
51 41
52 42 def setup
53 43 @project = Project.find(3)
54 44 @repository = Repository::Git.create(
55 45 :project => @project,
56 46 :url => REPOSITORY_PATH,
57 47 :path_encoding => 'ISO-8859-1'
58 48 )
59 49 assert @repository
60 50 @char_1 = CHAR_1_HEX.dup
61 51 if @char_1.respond_to?(:force_encoding)
62 52 @char_1.force_encoding('UTF-8')
63 53 end
64 54 end
65 55
66 56 def test_blank_path_to_repository_error_message
67 57 set_language_if_valid 'en'
68 58 repo = Repository::Git.new(
69 59 :project => @project,
70 60 :identifier => 'test'
71 61 )
72 62 assert !repo.save
73 63 assert_include "Path to repository can't be blank",
74 64 repo.errors.full_messages
75 65 end
76 66
77 67 def test_blank_path_to_repository_error_message_fr
78 68 set_language_if_valid 'fr'
79 69 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
80 70 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
81 71 repo = Repository::Git.new(
82 72 :project => @project,
83 73 :url => "",
84 74 :identifier => 'test',
85 75 :path_encoding => ''
86 76 )
87 77 assert !repo.save
88 78 assert_include str, repo.errors.full_messages
89 79 end
90 80
91 81 if File.directory?(REPOSITORY_PATH)
82 ## Ruby uses ANSI api to fork a process on Windows.
83 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
84 ## and these are incompatible with ASCII.
85 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
86 ## http://code.google.com/p/msysgit/issues/detail?id=80
87 ## So, Latin-1 path tests fail on Japanese Windows
88 WINDOWS_PASS = (Redmine::Platform.mswin? &&
89 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
90 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
91
92 92 def test_scm_available
93 93 klass = Repository::Git
94 94 assert_equal "Git", klass.scm_name
95 95 assert klass.scm_adapter_class
96 96 assert_not_equal "", klass.scm_command
97 97 assert_equal true, klass.scm_available
98 98 end
99 99
100 100 def test_fetch_changesets_from_scratch
101 101 assert_nil @repository.extra_info
102 102
103 103 assert_equal 0, @repository.changesets.count
104 104 @repository.fetch_changesets
105 105 @project.reload
106 106
107 107 assert_equal NUM_REV, @repository.changesets.count
108 108 assert_equal 39, @repository.filechanges.count
109 109
110 110 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
111 111 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
112 112 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
113 113 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
114 114 assert_equal User.find_by_login('jsmith'), commit.user
115 115 # TODO: add a commit with commit time <> author time to the test repository
116 116 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
117 117 assert_equal "2007-12-14".to_date, commit.commit_date
118 118 assert_equal 3, commit.filechanges.count
119 119 change = commit.filechanges.sort_by(&:path).first
120 120 assert_equal "README", change.path
121 121 assert_equal nil, change.from_path
122 122 assert_equal "A", change.action
123 123
124 124 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
125 125 end
126 126
127 127 def test_fetch_changesets_incremental
128 128 assert_equal 0, @repository.changesets.count
129 129 @repository.fetch_changesets
130 130 @project.reload
131 131 assert_equal NUM_REV, @repository.changesets.count
132 132 extra_info_heads = @repository.extra_info["heads"].dup
133 133 assert_equal NUM_HEAD, extra_info_heads.size
134 134 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
135 135 assert_equal 4, extra_info_heads.size
136 136
137 137 del_revs = [
138 138 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
139 139 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
140 140 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
141 141 "deff712f05a90d96edbd70facc47d944be5897e3",
142 142 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
143 143 "7e61ac704deecde634b51e59daa8110435dcb3da",
144 144 ]
145 145 @repository.changesets.each do |rev|
146 146 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
147 147 end
148 148 @project.reload
149 149 cs1 = @repository.changesets
150 150 assert_equal NUM_REV - 6, cs1.count
151 151 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
152 152 h = {}
153 153 h["heads"] = extra_info_heads
154 154 @repository.merge_extra_info(h)
155 155 @repository.save
156 156 @project.reload
157 157 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
158 158 @repository.fetch_changesets
159 159 @project.reload
160 160 assert_equal NUM_REV, @repository.changesets.count
161 161 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
162 162 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
163 163 end
164 164
165 165 def test_fetch_changesets_history_editing
166 166 assert_equal 0, @repository.changesets.count
167 167 @repository.fetch_changesets
168 168 @project.reload
169 169 assert_equal NUM_REV, @repository.changesets.count
170 170 extra_info_heads = @repository.extra_info["heads"].dup
171 171 assert_equal NUM_HEAD, extra_info_heads.size
172 172 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
173 173 assert_equal 4, extra_info_heads.size
174 174
175 175 del_revs = [
176 176 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
177 177 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
178 178 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
179 179 "deff712f05a90d96edbd70facc47d944be5897e3",
180 180 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
181 181 "7e61ac704deecde634b51e59daa8110435dcb3da",
182 182 ]
183 183 @repository.changesets.each do |rev|
184 184 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
185 185 end
186 186 @project.reload
187 187 assert_equal NUM_REV - 6, @repository.changesets.count
188 188
189 189 c = Changeset.new(:repository => @repository,
190 190 :committed_on => Time.now,
191 191 :revision => "abcd1234efgh",
192 192 :scmid => "abcd1234efgh",
193 193 :comments => 'test')
194 194 assert c.save
195 195 @project.reload
196 196 assert_equal NUM_REV - 5, @repository.changesets.count
197 197
198 198 extra_info_heads << "1234abcd5678"
199 199 h = {}
200 200 h["heads"] = extra_info_heads
201 201 @repository.merge_extra_info(h)
202 202 @repository.save
203 203 @project.reload
204 204 h1 = @repository.extra_info["heads"].dup
205 205 assert h1.index("1234abcd5678")
206 206 assert_equal 5, h1.size
207 207
208 208 @repository.fetch_changesets
209 209 @project.reload
210 210 assert_equal NUM_REV - 5, @repository.changesets.count
211 211 h2 = @repository.extra_info["heads"].dup
212 212 assert_equal h1, h2
213 213 end
214 214
215 215 def test_parents
216 216 assert_equal 0, @repository.changesets.count
217 217 @repository.fetch_changesets
218 218 @project.reload
219 219 assert_equal NUM_REV, @repository.changesets.count
220 220 r1 = @repository.find_changeset_by_name("7234cb2750b63")
221 221 assert_equal [], r1.parents
222 222 r2 = @repository.find_changeset_by_name("899a15dba03a3")
223 223 assert_equal 1, r2.parents.length
224 224 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
225 225 r2.parents[0].identifier
226 226 r3 = @repository.find_changeset_by_name("32ae898b720c2")
227 227 assert_equal 2, r3.parents.length
228 228 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
229 229 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
230 230 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
231 231 end
232 232
233 233 def test_db_consistent_ordering_init
234 234 assert_nil @repository.extra_info
235 235 assert_equal 0, @repository.changesets.count
236 236 @repository.fetch_changesets
237 237 @project.reload
238 238 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
239 239 end
240 240
241 241 def test_db_consistent_ordering_before_1_2
242 242 assert_nil @repository.extra_info
243 243 assert_equal 0, @repository.changesets.count
244 244 @repository.fetch_changesets
245 245 @project.reload
246 246 assert_equal NUM_REV, @repository.changesets.count
247 247 assert_not_nil @repository.extra_info
248 248 h = {}
249 249 h["heads"] = []
250 250 h["branches"] = {}
251 251 h["db_consistent"] = {}
252 252 @repository.merge_extra_info(h)
253 253 @repository.save
254 254 assert_equal NUM_REV, @repository.changesets.count
255 255 @repository.fetch_changesets
256 256 @project.reload
257 257 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
258 258
259 259 extra_info_heads = @repository.extra_info["heads"].dup
260 260 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
261 261 del_revs = [
262 262 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
263 263 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
264 264 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
265 265 "deff712f05a90d96edbd70facc47d944be5897e3",
266 266 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
267 267 "7e61ac704deecde634b51e59daa8110435dcb3da",
268 268 ]
269 269 @repository.changesets.each do |rev|
270 270 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
271 271 end
272 272 @project.reload
273 273 cs1 = @repository.changesets
274 274 assert_equal NUM_REV - 6, cs1.count
275 275 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
276 276
277 277 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
278 278 h = {}
279 279 h["heads"] = extra_info_heads
280 280 @repository.merge_extra_info(h)
281 281 @repository.save
282 282 @project.reload
283 283 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
284 284 @repository.fetch_changesets
285 285 @project.reload
286 286 assert_equal NUM_REV, @repository.changesets.count
287 287 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
288 288
289 289 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
290 290 end
291 291
292 292 def test_heads_from_branches_hash
293 293 assert_nil @repository.extra_info
294 294 assert_equal 0, @repository.changesets.count
295 295 assert_equal [], @repository.heads_from_branches_hash
296 296 h = {}
297 297 h["branches"] = {}
298 298 h["branches"]["test1"] = {}
299 299 h["branches"]["test1"]["last_scmid"] = "1234abcd"
300 300 h["branches"]["test2"] = {}
301 301 h["branches"]["test2"]["last_scmid"] = "abcd1234"
302 302 @repository.merge_extra_info(h)
303 303 @repository.save
304 304 @project.reload
305 305 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
306 306 end
307 307
308 308 def test_latest_changesets
309 309 assert_equal 0, @repository.changesets.count
310 310 @repository.fetch_changesets
311 311 @project.reload
312 312 assert_equal NUM_REV, @repository.changesets.count
313 313 # with limit
314 314 changesets = @repository.latest_changesets('', 'master', 2)
315 315 assert_equal 2, changesets.size
316 316
317 317 # with path
318 318 changesets = @repository.latest_changesets('images', 'master')
319 319 assert_equal [
320 320 'deff712f05a90d96edbd70facc47d944be5897e3',
321 321 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
322 322 '7234cb2750b63f47bff735edc50a1c0a433c2518',
323 323 ], changesets.collect(&:revision)
324 324
325 325 changesets = @repository.latest_changesets('README', nil)
326 326 assert_equal [
327 327 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
328 328 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
329 329 '713f4944648826f558cf548222f813dabe7cbb04',
330 330 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
331 331 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
332 332 '7234cb2750b63f47bff735edc50a1c0a433c2518',
333 333 ], changesets.collect(&:revision)
334 334
335 335 # with path, revision and limit
336 336 changesets = @repository.latest_changesets('images', '899a15dba')
337 337 assert_equal [
338 338 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
339 339 '7234cb2750b63f47bff735edc50a1c0a433c2518',
340 340 ], changesets.collect(&:revision)
341 341
342 342 changesets = @repository.latest_changesets('images', '899a15dba', 1)
343 343 assert_equal [
344 344 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
345 345 ], changesets.collect(&:revision)
346 346
347 347 changesets = @repository.latest_changesets('README', '899a15dba')
348 348 assert_equal [
349 349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
350 350 '7234cb2750b63f47bff735edc50a1c0a433c2518',
351 351 ], changesets.collect(&:revision)
352 352
353 353 changesets = @repository.latest_changesets('README', '899a15dba', 1)
354 354 assert_equal [
355 355 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
356 356 ], changesets.collect(&:revision)
357 357
358 358 # with path, tag and limit
359 359 changesets = @repository.latest_changesets('images', 'tag01.annotated')
360 360 assert_equal [
361 361 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
362 362 '7234cb2750b63f47bff735edc50a1c0a433c2518',
363 363 ], changesets.collect(&:revision)
364 364
365 365 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
366 366 assert_equal [
367 367 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
368 368 ], changesets.collect(&:revision)
369 369
370 370 changesets = @repository.latest_changesets('README', 'tag01.annotated')
371 371 assert_equal [
372 372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
373 373 '7234cb2750b63f47bff735edc50a1c0a433c2518',
374 374 ], changesets.collect(&:revision)
375 375
376 376 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
377 377 assert_equal [
378 378 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
379 379 ], changesets.collect(&:revision)
380 380
381 381 # with path, branch and limit
382 382 changesets = @repository.latest_changesets('images', 'test_branch')
383 383 assert_equal [
384 384 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
385 385 '7234cb2750b63f47bff735edc50a1c0a433c2518',
386 386 ], changesets.collect(&:revision)
387 387
388 388 changesets = @repository.latest_changesets('images', 'test_branch', 1)
389 389 assert_equal [
390 390 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
391 391 ], changesets.collect(&:revision)
392 392
393 393 changesets = @repository.latest_changesets('README', 'test_branch')
394 394 assert_equal [
395 395 '713f4944648826f558cf548222f813dabe7cbb04',
396 396 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
397 397 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
398 398 '7234cb2750b63f47bff735edc50a1c0a433c2518',
399 399 ], changesets.collect(&:revision)
400 400
401 401 changesets = @repository.latest_changesets('README', 'test_branch', 2)
402 402 assert_equal [
403 403 '713f4944648826f558cf548222f813dabe7cbb04',
404 404 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
405 405 ], changesets.collect(&:revision)
406 406
407 407 if WINDOWS_PASS
408 408 puts WINDOWS_SKIP_STR
409 409 elsif JRUBY_SKIP
410 410 puts JRUBY_SKIP_STR
411 411 else
412 412 # latin-1 encoding path
413 413 changesets = @repository.latest_changesets(
414 414 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
415 415 assert_equal [
416 416 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
417 417 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
418 418 ], changesets.collect(&:revision)
419 419
420 420 changesets = @repository.latest_changesets(
421 421 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
422 422 assert_equal [
423 423 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
424 424 ], changesets.collect(&:revision)
425 425 end
426 426 end
427 427
428 428 def test_latest_changesets_latin_1_dir
429 429 if WINDOWS_PASS
430 430 puts WINDOWS_SKIP_STR
431 431 elsif JRUBY_SKIP
432 432 puts JRUBY_SKIP_STR
433 433 else
434 434 assert_equal 0, @repository.changesets.count
435 435 @repository.fetch_changesets
436 436 @project.reload
437 437 assert_equal NUM_REV, @repository.changesets.count
438 438 changesets = @repository.latest_changesets(
439 439 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
440 440 assert_equal [
441 441 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
442 442 ], changesets.collect(&:revision)
443 443 end
444 444 end
445 445
446 446 def test_find_changeset_by_name
447 447 assert_equal 0, @repository.changesets.count
448 448 @repository.fetch_changesets
449 449 @project.reload
450 450 assert_equal NUM_REV, @repository.changesets.count
451 451 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
452 452 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
453 453 @repository.find_changeset_by_name(r).revision
454 454 end
455 455 end
456 456
457 457 def test_find_changeset_by_empty_name
458 458 assert_equal 0, @repository.changesets.count
459 459 @repository.fetch_changesets
460 460 @project.reload
461 461 assert_equal NUM_REV, @repository.changesets.count
462 462 ['', ' ', nil].each do |r|
463 463 assert_nil @repository.find_changeset_by_name(r)
464 464 end
465 465 end
466 466
467 467 def test_identifier
468 468 assert_equal 0, @repository.changesets.count
469 469 @repository.fetch_changesets
470 470 @project.reload
471 471 assert_equal NUM_REV, @repository.changesets.count
472 472 c = @repository.changesets.find_by_revision(
473 473 '7234cb2750b63f47bff735edc50a1c0a433c2518')
474 474 assert_equal c.scmid, c.identifier
475 475 end
476 476
477 477 def test_format_identifier
478 478 assert_equal 0, @repository.changesets.count
479 479 @repository.fetch_changesets
480 480 @project.reload
481 481 assert_equal NUM_REV, @repository.changesets.count
482 482 c = @repository.changesets.find_by_revision(
483 483 '7234cb2750b63f47bff735edc50a1c0a433c2518')
484 484 assert_equal '7234cb27', c.format_identifier
485 485 end
486 486
487 487 def test_activities
488 488 c = Changeset.new(:repository => @repository,
489 489 :committed_on => Time.now,
490 490 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
491 491 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
492 492 :comments => 'test')
493 493 assert c.event_title.include?('abc7234c:')
494 494 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
495 495 end
496 496
497 497 def test_log_utf8
498 498 assert_equal 0, @repository.changesets.count
499 499 @repository.fetch_changesets
500 500 @project.reload
501 501 assert_equal NUM_REV, @repository.changesets.count
502 502 str_felix_hex = FELIX_HEX.dup
503 503 if str_felix_hex.respond_to?(:force_encoding)
504 504 str_felix_hex.force_encoding('UTF-8')
505 505 end
506 506 c = @repository.changesets.find_by_revision(
507 507 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
508 508 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
509 509 end
510 510
511 511 def test_previous
512 512 assert_equal 0, @repository.changesets.count
513 513 @repository.fetch_changesets
514 514 @project.reload
515 515 assert_equal NUM_REV, @repository.changesets.count
516 516 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
517 517 changeset = @repository.find_changeset_by_name(r1)
518 518 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
519 519 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
520 520 end
521 521 end
522 522 end
523 523
524 524 def test_previous_nil
525 525 assert_equal 0, @repository.changesets.count
526 526 @repository.fetch_changesets
527 527 @project.reload
528 528 assert_equal NUM_REV, @repository.changesets.count
529 529 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
530 530 changeset = @repository.find_changeset_by_name(r1)
531 531 assert_nil changeset.previous
532 532 end
533 533 end
534 534
535 535 def test_next
536 536 assert_equal 0, @repository.changesets.count
537 537 @repository.fetch_changesets
538 538 @project.reload
539 539 assert_equal NUM_REV, @repository.changesets.count
540 540 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
541 541 changeset = @repository.find_changeset_by_name(r2)
542 542 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
543 543 assert_equal @repository.find_changeset_by_name(r1), changeset.next
544 544 end
545 545 end
546 546 end
547 547
548 548 def test_next_nil
549 549 assert_equal 0, @repository.changesets.count
550 550 @repository.fetch_changesets
551 551 @project.reload
552 552 assert_equal NUM_REV, @repository.changesets.count
553 553 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
554 554 changeset = @repository.find_changeset_by_name(r1)
555 555 assert_nil changeset.next
556 556 end
557 557 end
558 558 else
559 559 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
560 560 def test_fake; assert true end
561 561 end
562 562 end
General Comments 0
You need to be logged in to leave comments. Login now