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