##// END OF EJS Templates
scm: git: add test that diff type is saved in user preference (#10152)...
Toshi MARUYAMA -
r8640:af50c1e13e67
parent child
Show More
@@ -1,473 +1,493
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 = 21
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 137 get :show, :id => PRJ_ID, :path => ['images']
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 155 get :show, :id => PRJ_ID, :path => ['images'],
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 166 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
167 167 assert_response :success
168 168 assert_template 'changes'
169 169 assert_tag :tag => 'h2', :content => 'edit.png'
170 170 end
171 171
172 172 def test_entry_show
173 173 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
174 174 assert_response :success
175 175 assert_template 'entry'
176 176 # Line 19
177 177 assert_tag :tag => 'th',
178 178 :content => '11',
179 179 :attributes => { :class => 'line-num' },
180 180 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
181 181 end
182 182
183 183 def test_entry_show_latin_1
184 184 if @ruby19_non_utf8_pass
185 185 puts_ruby19_non_utf8_pass()
186 186 elsif JRUBY_SKIP
187 187 puts JRUBY_SKIP_STR
188 188 else
189 189 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
190 190 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
191 191 get :entry, :id => PRJ_ID,
192 192 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
193 193 assert_response :success
194 194 assert_template 'entry'
195 195 assert_tag :tag => 'th',
196 196 :content => '1',
197 197 :attributes => { :class => 'line-num' },
198 198 :sibling => { :tag => 'td',
199 199 :content => /test-#{@char_1}.txt/ }
200 200 end
201 201 end
202 202 end
203 203 end
204 204
205 205 def test_entry_download
206 206 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
207 207 :format => 'raw'
208 208 assert_response :success
209 209 # File content
210 210 assert @response.body.include?('WITHOUT ANY WARRANTY')
211 211 end
212 212
213 213 def test_directory_entry
214 214 get :entry, :id => PRJ_ID, :path => ['sources']
215 215 assert_response :success
216 216 assert_template 'show'
217 217 assert_not_nil assigns(:entry)
218 218 assert_equal 'sources', assigns(:entry).name
219 219 end
220 220
221 221 def test_diff
222 222 assert_equal 0, @repository.changesets.count
223 223 @repository.fetch_changesets
224 224 @project.reload
225 225 assert_equal NUM_REV, @repository.changesets.count
226 226 # Full diff of changeset 2f9c0091
227 227 ['inline', 'sbs'].each do |dt|
228 228 get :diff,
229 229 :id => PRJ_ID,
230 230 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
231 231 :type => dt
232 232 assert_response :success
233 233 assert_template 'diff'
234 234 # Line 22 removed
235 235 assert_tag :tag => 'th',
236 236 :content => /22/,
237 237 :sibling => { :tag => 'td',
238 238 :attributes => { :class => /diff_out/ },
239 239 :content => /def remove/ }
240 240 assert_tag :tag => 'h2', :content => /2f9c0091/
241 241 end
242 242 end
243 243
244 244 def test_diff_truncated
245 245 assert_equal 0, @repository.changesets.count
246 246 @repository.fetch_changesets
247 247 @project.reload
248 248 assert_equal NUM_REV, @repository.changesets.count
249 249 Setting.diff_max_lines_displayed = 5
250 250
251 251 # Truncated diff of changeset 2f9c0091
252 252 with_cache do
253 253 get :diff, :id => PRJ_ID, :type => 'inline',
254 254 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
255 255 assert_response :success
256 256 assert @response.body.include?("... This diff was truncated")
257 257
258 258 Setting.default_language = 'fr'
259 259 get :diff, :id => PRJ_ID, :type => 'inline',
260 260 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
261 261 assert_response :success
262 262 assert ! @response.body.include?("... This diff was truncated")
263 263 assert @response.body.include?("... Ce diff")
264 264 end
265 265 end
266 266
267 267 def test_diff_two_revs
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 ['inline', 'sbs'].each do |dt|
273 273 get :diff,
274 274 :id => PRJ_ID,
275 275 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
276 276 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
277 277 :type => dt
278 278 assert_response :success
279 279 assert_template 'diff'
280 280 diff = assigns(:diff)
281 281 assert_not_nil diff
282 282 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
283 283 end
284 284 end
285 285
286 286 def test_diff_latin_1
287 287 if @ruby19_non_utf8_pass
288 288 puts_ruby19_non_utf8_pass()
289 289 else
290 290 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
291 291 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
292 292 ['inline', 'sbs'].each do |dt|
293 293 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
294 294 assert_response :success
295 295 assert_template 'diff'
296 296 assert_tag :tag => 'thead',
297 297 :descendant => {
298 298 :tag => 'th',
299 299 :attributes => { :class => 'filename' } ,
300 300 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
301 301 },
302 302 :sibling => {
303 303 :tag => 'tbody',
304 304 :descendant => {
305 305 :tag => 'td',
306 306 :attributes => { :class => /diff_in/ },
307 307 :content => /test-#{@char_1}.txt/
308 308 }
309 309 }
310 310 end
311 311 end
312 312 end
313 313 end
314 314 end
315 315
316 def test_save_diff_type
317 @request.session[:user_id] = 1 # admin
318 user = User.find(1)
319 get :diff,
320 :id => PRJ_ID,
321 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
322 assert_response :success
323 assert_template 'diff'
324 user.reload
325 assert_equal "inline", user.pref[:diff_type]
326 get :diff,
327 :id => PRJ_ID,
328 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
329 :type => 'sbs'
330 assert_response :success
331 assert_template 'diff'
332 user.reload
333 assert_equal "sbs", user.pref[:diff_type]
334 end
335
316 336 def test_annotate
317 337 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
318 338 assert_response :success
319 339 assert_template 'annotate'
320 340 # Line 24, changeset 2f9c0091
321 341 assert_tag :tag => 'th', :content => '24',
322 342 :sibling => {
323 343 :tag => 'td',
324 344 :child => {
325 345 :tag => 'a',
326 346 :content => /2f9c0091/
327 347 }
328 348 }
329 349 assert_tag :tag => 'th', :content => '24',
330 350 :sibling => { :tag => 'td', :content => /jsmith/ }
331 351 assert_tag :tag => 'th', :content => '24',
332 352 :sibling => {
333 353 :tag => 'td',
334 354 :child => {
335 355 :tag => 'a',
336 356 :content => /2f9c0091/
337 357 }
338 358 }
339 359 assert_tag :tag => 'th', :content => '24',
340 360 :sibling => { :tag => 'td', :content => /watcher =/ }
341 361 end
342 362
343 363 def test_annotate_at_given_revision
344 364 assert_equal 0, @repository.changesets.count
345 365 @repository.fetch_changesets
346 366 @project.reload
347 367 assert_equal NUM_REV, @repository.changesets.count
348 368 get :annotate, :id => PRJ_ID, :rev => 'deff7',
349 369 :path => ['sources', 'watchers_controller.rb']
350 370 assert_response :success
351 371 assert_template 'annotate'
352 372 assert_tag :tag => 'h2', :content => /@ deff712f/
353 373 end
354 374
355 375 def test_annotate_binary_file
356 376 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
357 377 assert_response 500
358 378 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
359 379 :content => /cannot be annotated/
360 380 end
361 381
362 382 def test_annotate_error_when_too_big
363 383 with_settings :file_max_size_displayed => 1 do
364 384 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], :rev => 'deff712f'
365 385 assert_response 500
366 386 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
367 387 :content => /exceeds the maximum text file size/
368 388
369 389 get :annotate, :id => PRJ_ID, :path => ['README'], :rev => '7234cb2'
370 390 assert_response :success
371 391 assert_template 'annotate'
372 392 end
373 393 end
374 394
375 395 def test_annotate_latin_1
376 396 if @ruby19_non_utf8_pass
377 397 puts_ruby19_non_utf8_pass()
378 398 elsif JRUBY_SKIP
379 399 puts JRUBY_SKIP_STR
380 400 else
381 401 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
382 402 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
383 403 get :annotate, :id => PRJ_ID,
384 404 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
385 405 assert_tag :tag => 'th',
386 406 :content => '1',
387 407 :attributes => { :class => 'line-num' },
388 408 :sibling => { :tag => 'td',
389 409 :content => /test-#{@char_1}.txt/ }
390 410 end
391 411 end
392 412 end
393 413 end
394 414
395 415 def test_revision
396 416 assert_equal 0, @repository.changesets.count
397 417 @repository.fetch_changesets
398 418 @project.reload
399 419 assert_equal NUM_REV, @repository.changesets.count
400 420 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
401 421 get :revision, :id => PRJ_ID, :rev => r
402 422 assert_response :success
403 423 assert_template 'revision'
404 424 end
405 425 end
406 426
407 427 def test_empty_revision
408 428 assert_equal 0, @repository.changesets.count
409 429 @repository.fetch_changesets
410 430 @project.reload
411 431 assert_equal NUM_REV, @repository.changesets.count
412 432 ['', ' ', nil].each do |r|
413 433 get :revision, :id => PRJ_ID, :rev => r
414 434 assert_response 404
415 435 assert_error_tag :content => /was not found/
416 436 end
417 437 end
418 438
419 439 def test_destroy_valid_repository
420 440 @request.session[:user_id] = 1 # admin
421 441 assert_equal 0, @repository.changesets.count
422 442 @repository.fetch_changesets
423 443 @project.reload
424 444 assert_equal NUM_REV, @repository.changesets.count
425 445
426 446 assert_difference 'Repository.count', -1 do
427 447 delete :destroy, :id => @repository.id
428 448 end
429 449 assert_response 302
430 450 @project.reload
431 451 assert_nil @project.repository
432 452 end
433 453
434 454 def test_destroy_invalid_repository
435 455 @request.session[:user_id] = 1 # admin
436 456 @project.repository.destroy
437 457 @repository = Repository::Git.create!(
438 458 :project => @project,
439 459 :url => "/invalid",
440 460 :path_encoding => 'ISO-8859-1'
441 461 )
442 462 @repository.fetch_changesets
443 463 @repository.reload
444 464 assert_equal 0, @repository.changesets.count
445 465
446 466 assert_difference 'Repository.count', -1 do
447 467 delete :destroy, :id => @repository.id
448 468 end
449 469 assert_response 302
450 470 @project.reload
451 471 assert_nil @project.repository
452 472 end
453 473
454 474 private
455 475
456 476 def puts_ruby19_non_utf8_pass
457 477 puts "TODO: This test fails in Ruby 1.9 " +
458 478 "and Encoding.default_external is not UTF-8. " +
459 479 "Current value is '#{Encoding.default_external.to_s}'"
460 480 end
461 481 else
462 482 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
463 483 def test_fake; assert true end
464 484 end
465 485
466 486 private
467 487 def with_cache(&block)
468 488 before = ActionController::Base.perform_caching
469 489 ActionController::Base.perform_caching = true
470 490 block.call
471 491 ActionController::Base.perform_caching = before
472 492 end
473 493 end
General Comments 0
You need to be logged in to leave comments. Login now