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