##// END OF EJS Templates
Merged r6242 from trunk....
Toshi MARUYAMA -
r6131:ba6b822e976a
parent child
Show More
@@ -1,431 +1,432
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 RepositoriesMercurialControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 27 # No '..' in the repository path
28 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
29 29 '/tmp/test/mercurial_repository'
30 30 CHAR_1_HEX = "\xc3\x9c"
31 31 PRJ_ID = 3
32 32
33 33 ruby19_non_utf8_pass =
34 34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
35 35
36 36 def setup
37 37 @controller = RepositoriesController.new
38 38 @request = ActionController::TestRequest.new
39 39 @response = ActionController::TestResponse.new
40 40 User.current = nil
41 @project = Project.find(PRJ_ID)
41 42 @repository = Repository::Mercurial.create(
42 :project => Project.find(PRJ_ID),
43 :project => @project,
43 44 :url => REPOSITORY_PATH,
44 45 :path_encoding => 'ISO-8859-1'
45 46 )
46 47 assert @repository
47 48 @diff_c_support = true
48 49 @char_1 = CHAR_1_HEX.dup
49 50 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
50 51 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
51 52 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
52 53 if @char_1.respond_to?(:force_encoding)
53 54 @char_1.force_encoding('UTF-8')
54 55 @tag_char_1.force_encoding('UTF-8')
55 56 @branch_char_0.force_encoding('UTF-8')
56 57 @branch_char_1.force_encoding('UTF-8')
57 58 end
58 59 end
59 60
60 61 if ruby19_non_utf8_pass
61 62 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
62 63 "and Encoding.default_external is not UTF-8. " +
63 64 "Current value is '#{Encoding.default_external.to_s}'"
64 65 def test_fake; assert true end
65 66 elsif File.directory?(REPOSITORY_PATH)
66 67 def test_show_root
67 68 @repository.fetch_changesets
68 69 @repository.reload
69 70 get :show, :id => PRJ_ID
70 71 assert_response :success
71 72 assert_template 'show'
72 73 assert_not_nil assigns(:entries)
73 74 assert_equal 4, assigns(:entries).size
74 75 assert assigns(:entries).detect {|e| e.name == 'images' && 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_not_nil assigns(:changesets)
78 79 assigns(:changesets).size > 0
79 80 end
80 81
81 82 def test_show_directory
82 83 @repository.fetch_changesets
83 84 @repository.reload
84 85 get :show, :id => PRJ_ID, :path => ['images']
85 86 assert_response :success
86 87 assert_template 'show'
87 88 assert_not_nil assigns(:entries)
88 89 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
89 90 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
90 91 assert_not_nil entry
91 92 assert_equal 'file', entry.kind
92 93 assert_equal 'images/edit.png', entry.path
93 94 assert_not_nil assigns(:changesets)
94 95 assigns(:changesets).size > 0
95 96 end
96 97
97 98 def test_show_at_given_revision
98 99 @repository.fetch_changesets
99 100 @repository.reload
100 101 [0, '0', '0885933ad4f6'].each do |r1|
101 102 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
102 103 assert_response :success
103 104 assert_template 'show'
104 105 assert_not_nil assigns(:entries)
105 106 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 107 assert_not_nil assigns(:changesets)
107 108 assigns(:changesets).size > 0
108 109 end
109 110 end
110 111
111 112 def test_show_directory_sql_escape_percent
112 113 @repository.fetch_changesets
113 114 @repository.reload
114 115 [13, '13', '3a330eb32958'].each do |r1|
115 116 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
116 117 :rev => r1
117 118 assert_response :success
118 119 assert_template 'show'
119 120
120 121 assert_not_nil assigns(:entries)
121 122 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 123 assigns(:entries).collect(&:name)
123 124 changesets = assigns(:changesets)
124 125 assert_not_nil changesets
125 126 assigns(:changesets).size > 0
126 127 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
127 128 end
128 129 end
129 130
130 131 def test_show_directory_latin_1_path
131 132 @repository.fetch_changesets
132 133 @repository.reload
133 134 [21, '21', 'adf805632193'].each do |r1|
134 135 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
135 136 assert_response :success
136 137 assert_template 'show'
137 138
138 139 assert_not_nil assigns(:entries)
139 140 assert_equal ["make-latin-1-file.rb",
140 141 "test-#{@char_1}-1.txt",
141 142 "test-#{@char_1}-2.txt",
142 143 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
143 144 changesets = assigns(:changesets)
144 145 assert_not_nil changesets
145 146 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
146 147 end
147 148 end
148 149
149 150 def test_show_branch
150 151 @repository.fetch_changesets
151 152 @repository.reload
152 153 [
153 154 'default',
154 155 @branch_char_1,
155 156 'branch (1)[2]&,%.-3_4',
156 157 @branch_char_0,
157 158 'test_branch.latin-1',
158 159 'test-branch-00',
159 160 ].each do |bra|
160 161 get :show, :id => PRJ_ID, :rev => bra
161 162 assert_response :success
162 163 assert_template 'show'
163 164 assert_not_nil assigns(:entries)
164 165 assert assigns(:entries).size > 0
165 166 assert_not_nil assigns(:changesets)
166 167 assigns(:changesets).size > 0
167 168 end
168 169 end
169 170
170 171 def test_show_tag
171 172 @repository.fetch_changesets
172 173 @repository.reload
173 174 [
174 175 @tag_char_1,
175 176 'tag_test.00',
176 177 'tag-init-revision'
177 178 ].each do |tag|
178 179 get :show, :id => PRJ_ID, :rev => tag
179 180 assert_response :success
180 181 assert_template 'show'
181 182 assert_not_nil assigns(:entries)
182 183 assert assigns(:entries).size > 0
183 184 assert_not_nil assigns(:changesets)
184 185 assigns(:changesets).size > 0
185 186 end
186 187 end
187 188
188 189 def test_changes
189 190 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
190 191 assert_response :success
191 192 assert_template 'changes'
192 193 assert_tag :tag => 'h2', :content => 'edit.png'
193 194 end
194 195
195 196 def test_entry_show
196 197 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
197 198 assert_response :success
198 199 assert_template 'entry'
199 200 # Line 10
200 201 assert_tag :tag => 'th',
201 202 :content => '10',
202 203 :attributes => { :class => 'line-num' },
203 204 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
204 205 end
205 206
206 207 def test_entry_show_latin_1_path
207 208 [21, '21', 'adf805632193'].each do |r1|
208 209 get :entry, :id => PRJ_ID,
209 210 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
210 211 assert_response :success
211 212 assert_template 'entry'
212 213 assert_tag :tag => 'th',
213 214 :content => '1',
214 215 :attributes => { :class => 'line-num' },
215 216 :sibling => { :tag => 'td',
216 217 :content => /Mercurial is a distributed version control system/ }
217 218 end
218 219 end
219 220
220 221 def test_entry_show_latin_1_contents
221 222 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
222 223 [27, '27', '7bbf4c738e71'].each do |r1|
223 224 get :entry, :id => PRJ_ID,
224 225 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
225 226 assert_response :success
226 227 assert_template 'entry'
227 228 assert_tag :tag => 'th',
228 229 :content => '1',
229 230 :attributes => { :class => 'line-num' },
230 231 :sibling => { :tag => 'td',
231 232 :content => /test-#{@char_1}.txt/ }
232 233 end
233 234 end
234 235 end
235 236
236 237 def test_entry_download
237 238 get :entry, :id => PRJ_ID,
238 239 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
239 240 assert_response :success
240 241 # File content
241 242 assert @response.body.include?('WITHOUT ANY WARRANTY')
242 243 end
243 244
244 245 def test_entry_binary_force_download
245 246 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
246 247 assert_response :success
247 248 assert_equal 'image/png', @response.content_type
248 249 end
249 250
250 251 def test_directory_entry
251 252 get :entry, :id => PRJ_ID, :path => ['sources']
252 253 assert_response :success
253 254 assert_template 'show'
254 255 assert_not_nil assigns(:entry)
255 256 assert_equal 'sources', assigns(:entry).name
256 257 end
257 258
258 259 def test_diff
259 260 @repository.fetch_changesets
260 261 @repository.reload
261 262 [4, '4', 'def6d2f1254a'].each do |r1|
262 263 # Full diff of changeset 4
263 264 get :diff, :id => PRJ_ID, :rev => r1
264 265 assert_response :success
265 266 assert_template 'diff'
266 267 if @diff_c_support
267 268 # Line 22 removed
268 269 assert_tag :tag => 'th',
269 270 :content => '22',
270 271 :sibling => { :tag => 'td',
271 272 :attributes => { :class => /diff_out/ },
272 273 :content => /def remove/ }
273 274 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
274 275 end
275 276 end
276 277 end
277 278
278 279 def test_diff_two_revs
279 280 @repository.fetch_changesets
280 281 @repository.reload
281 282 [2, '400bb8672109', '400', 400].each do |r1|
282 283 [4, 'def6d2f1254a'].each do |r2|
283 284 get :diff, :id => PRJ_ID, :rev => r1,
284 285 :rev_to => r2
285 286 assert_response :success
286 287 assert_template 'diff'
287 288
288 289 diff = assigns(:diff)
289 290 assert_not_nil diff
290 291 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
291 292 end
292 293 end
293 294 end
294 295
295 296 def test_diff_latin_1_path
296 297 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
297 298 [21, 'adf805632193'].each do |r1|
298 299 get :diff, :id => PRJ_ID, :rev => r1
299 300 assert_response :success
300 301 assert_template 'diff'
301 302 assert_tag :tag => 'thead',
302 303 :descendant => {
303 304 :tag => 'th',
304 305 :attributes => { :class => 'filename' } ,
305 306 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
306 307 },
307 308 :sibling => {
308 309 :tag => 'tbody',
309 310 :descendant => {
310 311 :tag => 'td',
311 312 :attributes => { :class => /diff_in/ },
312 313 :content => /It is written in Python/
313 314 }
314 315 }
315 316 end
316 317 end
317 318 end
318 319
319 320 def test_annotate
320 321 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
321 322 assert_response :success
322 323 assert_template 'annotate'
323 324 # Line 23, revision 4:def6d2f1254a
324 325 assert_tag :tag => 'th',
325 326 :content => '23',
326 327 :attributes => { :class => 'line-num' },
327 328 :sibling =>
328 329 {
329 330 :tag => 'td',
330 331 :attributes => { :class => 'revision' },
331 332 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
332 333 }
333 334 assert_tag :tag => 'th',
334 335 :content => '23',
335 336 :attributes => { :class => 'line-num' },
336 337 :sibling =>
337 338 {
338 339 :tag => 'td' ,
339 340 :content => 'jsmith' ,
340 341 :attributes => { :class => 'author' },
341 342 }
342 343 assert_tag :tag => 'th',
343 344 :content => '23',
344 345 :attributes => { :class => 'line-num' },
345 346 :sibling => { :tag => 'td', :content => /watcher =/ }
346 347 end
347 348
348 349 def test_annotate_not_in_tip
349 350 @repository.fetch_changesets
350 351 @repository.reload
351 352 assert @repository.changesets.size > 0
352 353
353 354 get :annotate, :id => PRJ_ID,
354 355 :path => ['sources', 'welcome_controller.rb']
355 356 assert_response 404
356 357 assert_error_tag :content => /was not found/
357 358 end
358 359
359 360 def test_annotate_at_given_revision
360 361 @repository.fetch_changesets
361 362 @repository.reload
362 363 [2, '400bb8672109', '400', 400].each do |r1|
363 364 get :annotate, :id => PRJ_ID, :rev => r1,
364 365 :path => ['sources', 'watchers_controller.rb']
365 366 assert_response :success
366 367 assert_template 'annotate'
367 368 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
368 369 end
369 370 end
370 371
371 372 def test_annotate_latin_1_path
372 373 [21, '21', 'adf805632193'].each do |r1|
373 374 get :annotate, :id => PRJ_ID,
374 375 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
375 376 assert_response :success
376 377 assert_template 'annotate'
377 378 assert_tag :tag => 'th',
378 379 :content => '1',
379 380 :attributes => { :class => 'line-num' },
380 381 :sibling =>
381 382 {
382 383 :tag => 'td',
383 384 :attributes => { :class => 'revision' },
384 385 :child => { :tag => 'a', :content => '20:709858aafd1b' }
385 386 }
386 387 assert_tag :tag => 'th',
387 388 :content => '1',
388 389 :attributes => { :class => 'line-num' },
389 390 :sibling =>
390 391 {
391 392 :tag => 'td' ,
392 393 :content => 'jsmith' ,
393 394 :attributes => { :class => 'author' },
394 395 }
395 396 assert_tag :tag => 'th',
396 397 :content => '1',
397 398 :attributes => { :class => 'line-num' },
398 399 :sibling => { :tag => 'td',
399 400 :content => /Mercurial is a distributed version control system/ }
400 401
401 402 end
402 403 end
403 404
404 405 def test_annotate_latin_1_contents
405 406 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
406 407 [27, '7bbf4c738e71'].each do |r1|
407 408 get :annotate, :id => PRJ_ID,
408 409 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
409 410 assert_tag :tag => 'th',
410 411 :content => '1',
411 412 :attributes => { :class => 'line-num' },
412 413 :sibling => { :tag => 'td',
413 414 :content => /test-#{@char_1}.txt/ }
414 415 end
415 416 end
416 417 end
417 418
418 419 def test_empty_revision
419 420 @repository.fetch_changesets
420 421 @repository.reload
421 422 ['', ' ', nil].each do |r|
422 423 get :revision, :id => PRJ_ID, :rev => r
423 424 assert_response 404
424 425 assert_error_tag :content => /was not found/
425 426 end
426 427 end
427 428 else
428 429 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
429 430 def test_fake; assert true end
430 431 end
431 432 end
General Comments 0
You need to be logged in to leave comments. Login now