##// END OF EJS Templates
Fix: Unable to run unit and functional tests if git binary is not available....
Jean-Philippe Lang -
r9678:2311f80c5dd1
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,567 +1,567
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_entries
101 101 entries = @repository.entries
102 102 assert_kind_of Redmine::Scm::Adapters::Entries, entries
103 103 end
104 104
105 105 def test_fetch_changesets_from_scratch
106 106 assert_nil @repository.extra_info
107 107
108 108 assert_equal 0, @repository.changesets.count
109 109 @repository.fetch_changesets
110 110 @project.reload
111 111
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 assert_equal 39, @repository.filechanges.count
114 114
115 115 commit = @repository.changesets.find_by_revision("7234cb2750b63f47bff735edc50a1c0a433c2518")
116 116 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
117 117 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
118 118 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
119 119 assert_equal User.find_by_login('jsmith'), commit.user
120 120 # TODO: add a commit with commit time <> author time to the test repository
121 121 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
122 122 assert_equal "2007-12-14".to_date, commit.commit_date
123 123 assert_equal 3, commit.filechanges.count
124 124 change = commit.filechanges.sort_by(&:path).first
125 125 assert_equal "README", change.path
126 126 assert_equal nil, change.from_path
127 127 assert_equal "A", change.action
128 128
129 129 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
130 130 end
131 131
132 132 def test_fetch_changesets_incremental
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 extra_info_heads = @repository.extra_info["heads"].dup
138 138 assert_equal NUM_HEAD, extra_info_heads.size
139 139 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
140 140 assert_equal 4, extra_info_heads.size
141 141
142 142 del_revs = [
143 143 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
144 144 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
145 145 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
146 146 "deff712f05a90d96edbd70facc47d944be5897e3",
147 147 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
148 148 "7e61ac704deecde634b51e59daa8110435dcb3da",
149 149 ]
150 150 @repository.changesets.each do |rev|
151 151 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
152 152 end
153 153 @project.reload
154 154 cs1 = @repository.changesets
155 155 assert_equal NUM_REV - 6, cs1.count
156 156 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
157 157 h = {}
158 158 h["heads"] = extra_info_heads
159 159 @repository.merge_extra_info(h)
160 160 @repository.save
161 161 @project.reload
162 162 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
163 163 @repository.fetch_changesets
164 164 @project.reload
165 165 assert_equal NUM_REV, @repository.changesets.count
166 166 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
167 167 assert @repository.extra_info["heads"].index("83ca5fd546063a3c7dc2e568ba3355661a9e2b2c")
168 168 end
169 169
170 170 def test_fetch_changesets_history_editing
171 171 assert_equal 0, @repository.changesets.count
172 172 @repository.fetch_changesets
173 173 @project.reload
174 174 assert_equal NUM_REV, @repository.changesets.count
175 175 extra_info_heads = @repository.extra_info["heads"].dup
176 176 assert_equal NUM_HEAD, extra_info_heads.size
177 177 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
178 178 assert_equal 4, extra_info_heads.size
179 179
180 180 del_revs = [
181 181 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
182 182 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
183 183 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
184 184 "deff712f05a90d96edbd70facc47d944be5897e3",
185 185 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
186 186 "7e61ac704deecde634b51e59daa8110435dcb3da",
187 187 ]
188 188 @repository.changesets.each do |rev|
189 189 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
190 190 end
191 191 @project.reload
192 192 assert_equal NUM_REV - 6, @repository.changesets.count
193 193
194 194 c = Changeset.new(:repository => @repository,
195 195 :committed_on => Time.now,
196 196 :revision => "abcd1234efgh",
197 197 :scmid => "abcd1234efgh",
198 198 :comments => 'test')
199 199 assert c.save
200 200 @project.reload
201 201 assert_equal NUM_REV - 5, @repository.changesets.count
202 202
203 203 extra_info_heads << "1234abcd5678"
204 204 h = {}
205 205 h["heads"] = extra_info_heads
206 206 @repository.merge_extra_info(h)
207 207 @repository.save
208 208 @project.reload
209 209 h1 = @repository.extra_info["heads"].dup
210 210 assert h1.index("1234abcd5678")
211 211 assert_equal 5, h1.size
212 212
213 213 @repository.fetch_changesets
214 214 @project.reload
215 215 assert_equal NUM_REV - 5, @repository.changesets.count
216 216 h2 = @repository.extra_info["heads"].dup
217 217 assert_equal h1, h2
218 218 end
219 219
220 220 def test_parents
221 221 assert_equal 0, @repository.changesets.count
222 222 @repository.fetch_changesets
223 223 @project.reload
224 224 assert_equal NUM_REV, @repository.changesets.count
225 225 r1 = @repository.find_changeset_by_name("7234cb2750b63")
226 226 assert_equal [], r1.parents
227 227 r2 = @repository.find_changeset_by_name("899a15dba03a3")
228 228 assert_equal 1, r2.parents.length
229 229 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518",
230 230 r2.parents[0].identifier
231 231 r3 = @repository.find_changeset_by_name("32ae898b720c2")
232 232 assert_equal 2, r3.parents.length
233 233 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
234 234 assert_equal "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8", r4[0]
235 235 assert_equal "7e61ac704deecde634b51e59daa8110435dcb3da", r4[1]
236 236 end
237 237
238 238 def test_db_consistent_ordering_init
239 239 assert_nil @repository.extra_info
240 240 assert_equal 0, @repository.changesets.count
241 241 @repository.fetch_changesets
242 242 @project.reload
243 243 assert_equal 1, @repository.extra_info["db_consistent"]["ordering"]
244 244 end
245 245
246 246 def test_db_consistent_ordering_before_1_2
247 247 assert_nil @repository.extra_info
248 248 assert_equal 0, @repository.changesets.count
249 249 @repository.fetch_changesets
250 250 @project.reload
251 251 assert_equal NUM_REV, @repository.changesets.count
252 252 assert_not_nil @repository.extra_info
253 253 h = {}
254 254 h["heads"] = []
255 255 h["branches"] = {}
256 256 h["db_consistent"] = {}
257 257 @repository.merge_extra_info(h)
258 258 @repository.save
259 259 assert_equal NUM_REV, @repository.changesets.count
260 260 @repository.fetch_changesets
261 261 @project.reload
262 262 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
263 263
264 264 extra_info_heads = @repository.extra_info["heads"].dup
265 265 extra_info_heads.delete_if { |x| x == "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c" }
266 266 del_revs = [
267 267 "83ca5fd546063a3c7dc2e568ba3355661a9e2b2c",
268 268 "ed5bb786bbda2dee66a2d50faf51429dbc043a7b",
269 269 "4f26664364207fa8b1af9f8722647ab2d4ac5d43",
270 270 "deff712f05a90d96edbd70facc47d944be5897e3",
271 271 "32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf",
272 272 "7e61ac704deecde634b51e59daa8110435dcb3da",
273 273 ]
274 274 @repository.changesets.each do |rev|
275 275 rev.destroy if del_revs.detect {|r| r == rev.scmid.to_s }
276 276 end
277 277 @project.reload
278 278 cs1 = @repository.changesets
279 279 assert_equal NUM_REV - 6, cs1.count
280 280 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
281 281
282 282 extra_info_heads << "4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8"
283 283 h = {}
284 284 h["heads"] = extra_info_heads
285 285 @repository.merge_extra_info(h)
286 286 @repository.save
287 287 @project.reload
288 288 assert @repository.extra_info["heads"].index("4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8")
289 289 @repository.fetch_changesets
290 290 @project.reload
291 291 assert_equal NUM_REV, @repository.changesets.count
292 292 assert_equal NUM_HEAD, @repository.extra_info["heads"].size
293 293
294 294 assert_equal 0, @repository.extra_info["db_consistent"]["ordering"]
295 295 end
296 296
297 297 def test_heads_from_branches_hash
298 298 assert_nil @repository.extra_info
299 299 assert_equal 0, @repository.changesets.count
300 300 assert_equal [], @repository.heads_from_branches_hash
301 301 h = {}
302 302 h["branches"] = {}
303 303 h["branches"]["test1"] = {}
304 304 h["branches"]["test1"]["last_scmid"] = "1234abcd"
305 305 h["branches"]["test2"] = {}
306 306 h["branches"]["test2"]["last_scmid"] = "abcd1234"
307 307 @repository.merge_extra_info(h)
308 308 @repository.save
309 309 @project.reload
310 310 assert_equal ["1234abcd", "abcd1234"], @repository.heads_from_branches_hash.sort
311 311 end
312 312
313 313 def test_latest_changesets
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 # with limit
319 319 changesets = @repository.latest_changesets('', 'master', 2)
320 320 assert_equal 2, changesets.size
321 321
322 322 # with path
323 323 changesets = @repository.latest_changesets('images', 'master')
324 324 assert_equal [
325 325 'deff712f05a90d96edbd70facc47d944be5897e3',
326 326 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
327 327 '7234cb2750b63f47bff735edc50a1c0a433c2518',
328 328 ], changesets.collect(&:revision)
329 329
330 330 changesets = @repository.latest_changesets('README', nil)
331 331 assert_equal [
332 332 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
333 333 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
334 334 '713f4944648826f558cf548222f813dabe7cbb04',
335 335 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
336 336 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
337 337 '7234cb2750b63f47bff735edc50a1c0a433c2518',
338 338 ], changesets.collect(&:revision)
339 339
340 340 # with path, revision and limit
341 341 changesets = @repository.latest_changesets('images', '899a15dba')
342 342 assert_equal [
343 343 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
344 344 '7234cb2750b63f47bff735edc50a1c0a433c2518',
345 345 ], changesets.collect(&:revision)
346 346
347 347 changesets = @repository.latest_changesets('images', '899a15dba', 1)
348 348 assert_equal [
349 349 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
350 350 ], changesets.collect(&:revision)
351 351
352 352 changesets = @repository.latest_changesets('README', '899a15dba')
353 353 assert_equal [
354 354 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
355 355 '7234cb2750b63f47bff735edc50a1c0a433c2518',
356 356 ], changesets.collect(&:revision)
357 357
358 358 changesets = @repository.latest_changesets('README', '899a15dba', 1)
359 359 assert_equal [
360 360 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
361 361 ], changesets.collect(&:revision)
362 362
363 363 # with path, tag and limit
364 364 changesets = @repository.latest_changesets('images', 'tag01.annotated')
365 365 assert_equal [
366 366 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
367 367 '7234cb2750b63f47bff735edc50a1c0a433c2518',
368 368 ], changesets.collect(&:revision)
369 369
370 370 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
371 371 assert_equal [
372 372 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
373 373 ], changesets.collect(&:revision)
374 374
375 375 changesets = @repository.latest_changesets('README', 'tag01.annotated')
376 376 assert_equal [
377 377 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
378 378 '7234cb2750b63f47bff735edc50a1c0a433c2518',
379 379 ], changesets.collect(&:revision)
380 380
381 381 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
382 382 assert_equal [
383 383 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
384 384 ], changesets.collect(&:revision)
385 385
386 386 # with path, branch and limit
387 387 changesets = @repository.latest_changesets('images', 'test_branch')
388 388 assert_equal [
389 389 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
390 390 '7234cb2750b63f47bff735edc50a1c0a433c2518',
391 391 ], changesets.collect(&:revision)
392 392
393 393 changesets = @repository.latest_changesets('images', 'test_branch', 1)
394 394 assert_equal [
395 395 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
396 396 ], changesets.collect(&:revision)
397 397
398 398 changesets = @repository.latest_changesets('README', 'test_branch')
399 399 assert_equal [
400 400 '713f4944648826f558cf548222f813dabe7cbb04',
401 401 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
402 402 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
403 403 '7234cb2750b63f47bff735edc50a1c0a433c2518',
404 404 ], changesets.collect(&:revision)
405 405
406 406 changesets = @repository.latest_changesets('README', 'test_branch', 2)
407 407 assert_equal [
408 408 '713f4944648826f558cf548222f813dabe7cbb04',
409 409 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
410 410 ], changesets.collect(&:revision)
411 411
412 412 if WINDOWS_PASS
413 413 puts WINDOWS_SKIP_STR
414 414 elsif JRUBY_SKIP
415 415 puts JRUBY_SKIP_STR
416 416 else
417 417 # latin-1 encoding path
418 418 changesets = @repository.latest_changesets(
419 419 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
420 420 assert_equal [
421 421 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
422 422 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
423 423 ], changesets.collect(&:revision)
424 424
425 425 changesets = @repository.latest_changesets(
426 426 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
427 427 assert_equal [
428 428 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
429 429 ], changesets.collect(&:revision)
430 430 end
431 431 end
432 432
433 433 def test_latest_changesets_latin_1_dir
434 434 if WINDOWS_PASS
435 435 puts WINDOWS_SKIP_STR
436 436 elsif JRUBY_SKIP
437 437 puts JRUBY_SKIP_STR
438 438 else
439 439 assert_equal 0, @repository.changesets.count
440 440 @repository.fetch_changesets
441 441 @project.reload
442 442 assert_equal NUM_REV, @repository.changesets.count
443 443 changesets = @repository.latest_changesets(
444 444 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
445 445 assert_equal [
446 446 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
447 447 ], changesets.collect(&:revision)
448 448 end
449 449 end
450 450
451 451 def test_find_changeset_by_name
452 452 assert_equal 0, @repository.changesets.count
453 453 @repository.fetch_changesets
454 454 @project.reload
455 455 assert_equal NUM_REV, @repository.changesets.count
456 456 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
457 457 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
458 458 @repository.find_changeset_by_name(r).revision
459 459 end
460 460 end
461 461
462 462 def test_find_changeset_by_empty_name
463 463 assert_equal 0, @repository.changesets.count
464 464 @repository.fetch_changesets
465 465 @project.reload
466 466 assert_equal NUM_REV, @repository.changesets.count
467 467 ['', ' ', nil].each do |r|
468 468 assert_nil @repository.find_changeset_by_name(r)
469 469 end
470 470 end
471 471
472 472 def test_identifier
473 473 assert_equal 0, @repository.changesets.count
474 474 @repository.fetch_changesets
475 475 @project.reload
476 476 assert_equal NUM_REV, @repository.changesets.count
477 477 c = @repository.changesets.find_by_revision(
478 478 '7234cb2750b63f47bff735edc50a1c0a433c2518')
479 479 assert_equal c.scmid, c.identifier
480 480 end
481 481
482 482 def test_format_identifier
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 c = @repository.changesets.find_by_revision(
488 488 '7234cb2750b63f47bff735edc50a1c0a433c2518')
489 489 assert_equal '7234cb27', c.format_identifier
490 490 end
491 491
492 492 def test_activities
493 493 c = Changeset.new(:repository => @repository,
494 494 :committed_on => Time.now,
495 495 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
496 496 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
497 497 :comments => 'test')
498 498 assert c.event_title.include?('abc7234c:')
499 499 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
500 500 end
501 501
502 502 def test_log_utf8
503 503 assert_equal 0, @repository.changesets.count
504 504 @repository.fetch_changesets
505 505 @project.reload
506 506 assert_equal NUM_REV, @repository.changesets.count
507 507 str_felix_hex = FELIX_HEX.dup
508 508 if str_felix_hex.respond_to?(:force_encoding)
509 509 str_felix_hex.force_encoding('UTF-8')
510 510 end
511 511 c = @repository.changesets.find_by_revision(
512 512 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
513 513 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
514 514 end
515 515
516 516 def test_previous
517 517 assert_equal 0, @repository.changesets.count
518 518 @repository.fetch_changesets
519 519 @project.reload
520 520 assert_equal NUM_REV, @repository.changesets.count
521 521 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
522 522 changeset = @repository.find_changeset_by_name(r1)
523 523 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
524 524 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
525 525 end
526 526 end
527 527 end
528 528
529 529 def test_previous_nil
530 530 assert_equal 0, @repository.changesets.count
531 531 @repository.fetch_changesets
532 532 @project.reload
533 533 assert_equal NUM_REV, @repository.changesets.count
534 534 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb275|.each do |r1|
535 535 changeset = @repository.find_changeset_by_name(r1)
536 536 assert_nil changeset.previous
537 537 end
538 538 end
539 539
540 540 def test_next
541 541 assert_equal 0, @repository.changesets.count
542 542 @repository.fetch_changesets
543 543 @project.reload
544 544 assert_equal NUM_REV, @repository.changesets.count
545 545 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
546 546 changeset = @repository.find_changeset_by_name(r2)
547 547 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
548 548 assert_equal @repository.find_changeset_by_name(r1), changeset.next
549 549 end
550 550 end
551 551 end
552 552
553 553 def test_next_nil
554 554 assert_equal 0, @repository.changesets.count
555 555 @repository.fetch_changesets
556 556 @project.reload
557 557 assert_equal NUM_REV, @repository.changesets.count
558 558 %w|2a682156a3b6e77a8bf9cd4590e8db757f3c6c78 2a682156a3b6e77a|.each do |r1|
559 559 changeset = @repository.find_changeset_by_name(r1)
560 560 assert_nil changeset.next
561 561 end
562 562 end
563 563 else
564 564 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
565 565 def test_fake; assert true end
566 566 end
567 567 end
General Comments 0
You need to be logged in to leave comments. Login now