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