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