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