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