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