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