##// END OF EJS Templates
scm: git: use with_settings at test_diff_truncated of functional test (#11752)...
Toshi MARUYAMA -
r10069:43add0d30674
parent child
Show More
@@ -1,560 +1,560
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 3 #
4 4 # This program is free software; you can redistribute it and/or
5 5 # modify it under the terms of the GNU General Public License
6 6 # as published by the Free Software Foundation; either version 2
7 7 # of the License, or (at your option) any later version.
8 8 #
9 9 # This program is distributed in the hope that it will be useful,
10 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 12 # GNU General Public License for more details.
13 13 #
14 14 # You should have received a copy of the GNU General Public License
15 15 # along with this program; if not, write to the Free Software
16 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 18 require File.expand_path('../../test_helper', __FILE__)
19 19
20 20 class RepositoriesGitControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
27 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
28 28 PRJ_ID = 3
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 NUM_REV = 28
31 31
32 32 ## Git, Mercurial and CVS path encodings are binary.
33 33 ## Subversion supports URL encoding for path.
34 34 ## Redmine Mercurial adapter and extension use URL encoding.
35 35 ## Git accepts only binary path in command line parameter.
36 36 ## So, there is no way to use binary command line parameter in JRuby.
37 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
38 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
39 39
40 40 def setup
41 41 @ruby19_non_utf8_pass =
42 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
43 43
44 44 User.current = nil
45 45 @project = Project.find(PRJ_ID)
46 46 @repository = Repository::Git.create(
47 47 :project => @project,
48 48 :url => REPOSITORY_PATH,
49 49 :path_encoding => 'ISO-8859-1'
50 50 )
51 51 assert @repository
52 52 @char_1 = CHAR_1_HEX.dup
53 53 if @char_1.respond_to?(:force_encoding)
54 54 @char_1.force_encoding('UTF-8')
55 55 end
56 56
57 57 Setting.default_language = 'en'
58 58 end
59 59
60 60 def test_create_and_update
61 61 @request.session[:user_id] = 1
62 62 assert_difference 'Repository.count' do
63 63 post :create, :project_id => 'subproject1',
64 64 :repository_scm => 'Git',
65 65 :repository => {
66 66 :url => '/test',
67 67 :is_default => '0',
68 68 :identifier => 'test-create',
69 69 :extra_report_last_commit => '1',
70 70 }
71 71 end
72 72 assert_response 302
73 73 repository = Repository.first(:order => 'id DESC')
74 74 assert_kind_of Repository::Git, repository
75 75 assert_equal '/test', repository.url
76 76 assert_equal true, repository.extra_report_last_commit
77 77
78 78 put :update, :id => repository.id,
79 79 :repository => {
80 80 :extra_report_last_commit => '0'
81 81 }
82 82 assert_response 302
83 83 repo2 = Repository.find(repository.id)
84 84 assert_equal false, repo2.extra_report_last_commit
85 85 end
86 86
87 87 if File.directory?(REPOSITORY_PATH)
88 88 ## Ruby uses ANSI api to fork a process on Windows.
89 89 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
90 90 ## and these are incompatible with ASCII.
91 91 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
92 92 ## http://code.google.com/p/msysgit/issues/detail?id=80
93 93 ## So, Latin-1 path tests fail on Japanese Windows
94 94 WINDOWS_PASS = (Redmine::Platform.mswin? &&
95 95 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
96 96 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
97 97
98 98 def test_get_new
99 99 @request.session[:user_id] = 1
100 100 @project.repository.destroy
101 101 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
102 102 assert_response :success
103 103 assert_template 'new'
104 104 assert_kind_of Repository::Git, assigns(:repository)
105 105 assert assigns(:repository).new_record?
106 106 end
107 107
108 108 def test_browse_root
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113
114 114 get :show, :id => PRJ_ID
115 115 assert_response :success
116 116 assert_template 'show'
117 117 assert_not_nil assigns(:entries)
118 118 assert_equal 9, assigns(:entries).size
119 119 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
120 120 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
121 121 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
122 122 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
123 123 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
124 124 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
125 125 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
126 126 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
127 127 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
128 128 assert_not_nil assigns(:changesets)
129 129 assert assigns(:changesets).size > 0
130 130 end
131 131
132 132 def test_browse_branch
133 133 assert_equal 0, @repository.changesets.count
134 134 @repository.fetch_changesets
135 135 @project.reload
136 136 assert_equal NUM_REV, @repository.changesets.count
137 137 get :show, :id => PRJ_ID, :rev => 'test_branch'
138 138 assert_response :success
139 139 assert_template 'show'
140 140 assert_not_nil assigns(:entries)
141 141 assert_equal 4, assigns(:entries).size
142 142 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
143 143 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
144 144 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
145 145 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
146 146 assert_not_nil assigns(:changesets)
147 147 assert assigns(:changesets).size > 0
148 148 end
149 149
150 150 def test_browse_tag
151 151 assert_equal 0, @repository.changesets.count
152 152 @repository.fetch_changesets
153 153 @project.reload
154 154 assert_equal NUM_REV, @repository.changesets.count
155 155 [
156 156 "tag00.lightweight",
157 157 "tag01.annotated",
158 158 ].each do |t1|
159 159 get :show, :id => PRJ_ID, :rev => t1
160 160 assert_response :success
161 161 assert_template 'show'
162 162 assert_not_nil assigns(:entries)
163 163 assert assigns(:entries).size > 0
164 164 assert_not_nil assigns(:changesets)
165 165 assert assigns(:changesets).size > 0
166 166 end
167 167 end
168 168
169 169 def test_browse_directory
170 170 assert_equal 0, @repository.changesets.count
171 171 @repository.fetch_changesets
172 172 @project.reload
173 173 assert_equal NUM_REV, @repository.changesets.count
174 174 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
175 175 assert_response :success
176 176 assert_template 'show'
177 177 assert_not_nil assigns(:entries)
178 178 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
179 179 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
180 180 assert_not_nil entry
181 181 assert_equal 'file', entry.kind
182 182 assert_equal 'images/edit.png', entry.path
183 183 assert_not_nil assigns(:changesets)
184 184 assert assigns(:changesets).size > 0
185 185 end
186 186
187 187 def test_browse_at_given_revision
188 188 assert_equal 0, @repository.changesets.count
189 189 @repository.fetch_changesets
190 190 @project.reload
191 191 assert_equal NUM_REV, @repository.changesets.count
192 192 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
193 193 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201
202 202 def test_changes
203 203 get :changes, :id => PRJ_ID,
204 204 :path => repository_path_hash(['images', 'edit.png'])[:param]
205 205 assert_response :success
206 206 assert_template 'changes'
207 207 assert_tag :tag => 'h2', :content => 'edit.png'
208 208 end
209 209
210 210 def test_entry_show
211 211 get :entry, :id => PRJ_ID,
212 212 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
213 213 assert_response :success
214 214 assert_template 'entry'
215 215 # Line 19
216 216 assert_tag :tag => 'th',
217 217 :content => '11',
218 218 :attributes => { :class => 'line-num' },
219 219 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
220 220 end
221 221
222 222 def test_entry_show_latin_1
223 223 if @ruby19_non_utf8_pass
224 224 puts_ruby19_non_utf8_pass()
225 225 elsif WINDOWS_PASS
226 226 puts WINDOWS_SKIP_STR
227 227 elsif JRUBY_SKIP
228 228 puts JRUBY_SKIP_STR
229 229 else
230 230 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 231 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
232 232 get :entry, :id => PRJ_ID,
233 233 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
234 234 :rev => r1
235 235 assert_response :success
236 236 assert_template 'entry'
237 237 assert_tag :tag => 'th',
238 238 :content => '1',
239 239 :attributes => { :class => 'line-num' },
240 240 :sibling => { :tag => 'td',
241 241 :content => /test-#{@char_1}.txt/ }
242 242 end
243 243 end
244 244 end
245 245 end
246 246
247 247 def test_entry_download
248 248 get :entry, :id => PRJ_ID,
249 249 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
250 250 :format => 'raw'
251 251 assert_response :success
252 252 # File content
253 253 assert @response.body.include?('WITHOUT ANY WARRANTY')
254 254 end
255 255
256 256 def test_directory_entry
257 257 get :entry, :id => PRJ_ID,
258 258 :path => repository_path_hash(['sources'])[:param]
259 259 assert_response :success
260 260 assert_template 'show'
261 261 assert_not_nil assigns(:entry)
262 262 assert_equal 'sources', assigns(:entry).name
263 263 end
264 264
265 265 def test_diff
266 266 assert_equal 0, @repository.changesets.count
267 267 @repository.fetch_changesets
268 268 @project.reload
269 269 assert_equal NUM_REV, @repository.changesets.count
270 270 # Full diff of changeset 2f9c0091
271 271 ['inline', 'sbs'].each do |dt|
272 272 get :diff,
273 273 :id => PRJ_ID,
274 274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
275 275 :type => dt
276 276 assert_response :success
277 277 assert_template 'diff'
278 278 # Line 22 removed
279 279 assert_tag :tag => 'th',
280 280 :content => /22/,
281 281 :sibling => { :tag => 'td',
282 282 :attributes => { :class => /diff_out/ },
283 283 :content => /def remove/ }
284 284 assert_tag :tag => 'h2', :content => /2f9c0091/
285 285 end
286 286 end
287 287
288 288 def test_diff_with_rev_and_path
289 289 assert_equal 0, @repository.changesets.count
290 290 @repository.fetch_changesets
291 291 @project.reload
292 292 assert_equal NUM_REV, @repository.changesets.count
293 293 with_settings :diff_max_lines_displayed => 1000 do
294 294 # Full diff of changeset 2f9c0091
295 295 ['inline', 'sbs'].each do |dt|
296 296 get :diff,
297 297 :id => PRJ_ID,
298 298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
299 299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
300 300 :type => dt
301 301 assert_response :success
302 302 assert_template 'diff'
303 303 # Line 22 removed
304 304 assert_tag :tag => 'th',
305 305 :content => '22',
306 306 :sibling => { :tag => 'td',
307 307 :attributes => { :class => /diff_out/ },
308 308 :content => /def remove/ }
309 309 assert_tag :tag => 'h2', :content => /2f9c0091/
310 310 end
311 311 end
312 312 end
313 313
314 314 def test_diff_truncated
315 315 assert_equal 0, @repository.changesets.count
316 316 @repository.fetch_changesets
317 317 @project.reload
318 318 assert_equal NUM_REV, @repository.changesets.count
319 319
320 320 with_settings :diff_max_lines_displayed => 5 do
321 321 # Truncated diff of changeset 2f9c0091
322 322 with_cache do
323 323 get :diff, :id => PRJ_ID, :type => 'inline',
324 324 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
325 325 assert_response :success
326 326 assert @response.body.include?("... This diff was truncated")
327
328 Setting.default_language = 'fr'
327 with_settings :default_language => 'fr' do
329 328 get :diff, :id => PRJ_ID, :type => 'inline',
330 329 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
331 330 assert_response :success
332 331 assert ! @response.body.include?("... This diff was truncated")
333 332 assert @response.body.include?("... Ce diff")
334 333 end
335 334 end
336 335 end
336 end
337 337
338 338 def test_diff_two_revs
339 339 assert_equal 0, @repository.changesets.count
340 340 @repository.fetch_changesets
341 341 @project.reload
342 342 assert_equal NUM_REV, @repository.changesets.count
343 343 ['inline', 'sbs'].each do |dt|
344 344 get :diff,
345 345 :id => PRJ_ID,
346 346 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
347 347 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
348 348 :type => dt
349 349 assert_response :success
350 350 assert_template 'diff'
351 351 diff = assigns(:diff)
352 352 assert_not_nil diff
353 353 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
354 354 end
355 355 end
356 356
357 357 def test_diff_latin_1
358 358 if @ruby19_non_utf8_pass
359 359 puts_ruby19_non_utf8_pass()
360 360 else
361 361 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
362 362 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
363 363 ['inline', 'sbs'].each do |dt|
364 364 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
365 365 assert_response :success
366 366 assert_template 'diff'
367 367 assert_tag :tag => 'thead',
368 368 :descendant => {
369 369 :tag => 'th',
370 370 :attributes => { :class => 'filename' } ,
371 371 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
372 372 },
373 373 :sibling => {
374 374 :tag => 'tbody',
375 375 :descendant => {
376 376 :tag => 'td',
377 377 :attributes => { :class => /diff_in/ },
378 378 :content => /test-#{@char_1}.txt/
379 379 }
380 380 }
381 381 end
382 382 end
383 383 end
384 384 end
385 385 end
386 386
387 387 def test_save_diff_type
388 388 @request.session[:user_id] = 1 # admin
389 389 user = User.find(1)
390 390 get :diff,
391 391 :id => PRJ_ID,
392 392 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
393 393 assert_response :success
394 394 assert_template 'diff'
395 395 user.reload
396 396 assert_equal "inline", user.pref[:diff_type]
397 397 get :diff,
398 398 :id => PRJ_ID,
399 399 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
400 400 :type => 'sbs'
401 401 assert_response :success
402 402 assert_template 'diff'
403 403 user.reload
404 404 assert_equal "sbs", user.pref[:diff_type]
405 405 end
406 406
407 407 def test_annotate
408 408 get :annotate, :id => PRJ_ID,
409 409 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
410 410 assert_response :success
411 411 assert_template 'annotate'
412 412
413 413 # Line 23, changeset 2f9c0091
414 414 assert_select 'tr' do
415 415 assert_select 'th.line-num', :text => '23'
416 416 assert_select 'td.revision', :text => /2f9c0091/
417 417 assert_select 'td.author', :text => 'jsmith'
418 418 assert_select 'td', :text => /remove_watcher/
419 419 end
420 420 end
421 421
422 422 def test_annotate_at_given_revision
423 423 assert_equal 0, @repository.changesets.count
424 424 @repository.fetch_changesets
425 425 @project.reload
426 426 assert_equal NUM_REV, @repository.changesets.count
427 427 get :annotate, :id => PRJ_ID, :rev => 'deff7',
428 428 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
429 429 assert_response :success
430 430 assert_template 'annotate'
431 431 assert_tag :tag => 'h2', :content => /@ deff712f/
432 432 end
433 433
434 434 def test_annotate_binary_file
435 435 get :annotate, :id => PRJ_ID,
436 436 :path => repository_path_hash(['images', 'edit.png'])[:param]
437 437 assert_response 500
438 438 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
439 439 :content => /cannot be annotated/
440 440 end
441 441
442 442 def test_annotate_error_when_too_big
443 443 with_settings :file_max_size_displayed => 1 do
444 444 get :annotate, :id => PRJ_ID,
445 445 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
446 446 :rev => 'deff712f'
447 447 assert_response 500
448 448 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
449 449 :content => /exceeds the maximum text file size/
450 450
451 451 get :annotate, :id => PRJ_ID,
452 452 :path => repository_path_hash(['README'])[:param],
453 453 :rev => '7234cb2'
454 454 assert_response :success
455 455 assert_template 'annotate'
456 456 end
457 457 end
458 458
459 459 def test_annotate_latin_1
460 460 if @ruby19_non_utf8_pass
461 461 puts_ruby19_non_utf8_pass()
462 462 elsif WINDOWS_PASS
463 463 puts WINDOWS_SKIP_STR
464 464 elsif JRUBY_SKIP
465 465 puts JRUBY_SKIP_STR
466 466 else
467 467 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
468 468 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
469 469 get :annotate, :id => PRJ_ID,
470 470 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
471 471 :rev => r1
472 472 assert_tag :tag => 'th',
473 473 :content => '1',
474 474 :attributes => { :class => 'line-num' },
475 475 :sibling => { :tag => 'td',
476 476 :content => /test-#{@char_1}.txt/ }
477 477 end
478 478 end
479 479 end
480 480 end
481 481
482 482 def test_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 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
488 488 get :revision, :id => PRJ_ID, :rev => r
489 489 assert_response :success
490 490 assert_template 'revision'
491 491 end
492 492 end
493 493
494 494 def test_empty_revision
495 495 assert_equal 0, @repository.changesets.count
496 496 @repository.fetch_changesets
497 497 @project.reload
498 498 assert_equal NUM_REV, @repository.changesets.count
499 499 ['', ' ', nil].each do |r|
500 500 get :revision, :id => PRJ_ID, :rev => r
501 501 assert_response 404
502 502 assert_error_tag :content => /was not found/
503 503 end
504 504 end
505 505
506 506 def test_destroy_valid_repository
507 507 @request.session[:user_id] = 1 # admin
508 508 assert_equal 0, @repository.changesets.count
509 509 @repository.fetch_changesets
510 510 @project.reload
511 511 assert_equal NUM_REV, @repository.changesets.count
512 512
513 513 assert_difference 'Repository.count', -1 do
514 514 delete :destroy, :id => @repository.id
515 515 end
516 516 assert_response 302
517 517 @project.reload
518 518 assert_nil @project.repository
519 519 end
520 520
521 521 def test_destroy_invalid_repository
522 522 @request.session[:user_id] = 1 # admin
523 523 @project.repository.destroy
524 524 @repository = Repository::Git.create!(
525 525 :project => @project,
526 526 :url => "/invalid",
527 527 :path_encoding => 'ISO-8859-1'
528 528 )
529 529 @repository.fetch_changesets
530 530 @repository.reload
531 531 assert_equal 0, @repository.changesets.count
532 532
533 533 assert_difference 'Repository.count', -1 do
534 534 delete :destroy, :id => @repository.id
535 535 end
536 536 assert_response 302
537 537 @project.reload
538 538 assert_nil @project.repository
539 539 end
540 540
541 541 private
542 542
543 543 def puts_ruby19_non_utf8_pass
544 544 puts "TODO: This test fails in Ruby 1.9 " +
545 545 "and Encoding.default_external is not UTF-8. " +
546 546 "Current value is '#{Encoding.default_external.to_s}'"
547 547 end
548 548 else
549 549 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
550 550 def test_fake; assert true end
551 551 end
552 552
553 553 private
554 554 def with_cache(&block)
555 555 before = ActionController::Base.perform_caching
556 556 ActionController::Base.perform_caching = true
557 557 block.call
558 558 ActionController::Base.perform_caching = before
559 559 end
560 560 end
General Comments 0
You need to be logged in to leave comments. Login now