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