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