##// END OF EJS Templates
Fix test failures (#22058)....
Jean-Philippe Lang -
r14946:dae1e6ab2179
parent child
Show More
@@ -1,490 +1,487
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 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
20 20 class RepositoriesMercurialControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles,
24 24 :repositories, :enabled_modules
25 25
26 26 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
27 27 CHAR_1_HEX = "\xc3\x9c"
28 28 PRJ_ID = 3
29 29 NUM_REV = 34
30 30
31 31 ruby19_non_utf8_pass = Encoding.default_external.to_s != 'UTF-8'
32 32
33 33 def setup
34 34 User.current = nil
35 35 @project = Project.find(PRJ_ID)
36 36 @repository = Repository::Mercurial.create(
37 37 :project => @project,
38 38 :url => REPOSITORY_PATH,
39 39 :path_encoding => 'ISO-8859-1'
40 40 )
41 41 assert @repository
42 42 @diff_c_support = true
43 43 @char_1 = CHAR_1_HEX.dup.force_encoding('UTF-8')
44 44 @tag_char_1 = "tag-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
45 45 @branch_char_0 = "branch-#{CHAR_1_HEX}-00".force_encoding('UTF-8')
46 46 @branch_char_1 = "branch-#{CHAR_1_HEX}-01".force_encoding('UTF-8')
47 47 end
48 48
49 49 if ruby19_non_utf8_pass
50 50 puts "TODO: Mercurial functional test fails " +
51 51 "when Encoding.default_external is not UTF-8. " +
52 52 "Current value is '#{Encoding.default_external.to_s}'"
53 53 def test_fake; assert true end
54 54 elsif File.directory?(REPOSITORY_PATH)
55 55
56 56 def test_get_new
57 57 @request.session[:user_id] = 1
58 58 @project.repository.destroy
59 59 get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial'
60 60 assert_response :success
61 61 assert_template 'new'
62 62 assert_kind_of Repository::Mercurial, assigns(:repository)
63 63 assert assigns(:repository).new_record?
64 64 end
65 65
66 66 def test_show_root
67 67 assert_equal 0, @repository.changesets.count
68 68 @repository.fetch_changesets
69 69 @project.reload
70 70 assert_equal NUM_REV, @repository.changesets.count
71 71 get :show, :id => PRJ_ID
72 72 assert_response :success
73 73 assert_template 'show'
74 74 assert_not_nil assigns(:entries)
75 75 assert_equal 4, assigns(:entries).size
76 76 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
77 77 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
78 78 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
79 79 assert_not_nil assigns(:changesets)
80 80 assert assigns(:changesets).size > 0
81 81 end
82 82
83 83 def test_show_directory
84 84 assert_equal 0, @repository.changesets.count
85 85 @repository.fetch_changesets
86 86 @project.reload
87 87 assert_equal NUM_REV, @repository.changesets.count
88 88 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
89 89 assert_response :success
90 90 assert_template 'show'
91 91 assert_not_nil assigns(:entries)
92 92 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
93 93 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
94 94 assert_not_nil entry
95 95 assert_equal 'file', entry.kind
96 96 assert_equal 'images/edit.png', entry.path
97 97 assert_not_nil assigns(:changesets)
98 98 assert assigns(:changesets).size > 0
99 99 end
100 100
101 101 def test_show_at_given_revision
102 102 assert_equal 0, @repository.changesets.count
103 103 @repository.fetch_changesets
104 104 @project.reload
105 105 assert_equal NUM_REV, @repository.changesets.count
106 106 [0, '0', '0885933ad4f6'].each do |r1|
107 107 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
108 108 :rev => r1
109 109 assert_response :success
110 110 assert_template 'show'
111 111 assert_not_nil assigns(:entries)
112 112 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
113 113 assert_not_nil assigns(:changesets)
114 114 assert assigns(:changesets).size > 0
115 115 end
116 116 end
117 117
118 118 def test_show_directory_sql_escape_percent
119 119 assert_equal 0, @repository.changesets.count
120 120 @repository.fetch_changesets
121 121 @project.reload
122 122 assert_equal NUM_REV, @repository.changesets.count
123 123 [13, '13', '3a330eb32958'].each do |r1|
124 124 get :show, :id => PRJ_ID,
125 125 :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param],
126 126 :rev => r1
127 127 assert_response :success
128 128 assert_template 'show'
129 129
130 130 assert_not_nil assigns(:entries)
131 131 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
132 132 assigns(:entries).collect(&:name)
133 133 changesets = assigns(:changesets)
134 134 assert_not_nil changesets
135 135 assert assigns(:changesets).size > 0
136 136 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
137 137 end
138 138 end
139 139
140 140 def test_show_directory_latin_1_path
141 141 assert_equal 0, @repository.changesets.count
142 142 @repository.fetch_changesets
143 143 @project.reload
144 144 assert_equal NUM_REV, @repository.changesets.count
145 145 [21, '21', 'adf805632193'].each do |r1|
146 146 get :show, :id => PRJ_ID,
147 147 :path => repository_path_hash(['latin-1-dir'])[:param],
148 148 :rev => r1
149 149 assert_response :success
150 150 assert_template 'show'
151 151
152 152 assert_not_nil assigns(:entries)
153 153 assert_equal ["make-latin-1-file.rb",
154 154 "test-#{@char_1}-1.txt",
155 155 "test-#{@char_1}-2.txt",
156 156 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
157 157 changesets = assigns(:changesets)
158 158 assert_not_nil changesets
159 159 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
160 160 end
161 161 end
162 162
163 163 def show_should_show_branch_selection_form
164 164 @repository.fetch_changesets
165 165 @project.reload
166 166 get :show, :id => PRJ_ID
167 167 assert_select 'form#revision_selector[action=?]', '/projects/subproject1/repository/show' do
168 168 assert_select 'select[name=branch]' do
169 169 assert_select 'option[value=?]', 'test-branch-01'
170 170 end
171 171 end
172 172 end
173 173
174 174 def test_show_branch
175 175 assert_equal 0, @repository.changesets.count
176 176 @repository.fetch_changesets
177 177 @project.reload
178 178 assert_equal NUM_REV, @repository.changesets.count
179 179 [
180 180 'default',
181 181 @branch_char_1,
182 182 'branch (1)[2]&,%.-3_4',
183 183 @branch_char_0,
184 184 'test_branch.latin-1',
185 185 'test-branch-00',
186 186 ].each do |bra|
187 187 get :show, :id => PRJ_ID, :rev => bra
188 188 assert_response :success
189 189 assert_template 'show'
190 190 assert_not_nil assigns(:entries)
191 191 assert assigns(:entries).size > 0
192 192 assert_not_nil assigns(:changesets)
193 193 assert assigns(:changesets).size > 0
194 194 end
195 195 end
196 196
197 197 def test_show_tag
198 198 assert_equal 0, @repository.changesets.count
199 199 @repository.fetch_changesets
200 200 @project.reload
201 201 assert_equal NUM_REV, @repository.changesets.count
202 202 [
203 203 @tag_char_1,
204 204 'tag_test.00',
205 205 'tag-init-revision'
206 206 ].each do |tag|
207 207 get :show, :id => PRJ_ID, :rev => tag
208 208 assert_response :success
209 209 assert_template 'show'
210 210 assert_not_nil assigns(:entries)
211 211 assert assigns(:entries).size > 0
212 212 assert_not_nil assigns(:changesets)
213 213 assert assigns(:changesets).size > 0
214 214 end
215 215 end
216 216
217 217 def test_changes
218 218 get :changes, :id => PRJ_ID,
219 219 :path => repository_path_hash(['images', 'edit.png'])[:param]
220 220 assert_response :success
221 221 assert_template 'changes'
222 222 assert_select 'h2', :text => /edit.png/
223 223 end
224 224
225 225 def test_entry_show
226 226 get :entry, :id => PRJ_ID,
227 227 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
228 228 assert_response :success
229 229 assert_template 'entry'
230 230 # Line 10
231 231 assert_select 'tr#L10 td.line-code', :text => /WITHOUT ANY WARRANTY/
232 232 end
233 233
234 234 def test_entry_show_latin_1_path
235 235 [21, '21', 'adf805632193'].each do |r1|
236 236 get :entry, :id => PRJ_ID,
237 237 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
238 238 :rev => r1
239 239 assert_response :success
240 240 assert_template 'entry'
241 241 assert_select 'tr#L1 td.line-code', :text => /Mercurial is a distributed version control system/
242 242 end
243 243 end
244 244
245 245 def test_entry_show_latin_1_contents
246 246 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
247 247 [27, '27', '7bbf4c738e71'].each do |r1|
248 248 get :entry, :id => PRJ_ID,
249 249 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
250 250 :rev => r1
251 251 assert_response :success
252 252 assert_template 'entry'
253 253 assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
254 254 end
255 255 end
256 256 end
257 257
258 258 def test_entry_download
259 259 get :entry, :id => PRJ_ID,
260 260 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
261 261 :format => 'raw'
262 262 assert_response :success
263 263 # File content
264 264 assert @response.body.include?('WITHOUT ANY WARRANTY')
265 265 end
266 266
267 267 def test_entry_binary_force_download
268 get :entry, :id => PRJ_ID, :rev => 1,
269 :path => repository_path_hash(['images', 'edit.png'])[:param]
270 assert_response :success
271 assert_equal 'image/png', @response.content_type
268 # TODO: add a binary file which is not an image to the test repo
272 269 end
273 270
274 271 def test_directory_entry
275 272 get :entry, :id => PRJ_ID,
276 273 :path => repository_path_hash(['sources'])[:param]
277 274 assert_response :success
278 275 assert_template 'show'
279 276 assert_not_nil assigns(:entry)
280 277 assert_equal 'sources', assigns(:entry).name
281 278 end
282 279
283 280 def test_diff
284 281 assert_equal 0, @repository.changesets.count
285 282 @repository.fetch_changesets
286 283 @project.reload
287 284 assert_equal NUM_REV, @repository.changesets.count
288 285 [4, '4', 'def6d2f1254a'].each do |r1|
289 286 # Full diff of changeset 4
290 287 ['inline', 'sbs'].each do |dt|
291 288 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
292 289 assert_response :success
293 290 assert_template 'diff'
294 291 if @diff_c_support
295 292 # Line 22 removed
296 293 assert_select 'th.line-num:contains(22) ~ td.diff_out', :text => /def remove/
297 294 assert_select 'h2', :text => /4:def6d2f1254a/
298 295 end
299 296 end
300 297 end
301 298 end
302 299
303 300 def test_diff_two_revs
304 301 assert_equal 0, @repository.changesets.count
305 302 @repository.fetch_changesets
306 303 @project.reload
307 304 assert_equal NUM_REV, @repository.changesets.count
308 305 [2, '400bb8672109', '400', 400].each do |r1|
309 306 [4, 'def6d2f1254a'].each do |r2|
310 307 ['inline', 'sbs'].each do |dt|
311 308 get :diff,
312 309 :id => PRJ_ID,
313 310 :rev => r1,
314 311 :rev_to => r2,
315 312 :type => dt
316 313 assert_response :success
317 314 assert_template 'diff'
318 315 diff = assigns(:diff)
319 316 assert_not_nil diff
320 317 assert_select 'h2', :text => /4:def6d2f1254a 2:400bb8672109/
321 318 end
322 319 end
323 320 end
324 321 end
325 322
326 323 def test_diff_latin_1_path
327 324 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
328 325 [21, 'adf805632193'].each do |r1|
329 326 ['inline', 'sbs'].each do |dt|
330 327 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
331 328 assert_response :success
332 329 assert_template 'diff'
333 330 assert_select 'table' do
334 331 assert_select 'thead th.filename', :text => /latin-1-dir\/test-#{@char_1}-2.txt/
335 332 assert_select 'tbody td.diff_in', :text => /It is written in Python/
336 333 end
337 334 end
338 335 end
339 336 end
340 337 end
341 338
342 339 def test_diff_should_show_modified_filenames
343 340 get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline'
344 341 assert_response :success
345 342 assert_template 'diff'
346 343 assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
347 344 end
348 345
349 346 def test_diff_should_show_deleted_filenames
350 347 get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline'
351 348 assert_response :success
352 349 assert_template 'diff'
353 350 assert_select 'th.filename', :text => 'sources/welcome_controller.rb'
354 351 end
355 352
356 353 def test_annotate
357 354 get :annotate, :id => PRJ_ID,
358 355 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
359 356 assert_response :success
360 357 assert_template 'annotate'
361 358
362 359 # Line 22, revision 4:def6d2f1254a
363 360 assert_select 'tr' do
364 361 assert_select 'th.line-num', :text => '22'
365 362 assert_select 'td.revision', :text => '4:def6d2f1254a'
366 363 assert_select 'td.author', :text => 'jsmith'
367 364 assert_select 'td', :text => /remove_watcher/
368 365 end
369 366 end
370 367
371 368 def test_annotate_not_in_tip
372 369 assert_equal 0, @repository.changesets.count
373 370 @repository.fetch_changesets
374 371 @project.reload
375 372 assert_equal NUM_REV, @repository.changesets.count
376 373 get :annotate, :id => PRJ_ID,
377 374 :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param]
378 375 assert_response 404
379 376 assert_select_error /was not found/
380 377 end
381 378
382 379 def test_annotate_at_given_revision
383 380 assert_equal 0, @repository.changesets.count
384 381 @repository.fetch_changesets
385 382 @project.reload
386 383 assert_equal NUM_REV, @repository.changesets.count
387 384 [2, '400bb8672109', '400', 400].each do |r1|
388 385 get :annotate, :id => PRJ_ID, :rev => r1,
389 386 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
390 387 assert_response :success
391 388 assert_template 'annotate'
392 389 assert_select 'h2', :text => /@ 2:400bb8672109/
393 390 end
394 391 end
395 392
396 393 def test_annotate_latin_1_path
397 394 [21, '21', 'adf805632193'].each do |r1|
398 395 get :annotate, :id => PRJ_ID,
399 396 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param],
400 397 :rev => r1
401 398 assert_response :success
402 399 assert_template 'annotate'
403 400 assert_select "th.line-num", :text => '1' do
404 401 assert_select "+ td.revision" do
405 402 assert_select "a", :text => '20:709858aafd1b'
406 403 assert_select "+ td.author", :text => "jsmith" do
407 404 assert_select "+ td",
408 405 :text => "Mercurial is a distributed version control system."
409 406 end
410 407 end
411 408 end
412 409 end
413 410 end
414 411
415 412 def test_annotate_latin_1_contents
416 413 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
417 414 [27, '7bbf4c738e71'].each do |r1|
418 415 get :annotate, :id => PRJ_ID,
419 416 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
420 417 :rev => r1
421 418 assert_select 'tr#L1 td.line-code', :text => /test-#{@char_1}.txt/
422 419 end
423 420 end
424 421 end
425 422
426 423 def test_revision
427 424 assert_equal 0, @repository.changesets.count
428 425 @repository.fetch_changesets
429 426 @project.reload
430 427 assert_equal NUM_REV, @repository.changesets.count
431 428 ['1', '9d5b5b', '9d5b5b004199'].each do |r|
432 429 with_settings :default_language => "en" do
433 430 get :revision, :id => PRJ_ID, :rev => r
434 431 assert_response :success
435 432 assert_template 'revision'
436 433 assert_select 'title',
437 434 :text => 'Revision 1:9d5b5b004199 - Added 2 files and modified one. - eCookbook Subproject 1 - Redmine'
438 435 end
439 436 end
440 437 end
441 438
442 439 def test_empty_revision
443 440 assert_equal 0, @repository.changesets.count
444 441 @repository.fetch_changesets
445 442 @project.reload
446 443 assert_equal NUM_REV, @repository.changesets.count
447 444 ['', ' ', nil].each do |r|
448 445 get :revision, :id => PRJ_ID, :rev => r
449 446 assert_response 404
450 447 assert_select_error /was not found/
451 448 end
452 449 end
453 450
454 451 def test_destroy_valid_repository
455 452 @request.session[:user_id] = 1 # admin
456 453 assert_equal 0, @repository.changesets.count
457 454 @repository.fetch_changesets
458 455 assert_equal NUM_REV, @repository.changesets.count
459 456
460 457 assert_difference 'Repository.count', -1 do
461 458 delete :destroy, :id => @repository.id
462 459 end
463 460 assert_response 302
464 461 @project.reload
465 462 assert_nil @project.repository
466 463 end
467 464
468 465 def test_destroy_invalid_repository
469 466 @request.session[:user_id] = 1 # admin
470 467 @project.repository.destroy
471 468 @repository = Repository::Mercurial.create!(
472 469 :project => Project.find(PRJ_ID),
473 470 :url => "/invalid",
474 471 :path_encoding => 'ISO-8859-1'
475 472 )
476 473 @repository.fetch_changesets
477 474 assert_equal 0, @repository.changesets.count
478 475
479 476 assert_difference 'Repository.count', -1 do
480 477 delete :destroy, :id => @repository.id
481 478 end
482 479 assert_response 302
483 480 @project.reload
484 481 assert_nil @project.repository
485 482 end
486 483 else
487 484 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
488 485 def test_fake; assert true end
489 486 end
490 487 end
@@ -1,421 +1,421
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2016 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
20 20 class RepositoriesSubversionControllerTest < ActionController::TestCase
21 21 tests RepositoriesController
22 22
23 23 fixtures :projects, :users, :email_addresses, :roles, :members, :member_roles, :enabled_modules,
24 24 :repositories, :issues, :issue_statuses, :changesets, :changes,
25 25 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
26 26
27 27 PRJ_ID = 3
28 28 NUM_REV = 11
29 29
30 30 def setup
31 31 Setting.default_language = 'en'
32 32 User.current = nil
33 33
34 34 @project = Project.find(PRJ_ID)
35 35 @repository = Repository::Subversion.create(:project => @project,
36 36 :url => self.class.subversion_repository_url)
37 37 assert @repository
38 38 end
39 39
40 40 if repository_configured?('subversion')
41 41 def test_new
42 42 @request.session[:user_id] = 1
43 43 @project.repository.destroy
44 44 get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
45 45 assert_response :success
46 46 assert_template 'new'
47 47 assert_kind_of Repository::Subversion, assigns(:repository)
48 48 assert assigns(:repository).new_record?
49 49 end
50 50
51 51 def test_show
52 52 assert_equal 0, @repository.changesets.count
53 53 @repository.fetch_changesets
54 54 @project.reload
55 55 assert_equal NUM_REV, @repository.changesets.count
56 56 get :show, :id => PRJ_ID
57 57 assert_response :success
58 58 assert_template 'show'
59 59 assert_not_nil assigns(:entries)
60 60 assert_not_nil assigns(:changesets)
61 61
62 62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
63 63 assert_not_nil entry
64 64 assert_equal 'dir', entry.kind
65 65 assert_select 'tr.dir a[href="/projects/subproject1/repository/show/subversion_test"]'
66 66
67 67 assert_select 'input[name=rev]'
68 68 assert_select 'a', :text => 'Statistics'
69 69 assert_select 'a', :text => 'Atom'
70 70 assert_select 'a[href=?]', '/projects/subproject1/repository', :text => 'root'
71 71 end
72 72
73 73 def test_show_non_default
74 74 Repository::Subversion.create(:project => @project,
75 75 :url => self.class.subversion_repository_url,
76 76 :is_default => false, :identifier => 'svn')
77 77
78 78 get :show, :id => PRJ_ID, :repository_id => 'svn'
79 79 assert_response :success
80 80 assert_template 'show'
81 81 assert_select 'tr.dir a[href="/projects/subproject1/repository/svn/show/subversion_test"]'
82 82 # Repository menu should link to the main repo
83 83 assert_select '#main-menu a[href="/projects/subproject1/repository"]'
84 84 end
85 85
86 86 def test_browse_directory
87 87 assert_equal 0, @repository.changesets.count
88 88 @repository.fetch_changesets
89 89 @project.reload
90 90 assert_equal NUM_REV, @repository.changesets.count
91 91 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
92 92 assert_response :success
93 93 assert_template 'show'
94 94 assert_not_nil assigns(:entries)
95 95 assert_equal [
96 96 '[folder_with_brackets]', 'folder', '.project',
97 97 'helloworld.c', 'textfile.txt'
98 98 ],
99 99 assigns(:entries).collect(&:name)
100 100 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
101 101 assert_equal 'file', entry.kind
102 102 assert_equal 'subversion_test/helloworld.c', entry.path
103 103 assert_select 'a.text-x-c', :text => 'helloworld.c'
104 104 end
105 105
106 106 def test_browse_at_given_revision
107 107 assert_equal 0, @repository.changesets.count
108 108 @repository.fetch_changesets
109 109 @project.reload
110 110 assert_equal NUM_REV, @repository.changesets.count
111 111 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
112 112 :rev => 4
113 113 assert_response :success
114 114 assert_template 'show'
115 115 assert_not_nil assigns(:entries)
116 116 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
117 117 assigns(:entries).collect(&:name)
118 118 end
119 119
120 120 def test_file_changes
121 121 assert_equal 0, @repository.changesets.count
122 122 @repository.fetch_changesets
123 123 @project.reload
124 124 assert_equal NUM_REV, @repository.changesets.count
125 125 get :changes, :id => PRJ_ID,
126 126 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
127 127 assert_response :success
128 128 assert_template 'changes'
129 129
130 130 changesets = assigns(:changesets)
131 131 assert_not_nil changesets
132 132 assert_equal %w(6 3 2), changesets.collect(&:revision)
133 133
134 134 # svn properties displayed with svn >= 1.5 only
135 135 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
136 136 assert_not_nil assigns(:properties)
137 137 assert_equal 'native', assigns(:properties)['svn:eol-style']
138 138 assert_select 'ul li' do
139 139 assert_select 'b', :text => 'svn:eol-style'
140 140 assert_select 'span', :text => 'native'
141 141 end
142 142 end
143 143 end
144 144
145 145 def test_directory_changes
146 146 assert_equal 0, @repository.changesets.count
147 147 @repository.fetch_changesets
148 148 @project.reload
149 149 assert_equal NUM_REV, @repository.changesets.count
150 150 get :changes, :id => PRJ_ID,
151 151 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
152 152 assert_response :success
153 153 assert_template 'changes'
154 154
155 155 changesets = assigns(:changesets)
156 156 assert_not_nil changesets
157 157 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
158 158 end
159 159
160 160 def test_entry
161 161 assert_equal 0, @repository.changesets.count
162 162 @repository.fetch_changesets
163 163 @project.reload
164 164 assert_equal NUM_REV, @repository.changesets.count
165 165 get :entry, :id => PRJ_ID,
166 166 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
167 167 assert_response :success
168 168 assert_template 'entry'
169 169 end
170 170
171 171 def test_entry_should_send_if_too_big
172 172 assert_equal 0, @repository.changesets.count
173 173 @repository.fetch_changesets
174 174 @project.reload
175 175 assert_equal NUM_REV, @repository.changesets.count
176 176 # no files in the test repo is larger than 1KB...
177 177 with_settings :file_max_size_displayed => 0 do
178 178 get :entry, :id => PRJ_ID,
179 179 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
180 180 assert_response :success
181 181 assert_equal 'attachment; filename="helloworld.c"',
182 182 @response.headers['Content-Disposition']
183 183 end
184 184 end
185 185
186 def test_entry_should_send_images_inline
186 def test_entry_should_display_images
187 187 get :entry, :id => PRJ_ID,
188 188 :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
189 189 assert_response :success
190 assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition']
190 assert_template 'entry'
191 191 end
192 192
193 193 def test_entry_at_given_revision
194 194 assert_equal 0, @repository.changesets.count
195 195 @repository.fetch_changesets
196 196 @project.reload
197 197 assert_equal NUM_REV, @repository.changesets.count
198 198 get :entry, :id => PRJ_ID,
199 199 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
200 200 :rev => 2
201 201 assert_response :success
202 202 assert_template 'entry'
203 203 # this line was removed in r3 and file was moved in r6
204 204 assert_select 'td.line-code', :text => /Here's the code/
205 205 end
206 206
207 207 def test_entry_not_found
208 208 assert_equal 0, @repository.changesets.count
209 209 @repository.fetch_changesets
210 210 @project.reload
211 211 assert_equal NUM_REV, @repository.changesets.count
212 212 get :entry, :id => PRJ_ID,
213 213 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
214 214 assert_select 'p#errorExplanation', :text => /The entry or revision was not found in the repository/
215 215 end
216 216
217 217 def test_entry_download
218 218 assert_equal 0, @repository.changesets.count
219 219 @repository.fetch_changesets
220 220 @project.reload
221 221 assert_equal NUM_REV, @repository.changesets.count
222 222 get :raw, :id => PRJ_ID,
223 223 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
224 224 assert_response :success
225 225 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
226 226 end
227 227
228 228 def test_directory_entry
229 229 assert_equal 0, @repository.changesets.count
230 230 @repository.fetch_changesets
231 231 @project.reload
232 232 assert_equal NUM_REV, @repository.changesets.count
233 233 get :entry, :id => PRJ_ID,
234 234 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
235 235 assert_response :success
236 236 assert_template 'show'
237 237 assert_not_nil assigns(:entry)
238 238 assert_equal 'folder', assigns(:entry).name
239 239 end
240 240
241 241 # TODO: this test needs fixtures.
242 242 def test_revision
243 243 get :revision, :id => 1, :rev => 2
244 244 assert_response :success
245 245 assert_template 'revision'
246 246
247 247 assert_select 'ul' do
248 248 assert_select 'li' do
249 249 # link to the entry at rev 2
250 250 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo'
251 251 # link to partial diff
252 252 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo'
253 253 end
254 254 end
255 255 end
256 256
257 257 def test_invalid_revision
258 258 assert_equal 0, @repository.changesets.count
259 259 @repository.fetch_changesets
260 260 @project.reload
261 261 assert_equal NUM_REV, @repository.changesets.count
262 262 get :revision, :id => PRJ_ID, :rev => 'something_weird'
263 263 assert_response 404
264 264 assert_select_error /was not found/
265 265 end
266 266
267 267 def test_invalid_revision_diff
268 268 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
269 269 assert_response 404
270 270 assert_select_error /was not found/
271 271 end
272 272
273 273 def test_empty_revision
274 274 assert_equal 0, @repository.changesets.count
275 275 @repository.fetch_changesets
276 276 @project.reload
277 277 assert_equal NUM_REV, @repository.changesets.count
278 278 ['', ' ', nil].each do |r|
279 279 get :revision, :id => PRJ_ID, :rev => r
280 280 assert_response 404
281 281 assert_select_error /was not found/
282 282 end
283 283 end
284 284
285 285 # TODO: this test needs fixtures.
286 286 def test_revision_with_repository_pointing_to_a_subdirectory
287 287 r = Project.find(1).repository
288 288 # Changes repository url to a subdirectory
289 289 r.update_attribute :url, (r.url + '/test/some')
290 290
291 291 get :revision, :id => 1, :rev => 2
292 292 assert_response :success
293 293 assert_template 'revision'
294 294
295 295 assert_select 'ul' do
296 296 assert_select 'li' do
297 297 # link to the entry at rev 2
298 298 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo', :text => 'repo'
299 299 # link to partial diff
300 300 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo'
301 301 end
302 302 end
303 303 end
304 304
305 305 def test_revision_diff
306 306 assert_equal 0, @repository.changesets.count
307 307 @repository.fetch_changesets
308 308 @project.reload
309 309 assert_equal NUM_REV, @repository.changesets.count
310 310 ['inline', 'sbs'].each do |dt|
311 311 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
312 312 assert_response :success
313 313 assert_template 'diff'
314 314 assert_select 'h2', :text => /Revision 3/
315 315 assert_select 'th.filename', :text => 'subversion_test/textfile.txt'
316 316 end
317 317 end
318 318
319 319 def test_revision_diff_raw_format
320 320 assert_equal 0, @repository.changesets.count
321 321 @repository.fetch_changesets
322 322 @project.reload
323 323 assert_equal NUM_REV, @repository.changesets.count
324 324
325 325 get :diff, :id => PRJ_ID, :rev => 5, :format => 'diff'
326 326 assert_response :success
327 327 assert_equal 'text/x-patch', @response.content_type
328 328 assert_equal 'Index: subversion_test/folder/greeter.rb', @response.body.split(/\r?\n/).first
329 329 end
330 330
331 331 def test_directory_diff
332 332 assert_equal 0, @repository.changesets.count
333 333 @repository.fetch_changesets
334 334 @project.reload
335 335 assert_equal NUM_REV, @repository.changesets.count
336 336 ['inline', 'sbs'].each do |dt|
337 337 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
338 338 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
339 339 :type => dt
340 340 assert_response :success
341 341 assert_template 'diff'
342 342
343 343 diff = assigns(:diff)
344 344 assert_not_nil diff
345 345 # 2 files modified
346 346 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
347 347 assert_select 'h2', :text => /2:6/
348 348 end
349 349 end
350 350
351 351 def test_annotate
352 352 assert_equal 0, @repository.changesets.count
353 353 @repository.fetch_changesets
354 354 @project.reload
355 355 assert_equal NUM_REV, @repository.changesets.count
356 356 get :annotate, :id => PRJ_ID,
357 357 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
358 358 assert_response :success
359 359 assert_template 'annotate'
360 360
361 361 assert_select 'tr' do
362 362 assert_select 'th.line-num', :text => '1'
363 363 assert_select 'td.revision', :text => '4'
364 364 assert_select 'td.author', :text => 'jp'
365 365 assert_select 'td', :text => /stdio.h/
366 366 end
367 367 # Same revision
368 368 assert_select 'tr' do
369 369 assert_select 'th.line-num', :text => '2'
370 370 assert_select 'td.revision', :text => ''
371 371 assert_select 'td.author', :text => ''
372 372 end
373 373 end
374 374
375 375 def test_annotate_at_given_revision
376 376 assert_equal 0, @repository.changesets.count
377 377 @repository.fetch_changesets
378 378 @project.reload
379 379 assert_equal NUM_REV, @repository.changesets.count
380 380 get :annotate, :id => PRJ_ID, :rev => 8,
381 381 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
382 382 assert_response :success
383 383 assert_template 'annotate'
384 384 assert_select 'h2', :text => /@ 8/
385 385 end
386 386
387 387 def test_destroy_valid_repository
388 388 @request.session[:user_id] = 1 # admin
389 389 assert_equal 0, @repository.changesets.count
390 390 @repository.fetch_changesets
391 391 assert_equal NUM_REV, @repository.changesets.count
392 392
393 393 assert_difference 'Repository.count', -1 do
394 394 delete :destroy, :id => @repository.id
395 395 end
396 396 assert_response 302
397 397 @project.reload
398 398 assert_nil @project.repository
399 399 end
400 400
401 401 def test_destroy_invalid_repository
402 402 @request.session[:user_id] = 1 # admin
403 403 @project.repository.destroy
404 404 @repository = Repository::Subversion.create!(
405 405 :project => @project,
406 406 :url => "file:///invalid")
407 407 @repository.fetch_changesets
408 408 assert_equal 0, @repository.changesets.count
409 409
410 410 assert_difference 'Repository.count', -1 do
411 411 delete :destroy, :id => @repository.id
412 412 end
413 413 assert_response 302
414 414 @project.reload
415 415 assert_nil @project.repository
416 416 end
417 417 else
418 418 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
419 419 def test_fake; assert true end
420 420 end
421 421 end
General Comments 0
You need to be logged in to leave comments. Login now