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