##// END OF EJS Templates
Rails3: scm: mercurial: fix error of test_show_directory_latin_1_path at functional test...
Toshi MARUYAMA -
r7088:93202a201236
parent child
Show More
@@ -1,490 +1,492
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 assert_equal 0, @repository.changesets.count
140 141 @repository.fetch_changesets
141 @repository.reload
142 @project.reload
143 assert_equal NUM_REV, @repository.changesets.count
142 144 [21, '21', 'adf805632193'].each do |r1|
143 145 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
144 146 assert_response :success
145 147 assert_template 'show'
146 148
147 149 assert_not_nil assigns(:entries)
148 150 assert_equal ["make-latin-1-file.rb",
149 151 "test-#{@char_1}-1.txt",
150 152 "test-#{@char_1}-2.txt",
151 153 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
152 154 changesets = assigns(:changesets)
153 155 assert_not_nil changesets
154 156 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
155 157 end
156 158 end
157 159
158 160 def test_show_branch
159 161 @repository.fetch_changesets
160 162 @repository.reload
161 163 [
162 164 'default',
163 165 @branch_char_1,
164 166 'branch (1)[2]&,%.-3_4',
165 167 @branch_char_0,
166 168 'test_branch.latin-1',
167 169 'test-branch-00',
168 170 ].each do |bra|
169 171 get :show, :id => PRJ_ID, :rev => bra
170 172 assert_response :success
171 173 assert_template 'show'
172 174 assert_not_nil assigns(:entries)
173 175 assert assigns(:entries).size > 0
174 176 assert_not_nil assigns(:changesets)
175 177 assert assigns(:changesets).size > 0
176 178 end
177 179 end
178 180
179 181 def test_show_tag
180 182 @repository.fetch_changesets
181 183 @repository.reload
182 184 [
183 185 @tag_char_1,
184 186 'tag_test.00',
185 187 'tag-init-revision'
186 188 ].each do |tag|
187 189 get :show, :id => PRJ_ID, :rev => tag
188 190 assert_response :success
189 191 assert_template 'show'
190 192 assert_not_nil assigns(:entries)
191 193 assert assigns(:entries).size > 0
192 194 assert_not_nil assigns(:changesets)
193 195 assert assigns(:changesets).size > 0
194 196 end
195 197 end
196 198
197 199 def test_changes
198 200 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
199 201 assert_response :success
200 202 assert_template 'changes'
201 203 assert_tag :tag => 'h2', :content => 'edit.png'
202 204 end
203 205
204 206 def test_entry_show
205 207 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
206 208 assert_response :success
207 209 assert_template 'entry'
208 210 # Line 10
209 211 assert_tag :tag => 'th',
210 212 :content => '10',
211 213 :attributes => { :class => 'line-num' },
212 214 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
213 215 end
214 216
215 217 def test_entry_show_latin_1_path
216 218 [21, '21', 'adf805632193'].each do |r1|
217 219 get :entry, :id => PRJ_ID,
218 220 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
219 221 assert_response :success
220 222 assert_template 'entry'
221 223 assert_tag :tag => 'th',
222 224 :content => '1',
223 225 :attributes => { :class => 'line-num' },
224 226 :sibling => { :tag => 'td',
225 227 :content => /Mercurial is a distributed version control system/ }
226 228 end
227 229 end
228 230
229 231 def test_entry_show_latin_1_contents
230 232 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
231 233 [27, '27', '7bbf4c738e71'].each do |r1|
232 234 get :entry, :id => PRJ_ID,
233 235 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
234 236 assert_response :success
235 237 assert_template 'entry'
236 238 assert_tag :tag => 'th',
237 239 :content => '1',
238 240 :attributes => { :class => 'line-num' },
239 241 :sibling => { :tag => 'td',
240 242 :content => /test-#{@char_1}.txt/ }
241 243 end
242 244 end
243 245 end
244 246
245 247 def test_entry_download
246 248 get :entry, :id => PRJ_ID,
247 249 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
248 250 assert_response :success
249 251 # File content
250 252 assert @response.body.include?('WITHOUT ANY WARRANTY')
251 253 end
252 254
253 255 def test_entry_binary_force_download
254 256 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
255 257 assert_response :success
256 258 assert_equal 'image/png', @response.content_type
257 259 end
258 260
259 261 def test_directory_entry
260 262 get :entry, :id => PRJ_ID, :path => ['sources']
261 263 assert_response :success
262 264 assert_template 'show'
263 265 assert_not_nil assigns(:entry)
264 266 assert_equal 'sources', assigns(:entry).name
265 267 end
266 268
267 269 def test_diff
268 270 @repository.fetch_changesets
269 271 @repository.reload
270 272 [4, '4', 'def6d2f1254a'].each do |r1|
271 273 # Full diff of changeset 4
272 274 ['inline', 'sbs'].each do |dt|
273 275 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
274 276 assert_response :success
275 277 assert_template 'diff'
276 278 if @diff_c_support
277 279 # Line 22 removed
278 280 assert_tag :tag => 'th',
279 281 :content => '22',
280 282 :sibling => { :tag => 'td',
281 283 :attributes => { :class => /diff_out/ },
282 284 :content => /def remove/ }
283 285 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
284 286 end
285 287 end
286 288 end
287 289 end
288 290
289 291 def test_diff_two_revs
290 292 @repository.fetch_changesets
291 293 @repository.reload
292 294 [2, '400bb8672109', '400', 400].each do |r1|
293 295 [4, 'def6d2f1254a'].each do |r2|
294 296 ['inline', 'sbs'].each do |dt|
295 297 get :diff,
296 298 :id => PRJ_ID,
297 299 :rev => r1,
298 300 :rev_to => r2,
299 301 :type => dt
300 302 assert_response :success
301 303 assert_template 'diff'
302 304 diff = assigns(:diff)
303 305 assert_not_nil diff
304 306 assert_tag :tag => 'h2',
305 307 :content => /4:def6d2f1254a 2:400bb8672109/
306 308 end
307 309 end
308 310 end
309 311 end
310 312
311 313 def test_diff_latin_1_path
312 314 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
313 315 [21, 'adf805632193'].each do |r1|
314 316 ['inline', 'sbs'].each do |dt|
315 317 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
316 318 assert_response :success
317 319 assert_template 'diff'
318 320 assert_tag :tag => 'thead',
319 321 :descendant => {
320 322 :tag => 'th',
321 323 :attributes => { :class => 'filename' } ,
322 324 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
323 325 },
324 326 :sibling => {
325 327 :tag => 'tbody',
326 328 :descendant => {
327 329 :tag => 'td',
328 330 :attributes => { :class => /diff_in/ },
329 331 :content => /It is written in Python/
330 332 }
331 333 }
332 334 end
333 335 end
334 336 end
335 337 end
336 338
337 339 def test_annotate
338 340 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
339 341 assert_response :success
340 342 assert_template 'annotate'
341 343 # Line 23, revision 4:def6d2f1254a
342 344 assert_tag :tag => 'th',
343 345 :content => '23',
344 346 :attributes => { :class => 'line-num' },
345 347 :sibling =>
346 348 {
347 349 :tag => 'td',
348 350 :attributes => { :class => 'revision' },
349 351 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
350 352 }
351 353 assert_tag :tag => 'th',
352 354 :content => '23',
353 355 :attributes => { :class => 'line-num' },
354 356 :sibling =>
355 357 {
356 358 :tag => 'td' ,
357 359 :content => 'jsmith' ,
358 360 :attributes => { :class => 'author' },
359 361 }
360 362 assert_tag :tag => 'th',
361 363 :content => '23',
362 364 :attributes => { :class => 'line-num' },
363 365 :sibling => { :tag => 'td', :content => /watcher =/ }
364 366 end
365 367
366 368 def test_annotate_not_in_tip
367 369 @repository.fetch_changesets
368 370 @repository.reload
369 371 assert @repository.changesets.size > 0
370 372
371 373 get :annotate, :id => PRJ_ID,
372 374 :path => ['sources', 'welcome_controller.rb']
373 375 assert_response 404
374 376 assert_error_tag :content => /was not found/
375 377 end
376 378
377 379 def test_annotate_at_given_revision
378 380 @repository.fetch_changesets
379 381 @repository.reload
380 382 [2, '400bb8672109', '400', 400].each do |r1|
381 383 get :annotate, :id => PRJ_ID, :rev => r1,
382 384 :path => ['sources', 'watchers_controller.rb']
383 385 assert_response :success
384 386 assert_template 'annotate'
385 387 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
386 388 end
387 389 end
388 390
389 391 def test_annotate_latin_1_path
390 392 [21, '21', 'adf805632193'].each do |r1|
391 393 get :annotate, :id => PRJ_ID,
392 394 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
393 395 assert_response :success
394 396 assert_template 'annotate'
395 397 assert_tag :tag => 'th',
396 398 :content => '1',
397 399 :attributes => { :class => 'line-num' },
398 400 :sibling =>
399 401 {
400 402 :tag => 'td',
401 403 :attributes => { :class => 'revision' },
402 404 :child => { :tag => 'a', :content => '20:709858aafd1b' }
403 405 }
404 406 assert_tag :tag => 'th',
405 407 :content => '1',
406 408 :attributes => { :class => 'line-num' },
407 409 :sibling =>
408 410 {
409 411 :tag => 'td' ,
410 412 :content => 'jsmith' ,
411 413 :attributes => { :class => 'author' },
412 414 }
413 415 assert_tag :tag => 'th',
414 416 :content => '1',
415 417 :attributes => { :class => 'line-num' },
416 418 :sibling => { :tag => 'td',
417 419 :content => /Mercurial is a distributed version control system/ }
418 420
419 421 end
420 422 end
421 423
422 424 def test_annotate_latin_1_contents
423 425 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
424 426 [27, '7bbf4c738e71'].each do |r1|
425 427 get :annotate, :id => PRJ_ID,
426 428 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
427 429 assert_tag :tag => 'th',
428 430 :content => '1',
429 431 :attributes => { :class => 'line-num' },
430 432 :sibling => { :tag => 'td',
431 433 :content => /test-#{@char_1}.txt/ }
432 434 end
433 435 end
434 436 end
435 437
436 438 def test_empty_revision
437 439 @repository.fetch_changesets
438 440 @repository.reload
439 441 ['', ' ', nil].each do |r|
440 442 get :revision, :id => PRJ_ID, :rev => r
441 443 assert_response 404
442 444 assert_error_tag :content => /was not found/
443 445 end
444 446 end
445 447
446 448 def test_destroy_valid_repository
447 449 @request.session[:user_id] = 1 # admin
448 450 assert_equal 0, @repository.changesets.count
449 451 @repository.fetch_changesets
450 452 @project.reload
451 453 assert_equal NUM_REV, @repository.changesets.count
452 454
453 455 get :destroy, :id => PRJ_ID
454 456 assert_response 302
455 457 @project.reload
456 458 assert_nil @project.repository
457 459 end
458 460
459 461 def test_destroy_invalid_repository
460 462 @request.session[:user_id] = 1 # admin
461 463 assert_equal 0, @repository.changesets.count
462 464 @repository.fetch_changesets
463 465 @project.reload
464 466 assert_equal NUM_REV, @repository.changesets.count
465 467
466 468 get :destroy, :id => PRJ_ID
467 469 assert_response 302
468 470 @project.reload
469 471 assert_nil @project.repository
470 472
471 473 @repository = Repository::Mercurial.create(
472 474 :project => Project.find(PRJ_ID),
473 475 :url => "/invalid",
474 476 :path_encoding => 'ISO-8859-1'
475 477 )
476 478 assert @repository
477 479 @repository.fetch_changesets
478 480 @project.reload
479 481 assert_equal 0, @repository.changesets.count
480 482
481 483 get :destroy, :id => PRJ_ID
482 484 assert_response 302
483 485 @project.reload
484 486 assert_nil @project.repository
485 487 end
486 488 else
487 489 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
488 490 def test_fake; assert true end
489 491 end
490 492 end
General Comments 0
You need to be logged in to leave comments. Login now