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