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