##// END OF EJS Templates
Rails3: scm: git: fix error of test_annotate_at_given_revision at functional test...
Toshi MARUYAMA -
r7022:117ebf2d65d1
parent child
Show More
@@ -1,453 +1,455
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 RepositoriesGitControllerTest < 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/git_repository').to_s
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30 PRJ_ID = 3
31 31 CHAR_1_HEX = "\xc3\x9c"
32 32 NUM_REV = 21
33 33
34 34 ## Git, Mercurial and CVS path encodings are binary.
35 35 ## Subversion supports URL encoding for path.
36 36 ## Redmine Mercurial adapter and extension use URL encoding.
37 37 ## Git accepts only binary path in command line parameter.
38 38 ## So, there is no way to use binary command line parameter in JRuby.
39 39 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
40 40 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
41 41
42 42 def setup
43 43 @ruby19_non_utf8_pass =
44 44 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
45 45
46 46 @controller = RepositoriesController.new
47 47 @request = ActionController::TestRequest.new
48 48 @response = ActionController::TestResponse.new
49 49 User.current = nil
50 50 @project = Project.find(PRJ_ID)
51 51 @repository = Repository::Git.create(
52 52 :project => @project,
53 53 :url => REPOSITORY_PATH,
54 54 :path_encoding => 'ISO-8859-1'
55 55 )
56 56 assert @repository
57 57 @char_1 = CHAR_1_HEX.dup
58 58 if @char_1.respond_to?(:force_encoding)
59 59 @char_1.force_encoding('UTF-8')
60 60 end
61 61
62 62 Setting.default_language = 'en'
63 63 end
64 64
65 65 if File.directory?(REPOSITORY_PATH)
66 66 def test_browse_root
67 67 assert_equal 0, @repository.changesets.count
68 68 @repository.fetch_changesets
69 69 @project.reload
70 70 assert_equal NUM_REV, @repository.changesets.count
71 71
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 9, 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 == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
79 79 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
80 80 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
81 81 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
82 82 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
83 83 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
84 84 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
85 85 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
86 86 assert_not_nil assigns(:changesets)
87 87 assert assigns(:changesets).size > 0
88 88 end
89 89
90 90 def test_browse_branch
91 91 assert_equal 0, @repository.changesets.count
92 92 @repository.fetch_changesets
93 93 @project.reload
94 94 assert_equal NUM_REV, @repository.changesets.count
95 95 get :show, :id => PRJ_ID, :rev => 'test_branch'
96 96 assert_response :success
97 97 assert_template 'show'
98 98 assert_not_nil assigns(:entries)
99 99 assert_equal 4, assigns(:entries).size
100 100 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
101 101 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
102 102 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
103 103 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
104 104 assert_not_nil assigns(:changesets)
105 105 assert assigns(:changesets).size > 0
106 106 end
107 107
108 108 def test_browse_tag
109 109 assert_equal 0, @repository.changesets.count
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 [
114 114 "tag00.lightweight",
115 115 "tag01.annotated",
116 116 ].each do |t1|
117 117 get :show, :id => PRJ_ID, :rev => t1
118 118 assert_response :success
119 119 assert_template 'show'
120 120 assert_not_nil assigns(:entries)
121 121 assert assigns(:entries).size > 0
122 122 assert_not_nil assigns(:changesets)
123 123 assert assigns(:changesets).size > 0
124 124 end
125 125 end
126 126
127 127 def test_browse_directory
128 128 assert_equal 0, @repository.changesets.count
129 129 @repository.fetch_changesets
130 130 @project.reload
131 131 assert_equal NUM_REV, @repository.changesets.count
132 132 get :show, :id => PRJ_ID, :path => ['images']
133 133 assert_response :success
134 134 assert_template 'show'
135 135 assert_not_nil assigns(:entries)
136 136 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
137 137 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
138 138 assert_not_nil entry
139 139 assert_equal 'file', entry.kind
140 140 assert_equal 'images/edit.png', entry.path
141 141 assert_not_nil assigns(:changesets)
142 142 assert assigns(:changesets).size > 0
143 143 end
144 144
145 145 def test_browse_at_given_revision
146 146 assert_equal 0, @repository.changesets.count
147 147 @repository.fetch_changesets
148 148 @project.reload
149 149 assert_equal NUM_REV, @repository.changesets.count
150 150 get :show, :id => PRJ_ID, :path => ['images'],
151 151 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
152 152 assert_response :success
153 153 assert_template 'show'
154 154 assert_not_nil assigns(:entries)
155 155 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
156 156 assert_not_nil assigns(:changesets)
157 157 assert assigns(:changesets).size > 0
158 158 end
159 159
160 160 def test_changes
161 161 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
162 162 assert_response :success
163 163 assert_template 'changes'
164 164 assert_tag :tag => 'h2', :content => 'edit.png'
165 165 end
166 166
167 167 def test_entry_show
168 168 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
169 169 assert_response :success
170 170 assert_template 'entry'
171 171 # Line 19
172 172 assert_tag :tag => 'th',
173 173 :content => '11',
174 174 :attributes => { :class => 'line-num' },
175 175 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
176 176 end
177 177
178 178 def test_entry_show_latin_1
179 179 if @ruby19_non_utf8_pass
180 180 puts_ruby19_non_utf8_pass()
181 181 elsif JRUBY_SKIP
182 182 puts JRUBY_SKIP_STR
183 183 else
184 184 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
185 185 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
186 186 get :entry, :id => PRJ_ID,
187 187 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
188 188 assert_response :success
189 189 assert_template 'entry'
190 190 assert_tag :tag => 'th',
191 191 :content => '1',
192 192 :attributes => { :class => 'line-num' },
193 193 :sibling => { :tag => 'td',
194 194 :content => /test-#{@char_1}.txt/ }
195 195 end
196 196 end
197 197 end
198 198 end
199 199
200 200 def test_entry_download
201 201 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
202 202 :format => 'raw'
203 203 assert_response :success
204 204 # File content
205 205 assert @response.body.include?('WITHOUT ANY WARRANTY')
206 206 end
207 207
208 208 def test_directory_entry
209 209 get :entry, :id => PRJ_ID, :path => ['sources']
210 210 assert_response :success
211 211 assert_template 'show'
212 212 assert_not_nil assigns(:entry)
213 213 assert_equal 'sources', assigns(:entry).name
214 214 end
215 215
216 216 def test_diff
217 217 assert_equal 0, @repository.changesets.count
218 218 @repository.fetch_changesets
219 219 @project.reload
220 220 assert_equal NUM_REV, @repository.changesets.count
221 221 # Full diff of changeset 2f9c0091
222 222 ['inline', 'sbs'].each do |dt|
223 223 get :diff,
224 224 :id => PRJ_ID,
225 225 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
226 226 :type => dt
227 227 assert_response :success
228 228 assert_template 'diff'
229 229 # Line 22 removed
230 230 assert_tag :tag => 'th',
231 231 :content => /22/,
232 232 :sibling => { :tag => 'td',
233 233 :attributes => { :class => /diff_out/ },
234 234 :content => /def remove/ }
235 235 assert_tag :tag => 'h2', :content => /2f9c0091/
236 236 end
237 237 end
238 238
239 239 def test_diff_truncated
240 240 assert_equal 0, @repository.changesets.count
241 241 @repository.fetch_changesets
242 242 @project.reload
243 243 assert_equal NUM_REV, @repository.changesets.count
244 244 Setting.diff_max_lines_displayed = 5
245 245
246 246 # Truncated diff of changeset 2f9c0091
247 247 with_cache do
248 248 get :diff, :id => PRJ_ID, :type => 'inline',
249 249 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
250 250 assert_response :success
251 251 assert @response.body.include?("... This diff was truncated")
252 252
253 253 Setting.default_language = 'fr'
254 254 get :diff, :id => PRJ_ID, :type => 'inline',
255 255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
256 256 assert_response :success
257 257 assert ! @response.body.include?("... This diff was truncated")
258 258 assert @response.body.include?("... Ce diff")
259 259 end
260 260 end
261 261
262 262 def test_diff_two_revs
263 263 assert_equal 0, @repository.changesets.count
264 264 @repository.fetch_changesets
265 265 @project.reload
266 266 assert_equal NUM_REV, @repository.changesets.count
267 267 ['inline', 'sbs'].each do |dt|
268 268 get :diff,
269 269 :id => PRJ_ID,
270 270 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
271 271 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
272 272 :type => dt
273 273 assert_response :success
274 274 assert_template 'diff'
275 275 diff = assigns(:diff)
276 276 assert_not_nil diff
277 277 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
278 278 end
279 279 end
280 280
281 281 def test_diff_latin_1
282 282 if @ruby19_non_utf8_pass
283 283 puts_ruby19_non_utf8_pass()
284 284 else
285 285 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
286 286 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
287 287 ['inline', 'sbs'].each do |dt|
288 288 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
289 289 assert_response :success
290 290 assert_template 'diff'
291 291 assert_tag :tag => 'thead',
292 292 :descendant => {
293 293 :tag => 'th',
294 294 :attributes => { :class => 'filename' } ,
295 295 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
296 296 },
297 297 :sibling => {
298 298 :tag => 'tbody',
299 299 :descendant => {
300 300 :tag => 'td',
301 301 :attributes => { :class => /diff_in/ },
302 302 :content => /test-#{@char_1}.txt/
303 303 }
304 304 }
305 305 end
306 306 end
307 307 end
308 308 end
309 309 end
310 310
311 311 def test_annotate
312 312 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
313 313 assert_response :success
314 314 assert_template 'annotate'
315 315 # Line 24, changeset 2f9c0091
316 316 assert_tag :tag => 'th', :content => '24',
317 317 :sibling => {
318 318 :tag => 'td',
319 319 :child => {
320 320 :tag => 'a',
321 321 :content => /2f9c0091/
322 322 }
323 323 }
324 324 assert_tag :tag => 'th', :content => '24',
325 325 :sibling => { :tag => 'td', :content => /jsmith/ }
326 326 assert_tag :tag => 'th', :content => '24',
327 327 :sibling => {
328 328 :tag => 'td',
329 329 :child => {
330 330 :tag => 'a',
331 331 :content => /2f9c0091/
332 332 }
333 333 }
334 334 assert_tag :tag => 'th', :content => '24',
335 335 :sibling => { :tag => 'td', :content => /watcher =/ }
336 336 end
337 337
338 338 def test_annotate_at_given_revision
339 assert_equal 0, @repository.changesets.count
339 340 @repository.fetch_changesets
340 @repository.reload
341 @project.reload
342 assert_equal NUM_REV, @repository.changesets.count
341 343 get :annotate, :id => PRJ_ID, :rev => 'deff7',
342 344 :path => ['sources', 'watchers_controller.rb']
343 345 assert_response :success
344 346 assert_template 'annotate'
345 347 assert_tag :tag => 'h2', :content => /@ deff712f/
346 348 end
347 349
348 350 def test_annotate_binary_file
349 351 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
350 352 assert_response 500
351 353 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
352 354 :content => /cannot be annotated/
353 355 end
354 356
355 357 def test_annotate_latin_1
356 358 if @ruby19_non_utf8_pass
357 359 puts_ruby19_non_utf8_pass()
358 360 elsif JRUBY_SKIP
359 361 puts JRUBY_SKIP_STR
360 362 else
361 363 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
362 364 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
363 365 get :annotate, :id => PRJ_ID,
364 366 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
365 367 assert_tag :tag => 'th',
366 368 :content => '1',
367 369 :attributes => { :class => 'line-num' },
368 370 :sibling => { :tag => 'td',
369 371 :content => /test-#{@char_1}.txt/ }
370 372 end
371 373 end
372 374 end
373 375 end
374 376
375 377 def test_revision
376 378 @repository.fetch_changesets
377 379 @repository.reload
378 380 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
379 381 get :revision, :id => PRJ_ID, :rev => r
380 382 assert_response :success
381 383 assert_template 'revision'
382 384 end
383 385 end
384 386
385 387 def test_empty_revision
386 388 @repository.fetch_changesets
387 389 @repository.reload
388 390 ['', ' ', nil].each do |r|
389 391 get :revision, :id => PRJ_ID, :rev => r
390 392 assert_response 404
391 393 assert_error_tag :content => /was not found/
392 394 end
393 395 end
394 396
395 397 def test_destroy_valid_repository
396 398 @request.session[:user_id] = 1 # admin
397 399 @repository.fetch_changesets
398 400 @repository.reload
399 401 assert @repository.changesets.count > 0
400 402
401 403 get :destroy, :id => PRJ_ID
402 404 assert_response 302
403 405 @project.reload
404 406 assert_nil @project.repository
405 407 end
406 408
407 409 def test_destroy_invalid_repository
408 410 @request.session[:user_id] = 1 # admin
409 411 @repository.fetch_changesets
410 412 @repository.reload
411 413 assert @repository.changesets.count > 0
412 414
413 415 get :destroy, :id => PRJ_ID
414 416 assert_response 302
415 417 @project.reload
416 418 assert_nil @project.repository
417 419
418 420 @repository = Repository::Git.create(
419 421 :project => @project,
420 422 :url => "/invalid",
421 423 :path_encoding => 'ISO-8859-1'
422 424 )
423 425 assert @repository
424 426 @repository.fetch_changesets
425 427 @repository.reload
426 428 assert_equal 0, @repository.changesets.count
427 429
428 430 get :destroy, :id => PRJ_ID
429 431 assert_response 302
430 432 @project.reload
431 433 assert_nil @project.repository
432 434 end
433 435
434 436 private
435 437
436 438 def puts_ruby19_non_utf8_pass
437 439 puts "TODO: This test fails in Ruby 1.9 " +
438 440 "and Encoding.default_external is not UTF-8. " +
439 441 "Current value is '#{Encoding.default_external.to_s}'"
440 442 end
441 443 else
442 444 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
443 445 def test_fake; assert true end
444 446 end
445 447
446 448 private
447 449 def with_cache(&block)
448 450 before = ActionController::Base.perform_caching
449 451 ActionController::Base.perform_caching = true
450 452 block.call
451 453 ActionController::Base.perform_caching = before
452 454 end
453 455 end
General Comments 0
You need to be logged in to leave comments. Login now