##// END OF EJS Templates
Rails3: scm: git: fix error of test_browse_at_given_revision at functional test...
Toshi MARUYAMA -
r7018:1cae0ae4157d
parent child
Show More
@@ -1,445 +1,447
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 assert_equal 0, @repository.changesets.count
146 147 @repository.fetch_changesets
147 @repository.reload
148 @project.reload
149 assert_equal NUM_REV, @repository.changesets.count
148 150 get :show, :id => PRJ_ID, :path => ['images'],
149 151 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
150 152 assert_response :success
151 153 assert_template 'show'
152 154 assert_not_nil assigns(:entries)
153 155 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
154 156 assert_not_nil assigns(:changesets)
155 157 assert assigns(:changesets).size > 0
156 158 end
157 159
158 160 def test_changes
159 161 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
160 162 assert_response :success
161 163 assert_template 'changes'
162 164 assert_tag :tag => 'h2', :content => 'edit.png'
163 165 end
164 166
165 167 def test_entry_show
166 168 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
167 169 assert_response :success
168 170 assert_template 'entry'
169 171 # Line 19
170 172 assert_tag :tag => 'th',
171 173 :content => '11',
172 174 :attributes => { :class => 'line-num' },
173 175 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
174 176 end
175 177
176 178 def test_entry_show_latin_1
177 179 if @ruby19_non_utf8_pass
178 180 puts_ruby19_non_utf8_pass()
179 181 elsif JRUBY_SKIP
180 182 puts JRUBY_SKIP_STR
181 183 else
182 184 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
183 185 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
184 186 get :entry, :id => PRJ_ID,
185 187 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
186 188 assert_response :success
187 189 assert_template 'entry'
188 190 assert_tag :tag => 'th',
189 191 :content => '1',
190 192 :attributes => { :class => 'line-num' },
191 193 :sibling => { :tag => 'td',
192 194 :content => /test-#{@char_1}.txt/ }
193 195 end
194 196 end
195 197 end
196 198 end
197 199
198 200 def test_entry_download
199 201 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
200 202 :format => 'raw'
201 203 assert_response :success
202 204 # File content
203 205 assert @response.body.include?('WITHOUT ANY WARRANTY')
204 206 end
205 207
206 208 def test_directory_entry
207 209 get :entry, :id => PRJ_ID, :path => ['sources']
208 210 assert_response :success
209 211 assert_template 'show'
210 212 assert_not_nil assigns(:entry)
211 213 assert_equal 'sources', assigns(:entry).name
212 214 end
213 215
214 216 def test_diff
215 217 @repository.fetch_changesets
216 218 @repository.reload
217 219 # Full diff of changeset 2f9c0091
218 220 ['inline', 'sbs'].each do |dt|
219 221 get :diff,
220 222 :id => PRJ_ID,
221 223 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
222 224 :type => dt
223 225 assert_response :success
224 226 assert_template 'diff'
225 227 # Line 22 removed
226 228 assert_tag :tag => 'th',
227 229 :content => /22/,
228 230 :sibling => { :tag => 'td',
229 231 :attributes => { :class => /diff_out/ },
230 232 :content => /def remove/ }
231 233 assert_tag :tag => 'h2', :content => /2f9c0091/
232 234 end
233 235 end
234 236
235 237 def test_diff_truncated
236 238 @repository.fetch_changesets
237 239 @repository.reload
238 240 Setting.diff_max_lines_displayed = 5
239 241
240 242 # Truncated diff of changeset 2f9c0091
241 243 with_cache do
242 244 get :diff, :id => PRJ_ID, :type => 'inline',
243 245 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
244 246 assert_response :success
245 247 assert @response.body.include?("... This diff was truncated")
246 248
247 249 Setting.default_language = 'fr'
248 250 get :diff, :id => PRJ_ID, :type => 'inline',
249 251 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
250 252 assert_response :success
251 253 assert ! @response.body.include?("... This diff was truncated")
252 254 assert @response.body.include?("... Ce diff")
253 255 end
254 256 end
255 257
256 258 def test_diff_two_revs
257 259 @repository.fetch_changesets
258 260 @repository.reload
259 261 ['inline', 'sbs'].each do |dt|
260 262 get :diff,
261 263 :id => PRJ_ID,
262 264 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
263 265 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
264 266 :type => dt
265 267 assert_response :success
266 268 assert_template 'diff'
267 269 diff = assigns(:diff)
268 270 assert_not_nil diff
269 271 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
270 272 end
271 273 end
272 274
273 275 def test_diff_latin_1
274 276 if @ruby19_non_utf8_pass
275 277 puts_ruby19_non_utf8_pass()
276 278 else
277 279 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
278 280 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
279 281 ['inline', 'sbs'].each do |dt|
280 282 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
281 283 assert_response :success
282 284 assert_template 'diff'
283 285 assert_tag :tag => 'thead',
284 286 :descendant => {
285 287 :tag => 'th',
286 288 :attributes => { :class => 'filename' } ,
287 289 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
288 290 },
289 291 :sibling => {
290 292 :tag => 'tbody',
291 293 :descendant => {
292 294 :tag => 'td',
293 295 :attributes => { :class => /diff_in/ },
294 296 :content => /test-#{@char_1}.txt/
295 297 }
296 298 }
297 299 end
298 300 end
299 301 end
300 302 end
301 303 end
302 304
303 305 def test_annotate
304 306 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
305 307 assert_response :success
306 308 assert_template 'annotate'
307 309 # Line 24, changeset 2f9c0091
308 310 assert_tag :tag => 'th', :content => '24',
309 311 :sibling => {
310 312 :tag => 'td',
311 313 :child => {
312 314 :tag => 'a',
313 315 :content => /2f9c0091/
314 316 }
315 317 }
316 318 assert_tag :tag => 'th', :content => '24',
317 319 :sibling => { :tag => 'td', :content => /jsmith/ }
318 320 assert_tag :tag => 'th', :content => '24',
319 321 :sibling => {
320 322 :tag => 'td',
321 323 :child => {
322 324 :tag => 'a',
323 325 :content => /2f9c0091/
324 326 }
325 327 }
326 328 assert_tag :tag => 'th', :content => '24',
327 329 :sibling => { :tag => 'td', :content => /watcher =/ }
328 330 end
329 331
330 332 def test_annotate_at_given_revision
331 333 @repository.fetch_changesets
332 334 @repository.reload
333 335 get :annotate, :id => PRJ_ID, :rev => 'deff7',
334 336 :path => ['sources', 'watchers_controller.rb']
335 337 assert_response :success
336 338 assert_template 'annotate'
337 339 assert_tag :tag => 'h2', :content => /@ deff712f/
338 340 end
339 341
340 342 def test_annotate_binary_file
341 343 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
342 344 assert_response 500
343 345 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
344 346 :content => /cannot be annotated/
345 347 end
346 348
347 349 def test_annotate_latin_1
348 350 if @ruby19_non_utf8_pass
349 351 puts_ruby19_non_utf8_pass()
350 352 elsif JRUBY_SKIP
351 353 puts JRUBY_SKIP_STR
352 354 else
353 355 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
354 356 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
355 357 get :annotate, :id => PRJ_ID,
356 358 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
357 359 assert_tag :tag => 'th',
358 360 :content => '1',
359 361 :attributes => { :class => 'line-num' },
360 362 :sibling => { :tag => 'td',
361 363 :content => /test-#{@char_1}.txt/ }
362 364 end
363 365 end
364 366 end
365 367 end
366 368
367 369 def test_revision
368 370 @repository.fetch_changesets
369 371 @repository.reload
370 372 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
371 373 get :revision, :id => PRJ_ID, :rev => r
372 374 assert_response :success
373 375 assert_template 'revision'
374 376 end
375 377 end
376 378
377 379 def test_empty_revision
378 380 @repository.fetch_changesets
379 381 @repository.reload
380 382 ['', ' ', nil].each do |r|
381 383 get :revision, :id => PRJ_ID, :rev => r
382 384 assert_response 404
383 385 assert_error_tag :content => /was not found/
384 386 end
385 387 end
386 388
387 389 def test_destroy_valid_repository
388 390 @request.session[:user_id] = 1 # admin
389 391 @repository.fetch_changesets
390 392 @repository.reload
391 393 assert @repository.changesets.count > 0
392 394
393 395 get :destroy, :id => PRJ_ID
394 396 assert_response 302
395 397 @project.reload
396 398 assert_nil @project.repository
397 399 end
398 400
399 401 def test_destroy_invalid_repository
400 402 @request.session[:user_id] = 1 # admin
401 403 @repository.fetch_changesets
402 404 @repository.reload
403 405 assert @repository.changesets.count > 0
404 406
405 407 get :destroy, :id => PRJ_ID
406 408 assert_response 302
407 409 @project.reload
408 410 assert_nil @project.repository
409 411
410 412 @repository = Repository::Git.create(
411 413 :project => @project,
412 414 :url => "/invalid",
413 415 :path_encoding => 'ISO-8859-1'
414 416 )
415 417 assert @repository
416 418 @repository.fetch_changesets
417 419 @repository.reload
418 420 assert_equal 0, @repository.changesets.count
419 421
420 422 get :destroy, :id => PRJ_ID
421 423 assert_response 302
422 424 @project.reload
423 425 assert_nil @project.repository
424 426 end
425 427
426 428 private
427 429
428 430 def puts_ruby19_non_utf8_pass
429 431 puts "TODO: This test fails in Ruby 1.9 " +
430 432 "and Encoding.default_external is not UTF-8. " +
431 433 "Current value is '#{Encoding.default_external.to_s}'"
432 434 end
433 435 else
434 436 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
435 437 def test_fake; assert true end
436 438 end
437 439
438 440 private
439 441 def with_cache(&block)
440 442 before = ActionController::Base.perform_caching
441 443 ActionController::Base.perform_caching = true
442 444 block.call
443 445 ActionController::Base.perform_caching = before
444 446 end
445 447 end
General Comments 0
You need to be logged in to leave comments. Login now