##// END OF EJS Templates
Rails3: scm: git: fix error of test_diff_truncated at functional test...
Toshi MARUYAMA -
r7020:14386007f51e
parent child
Show More
@@ -1,449 +1,451
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 assert_equal 0, @repository.changesets.count
240 241 @repository.fetch_changesets
241 @repository.reload
242 @project.reload
243 assert_equal NUM_REV, @repository.changesets.count
242 244 Setting.diff_max_lines_displayed = 5
243 245
244 246 # Truncated diff of changeset 2f9c0091
245 247 with_cache do
246 248 get :diff, :id => PRJ_ID, :type => 'inline',
247 249 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
248 250 assert_response :success
249 251 assert @response.body.include?("... This diff was truncated")
250 252
251 253 Setting.default_language = 'fr'
252 254 get :diff, :id => PRJ_ID, :type => 'inline',
253 255 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
254 256 assert_response :success
255 257 assert ! @response.body.include?("... This diff was truncated")
256 258 assert @response.body.include?("... Ce diff")
257 259 end
258 260 end
259 261
260 262 def test_diff_two_revs
261 263 @repository.fetch_changesets
262 264 @repository.reload
263 265 ['inline', 'sbs'].each do |dt|
264 266 get :diff,
265 267 :id => PRJ_ID,
266 268 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
267 269 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
268 270 :type => dt
269 271 assert_response :success
270 272 assert_template 'diff'
271 273 diff = assigns(:diff)
272 274 assert_not_nil diff
273 275 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
274 276 end
275 277 end
276 278
277 279 def test_diff_latin_1
278 280 if @ruby19_non_utf8_pass
279 281 puts_ruby19_non_utf8_pass()
280 282 else
281 283 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
282 284 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
283 285 ['inline', 'sbs'].each do |dt|
284 286 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
285 287 assert_response :success
286 288 assert_template 'diff'
287 289 assert_tag :tag => 'thead',
288 290 :descendant => {
289 291 :tag => 'th',
290 292 :attributes => { :class => 'filename' } ,
291 293 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
292 294 },
293 295 :sibling => {
294 296 :tag => 'tbody',
295 297 :descendant => {
296 298 :tag => 'td',
297 299 :attributes => { :class => /diff_in/ },
298 300 :content => /test-#{@char_1}.txt/
299 301 }
300 302 }
301 303 end
302 304 end
303 305 end
304 306 end
305 307 end
306 308
307 309 def test_annotate
308 310 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
309 311 assert_response :success
310 312 assert_template 'annotate'
311 313 # Line 24, changeset 2f9c0091
312 314 assert_tag :tag => 'th', :content => '24',
313 315 :sibling => {
314 316 :tag => 'td',
315 317 :child => {
316 318 :tag => 'a',
317 319 :content => /2f9c0091/
318 320 }
319 321 }
320 322 assert_tag :tag => 'th', :content => '24',
321 323 :sibling => { :tag => 'td', :content => /jsmith/ }
322 324 assert_tag :tag => 'th', :content => '24',
323 325 :sibling => {
324 326 :tag => 'td',
325 327 :child => {
326 328 :tag => 'a',
327 329 :content => /2f9c0091/
328 330 }
329 331 }
330 332 assert_tag :tag => 'th', :content => '24',
331 333 :sibling => { :tag => 'td', :content => /watcher =/ }
332 334 end
333 335
334 336 def test_annotate_at_given_revision
335 337 @repository.fetch_changesets
336 338 @repository.reload
337 339 get :annotate, :id => PRJ_ID, :rev => 'deff7',
338 340 :path => ['sources', 'watchers_controller.rb']
339 341 assert_response :success
340 342 assert_template 'annotate'
341 343 assert_tag :tag => 'h2', :content => /@ deff712f/
342 344 end
343 345
344 346 def test_annotate_binary_file
345 347 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
346 348 assert_response 500
347 349 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
348 350 :content => /cannot be annotated/
349 351 end
350 352
351 353 def test_annotate_latin_1
352 354 if @ruby19_non_utf8_pass
353 355 puts_ruby19_non_utf8_pass()
354 356 elsif JRUBY_SKIP
355 357 puts JRUBY_SKIP_STR
356 358 else
357 359 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
358 360 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
359 361 get :annotate, :id => PRJ_ID,
360 362 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
361 363 assert_tag :tag => 'th',
362 364 :content => '1',
363 365 :attributes => { :class => 'line-num' },
364 366 :sibling => { :tag => 'td',
365 367 :content => /test-#{@char_1}.txt/ }
366 368 end
367 369 end
368 370 end
369 371 end
370 372
371 373 def test_revision
372 374 @repository.fetch_changesets
373 375 @repository.reload
374 376 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
375 377 get :revision, :id => PRJ_ID, :rev => r
376 378 assert_response :success
377 379 assert_template 'revision'
378 380 end
379 381 end
380 382
381 383 def test_empty_revision
382 384 @repository.fetch_changesets
383 385 @repository.reload
384 386 ['', ' ', nil].each do |r|
385 387 get :revision, :id => PRJ_ID, :rev => r
386 388 assert_response 404
387 389 assert_error_tag :content => /was not found/
388 390 end
389 391 end
390 392
391 393 def test_destroy_valid_repository
392 394 @request.session[:user_id] = 1 # admin
393 395 @repository.fetch_changesets
394 396 @repository.reload
395 397 assert @repository.changesets.count > 0
396 398
397 399 get :destroy, :id => PRJ_ID
398 400 assert_response 302
399 401 @project.reload
400 402 assert_nil @project.repository
401 403 end
402 404
403 405 def test_destroy_invalid_repository
404 406 @request.session[:user_id] = 1 # admin
405 407 @repository.fetch_changesets
406 408 @repository.reload
407 409 assert @repository.changesets.count > 0
408 410
409 411 get :destroy, :id => PRJ_ID
410 412 assert_response 302
411 413 @project.reload
412 414 assert_nil @project.repository
413 415
414 416 @repository = Repository::Git.create(
415 417 :project => @project,
416 418 :url => "/invalid",
417 419 :path_encoding => 'ISO-8859-1'
418 420 )
419 421 assert @repository
420 422 @repository.fetch_changesets
421 423 @repository.reload
422 424 assert_equal 0, @repository.changesets.count
423 425
424 426 get :destroy, :id => PRJ_ID
425 427 assert_response 302
426 428 @project.reload
427 429 assert_nil @project.repository
428 430 end
429 431
430 432 private
431 433
432 434 def puts_ruby19_non_utf8_pass
433 435 puts "TODO: This test fails in Ruby 1.9 " +
434 436 "and Encoding.default_external is not UTF-8. " +
435 437 "Current value is '#{Encoding.default_external.to_s}'"
436 438 end
437 439 else
438 440 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
439 441 def test_fake; assert true end
440 442 end
441 443
442 444 private
443 445 def with_cache(&block)
444 446 before = ActionController::Base.perform_caching
445 447 ActionController::Base.perform_caching = true
446 448 block.call
447 449 ActionController::Base.perform_caching = before
448 450 end
449 451 end
General Comments 0
You need to be logged in to leave comments. Login now