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