##// END OF EJS Templates
Rails3: scm: mercurial: fix error of test_diff at functional test...
Toshi MARUYAMA -
r7091:321fac266890
parent child
Show More
@@ -1,496 +1,498
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 require 'repositories_controller'
20 20
21 21 # Re-raise errors caught by the controller.
22 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
24 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles,
26 26 :repositories, :enabled_modules
27 27
28 28 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
29 29 CHAR_1_HEX = "\xc3\x9c"
30 30 PRJ_ID = 3
31 31 NUM_REV = 29
32 32
33 33 ruby19_non_utf8_pass =
34 34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
35 35
36 36 def setup
37 37 @controller = RepositoriesController.new
38 38 @request = ActionController::TestRequest.new
39 39 @response = ActionController::TestResponse.new
40 40 User.current = nil
41 41 @project = Project.find(PRJ_ID)
42 42 @repository = Repository::Mercurial.create(
43 43 :project => @project,
44 44 :url => REPOSITORY_PATH,
45 45 :path_encoding => 'ISO-8859-1'
46 46 )
47 47 assert @repository
48 48 @diff_c_support = true
49 49 @char_1 = CHAR_1_HEX.dup
50 50 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
51 51 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
52 52 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
53 53 if @char_1.respond_to?(:force_encoding)
54 54 @char_1.force_encoding('UTF-8')
55 55 @tag_char_1.force_encoding('UTF-8')
56 56 @branch_char_0.force_encoding('UTF-8')
57 57 @branch_char_1.force_encoding('UTF-8')
58 58 end
59 59 end
60 60
61 61 if ruby19_non_utf8_pass
62 62 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
63 63 "and Encoding.default_external is not UTF-8. " +
64 64 "Current value is '#{Encoding.default_external.to_s}'"
65 65 def test_fake; assert true end
66 66 elsif File.directory?(REPOSITORY_PATH)
67 67 def test_show_root
68 68 assert_equal 0, @repository.changesets.count
69 69 @repository.fetch_changesets
70 70 @project.reload
71 71 assert_equal NUM_REV, @repository.changesets.count
72 72 get :show, :id => PRJ_ID
73 73 assert_response :success
74 74 assert_template 'show'
75 75 assert_not_nil assigns(:entries)
76 76 assert_equal 4, assigns(:entries).size
77 77 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
78 78 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
79 79 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
80 80 assert_not_nil assigns(:changesets)
81 81 assert assigns(:changesets).size > 0
82 82 end
83 83
84 84 def test_show_directory
85 85 assert_equal 0, @repository.changesets.count
86 86 @repository.fetch_changesets
87 87 @project.reload
88 88 assert_equal NUM_REV, @repository.changesets.count
89 89 get :show, :id => PRJ_ID, :path => ['images']
90 90 assert_response :success
91 91 assert_template 'show'
92 92 assert_not_nil assigns(:entries)
93 93 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
94 94 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
95 95 assert_not_nil entry
96 96 assert_equal 'file', entry.kind
97 97 assert_equal 'images/edit.png', entry.path
98 98 assert_not_nil assigns(:changesets)
99 99 assert assigns(:changesets).size > 0
100 100 end
101 101
102 102 def test_show_at_given_revision
103 103 assert_equal 0, @repository.changesets.count
104 104 @repository.fetch_changesets
105 105 @project.reload
106 106 assert_equal NUM_REV, @repository.changesets.count
107 107 [0, '0', '0885933ad4f6'].each do |r1|
108 108 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
109 109 assert_response :success
110 110 assert_template 'show'
111 111 assert_not_nil assigns(:entries)
112 112 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
113 113 assert_not_nil assigns(:changesets)
114 114 assert assigns(:changesets).size > 0
115 115 end
116 116 end
117 117
118 118 def test_show_directory_sql_escape_percent
119 119 assert_equal 0, @repository.changesets.count
120 120 @repository.fetch_changesets
121 121 @project.reload
122 122 assert_equal NUM_REV, @repository.changesets.count
123 123 [13, '13', '3a330eb32958'].each do |r1|
124 124 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
125 125 :rev => r1
126 126 assert_response :success
127 127 assert_template 'show'
128 128
129 129 assert_not_nil assigns(:entries)
130 130 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
131 131 assigns(:entries).collect(&:name)
132 132 changesets = assigns(:changesets)
133 133 assert_not_nil changesets
134 134 assert assigns(:changesets).size > 0
135 135 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
136 136 end
137 137 end
138 138
139 139 def test_show_directory_latin_1_path
140 140 assert_equal 0, @repository.changesets.count
141 141 @repository.fetch_changesets
142 142 @project.reload
143 143 assert_equal NUM_REV, @repository.changesets.count
144 144 [21, '21', 'adf805632193'].each do |r1|
145 145 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
146 146 assert_response :success
147 147 assert_template 'show'
148 148
149 149 assert_not_nil assigns(:entries)
150 150 assert_equal ["make-latin-1-file.rb",
151 151 "test-#{@char_1}-1.txt",
152 152 "test-#{@char_1}-2.txt",
153 153 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
154 154 changesets = assigns(:changesets)
155 155 assert_not_nil changesets
156 156 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
157 157 end
158 158 end
159 159
160 160 def test_show_branch
161 161 assert_equal 0, @repository.changesets.count
162 162 @repository.fetch_changesets
163 163 @project.reload
164 164 assert_equal NUM_REV, @repository.changesets.count
165 165 [
166 166 'default',
167 167 @branch_char_1,
168 168 'branch (1)[2]&,%.-3_4',
169 169 @branch_char_0,
170 170 'test_branch.latin-1',
171 171 'test-branch-00',
172 172 ].each do |bra|
173 173 get :show, :id => PRJ_ID, :rev => bra
174 174 assert_response :success
175 175 assert_template 'show'
176 176 assert_not_nil assigns(:entries)
177 177 assert assigns(:entries).size > 0
178 178 assert_not_nil assigns(:changesets)
179 179 assert assigns(:changesets).size > 0
180 180 end
181 181 end
182 182
183 183 def test_show_tag
184 184 assert_equal 0, @repository.changesets.count
185 185 @repository.fetch_changesets
186 186 @project.reload
187 187 assert_equal NUM_REV, @repository.changesets.count
188 188 [
189 189 @tag_char_1,
190 190 'tag_test.00',
191 191 'tag-init-revision'
192 192 ].each do |tag|
193 193 get :show, :id => PRJ_ID, :rev => tag
194 194 assert_response :success
195 195 assert_template 'show'
196 196 assert_not_nil assigns(:entries)
197 197 assert assigns(:entries).size > 0
198 198 assert_not_nil assigns(:changesets)
199 199 assert assigns(:changesets).size > 0
200 200 end
201 201 end
202 202
203 203 def test_changes
204 204 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
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, :path => ['sources', 'watchers_controller.rb']
212 212 assert_response :success
213 213 assert_template 'entry'
214 214 # Line 10
215 215 assert_tag :tag => 'th',
216 216 :content => '10',
217 217 :attributes => { :class => 'line-num' },
218 218 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
219 219 end
220 220
221 221 def test_entry_show_latin_1_path
222 222 [21, '21', 'adf805632193'].each do |r1|
223 223 get :entry, :id => PRJ_ID,
224 224 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
225 225 assert_response :success
226 226 assert_template 'entry'
227 227 assert_tag :tag => 'th',
228 228 :content => '1',
229 229 :attributes => { :class => 'line-num' },
230 230 :sibling => { :tag => 'td',
231 231 :content => /Mercurial is a distributed version control system/ }
232 232 end
233 233 end
234 234
235 235 def test_entry_show_latin_1_contents
236 236 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
237 237 [27, '27', '7bbf4c738e71'].each do |r1|
238 238 get :entry, :id => PRJ_ID,
239 239 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
240 240 assert_response :success
241 241 assert_template 'entry'
242 242 assert_tag :tag => 'th',
243 243 :content => '1',
244 244 :attributes => { :class => 'line-num' },
245 245 :sibling => { :tag => 'td',
246 246 :content => /test-#{@char_1}.txt/ }
247 247 end
248 248 end
249 249 end
250 250
251 251 def test_entry_download
252 252 get :entry, :id => PRJ_ID,
253 253 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
254 254 assert_response :success
255 255 # File content
256 256 assert @response.body.include?('WITHOUT ANY WARRANTY')
257 257 end
258 258
259 259 def test_entry_binary_force_download
260 260 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
261 261 assert_response :success
262 262 assert_equal 'image/png', @response.content_type
263 263 end
264 264
265 265 def test_directory_entry
266 266 get :entry, :id => PRJ_ID, :path => ['sources']
267 267 assert_response :success
268 268 assert_template 'show'
269 269 assert_not_nil assigns(:entry)
270 270 assert_equal 'sources', assigns(:entry).name
271 271 end
272 272
273 273 def test_diff
274 assert_equal 0, @repository.changesets.count
274 275 @repository.fetch_changesets
275 @repository.reload
276 @project.reload
277 assert_equal NUM_REV, @repository.changesets.count
276 278 [4, '4', 'def6d2f1254a'].each do |r1|
277 279 # Full diff of changeset 4
278 280 ['inline', 'sbs'].each do |dt|
279 281 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
280 282 assert_response :success
281 283 assert_template 'diff'
282 284 if @diff_c_support
283 285 # Line 22 removed
284 286 assert_tag :tag => 'th',
285 287 :content => '22',
286 288 :sibling => { :tag => 'td',
287 289 :attributes => { :class => /diff_out/ },
288 290 :content => /def remove/ }
289 291 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
290 292 end
291 293 end
292 294 end
293 295 end
294 296
295 297 def test_diff_two_revs
296 298 @repository.fetch_changesets
297 299 @repository.reload
298 300 [2, '400bb8672109', '400', 400].each do |r1|
299 301 [4, 'def6d2f1254a'].each do |r2|
300 302 ['inline', 'sbs'].each do |dt|
301 303 get :diff,
302 304 :id => PRJ_ID,
303 305 :rev => r1,
304 306 :rev_to => r2,
305 307 :type => dt
306 308 assert_response :success
307 309 assert_template 'diff'
308 310 diff = assigns(:diff)
309 311 assert_not_nil diff
310 312 assert_tag :tag => 'h2',
311 313 :content => /4:def6d2f1254a 2:400bb8672109/
312 314 end
313 315 end
314 316 end
315 317 end
316 318
317 319 def test_diff_latin_1_path
318 320 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
319 321 [21, 'adf805632193'].each do |r1|
320 322 ['inline', 'sbs'].each do |dt|
321 323 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
322 324 assert_response :success
323 325 assert_template 'diff'
324 326 assert_tag :tag => 'thead',
325 327 :descendant => {
326 328 :tag => 'th',
327 329 :attributes => { :class => 'filename' } ,
328 330 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
329 331 },
330 332 :sibling => {
331 333 :tag => 'tbody',
332 334 :descendant => {
333 335 :tag => 'td',
334 336 :attributes => { :class => /diff_in/ },
335 337 :content => /It is written in Python/
336 338 }
337 339 }
338 340 end
339 341 end
340 342 end
341 343 end
342 344
343 345 def test_annotate
344 346 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
345 347 assert_response :success
346 348 assert_template 'annotate'
347 349 # Line 23, revision 4:def6d2f1254a
348 350 assert_tag :tag => 'th',
349 351 :content => '23',
350 352 :attributes => { :class => 'line-num' },
351 353 :sibling =>
352 354 {
353 355 :tag => 'td',
354 356 :attributes => { :class => 'revision' },
355 357 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
356 358 }
357 359 assert_tag :tag => 'th',
358 360 :content => '23',
359 361 :attributes => { :class => 'line-num' },
360 362 :sibling =>
361 363 {
362 364 :tag => 'td' ,
363 365 :content => 'jsmith' ,
364 366 :attributes => { :class => 'author' },
365 367 }
366 368 assert_tag :tag => 'th',
367 369 :content => '23',
368 370 :attributes => { :class => 'line-num' },
369 371 :sibling => { :tag => 'td', :content => /watcher =/ }
370 372 end
371 373
372 374 def test_annotate_not_in_tip
373 375 @repository.fetch_changesets
374 376 @repository.reload
375 377 assert @repository.changesets.size > 0
376 378
377 379 get :annotate, :id => PRJ_ID,
378 380 :path => ['sources', 'welcome_controller.rb']
379 381 assert_response 404
380 382 assert_error_tag :content => /was not found/
381 383 end
382 384
383 385 def test_annotate_at_given_revision
384 386 @repository.fetch_changesets
385 387 @repository.reload
386 388 [2, '400bb8672109', '400', 400].each do |r1|
387 389 get :annotate, :id => PRJ_ID, :rev => r1,
388 390 :path => ['sources', 'watchers_controller.rb']
389 391 assert_response :success
390 392 assert_template 'annotate'
391 393 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
392 394 end
393 395 end
394 396
395 397 def test_annotate_latin_1_path
396 398 [21, '21', 'adf805632193'].each do |r1|
397 399 get :annotate, :id => PRJ_ID,
398 400 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
399 401 assert_response :success
400 402 assert_template 'annotate'
401 403 assert_tag :tag => 'th',
402 404 :content => '1',
403 405 :attributes => { :class => 'line-num' },
404 406 :sibling =>
405 407 {
406 408 :tag => 'td',
407 409 :attributes => { :class => 'revision' },
408 410 :child => { :tag => 'a', :content => '20:709858aafd1b' }
409 411 }
410 412 assert_tag :tag => 'th',
411 413 :content => '1',
412 414 :attributes => { :class => 'line-num' },
413 415 :sibling =>
414 416 {
415 417 :tag => 'td' ,
416 418 :content => 'jsmith' ,
417 419 :attributes => { :class => 'author' },
418 420 }
419 421 assert_tag :tag => 'th',
420 422 :content => '1',
421 423 :attributes => { :class => 'line-num' },
422 424 :sibling => { :tag => 'td',
423 425 :content => /Mercurial is a distributed version control system/ }
424 426
425 427 end
426 428 end
427 429
428 430 def test_annotate_latin_1_contents
429 431 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
430 432 [27, '7bbf4c738e71'].each do |r1|
431 433 get :annotate, :id => PRJ_ID,
432 434 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
433 435 assert_tag :tag => 'th',
434 436 :content => '1',
435 437 :attributes => { :class => 'line-num' },
436 438 :sibling => { :tag => 'td',
437 439 :content => /test-#{@char_1}.txt/ }
438 440 end
439 441 end
440 442 end
441 443
442 444 def test_empty_revision
443 445 @repository.fetch_changesets
444 446 @repository.reload
445 447 ['', ' ', nil].each do |r|
446 448 get :revision, :id => PRJ_ID, :rev => r
447 449 assert_response 404
448 450 assert_error_tag :content => /was not found/
449 451 end
450 452 end
451 453
452 454 def test_destroy_valid_repository
453 455 @request.session[:user_id] = 1 # admin
454 456 assert_equal 0, @repository.changesets.count
455 457 @repository.fetch_changesets
456 458 @project.reload
457 459 assert_equal NUM_REV, @repository.changesets.count
458 460
459 461 get :destroy, :id => PRJ_ID
460 462 assert_response 302
461 463 @project.reload
462 464 assert_nil @project.repository
463 465 end
464 466
465 467 def test_destroy_invalid_repository
466 468 @request.session[:user_id] = 1 # admin
467 469 assert_equal 0, @repository.changesets.count
468 470 @repository.fetch_changesets
469 471 @project.reload
470 472 assert_equal NUM_REV, @repository.changesets.count
471 473
472 474 get :destroy, :id => PRJ_ID
473 475 assert_response 302
474 476 @project.reload
475 477 assert_nil @project.repository
476 478
477 479 @repository = Repository::Mercurial.create(
478 480 :project => Project.find(PRJ_ID),
479 481 :url => "/invalid",
480 482 :path_encoding => 'ISO-8859-1'
481 483 )
482 484 assert @repository
483 485 @repository.fetch_changesets
484 486 @project.reload
485 487 assert_equal 0, @repository.changesets.count
486 488
487 489 get :destroy, :id => PRJ_ID
488 490 assert_response 302
489 491 @project.reload
490 492 assert_nil @project.repository
491 493 end
492 494 else
493 495 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
494 496 def test_fake; assert true end
495 497 end
496 498 end
General Comments 0
You need to be logged in to leave comments. Login now