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