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