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