comparison test/functional/repositories_subversion_controller_test.rb @ 1115:433d4f72a19b redmine-2.2

Update to Redmine SVN revision 11137 on 2.2-stable branch
author Chris Cannam
date Mon, 07 Jan 2013 12:01:42 +0000
parents cbb26bc654de
children 622f24f53b42 261b3d9a4903
comparison
equal deleted inserted replaced
929:5f33065ddc4b 1115:433d4f72a19b
1 # Redmine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller'
20
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
23 19
24 class RepositoriesSubversionControllerTest < ActionController::TestCase 20 class RepositoriesSubversionControllerTest < ActionController::TestCase
21 tests RepositoriesController
22
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, 23 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules,
26 :repositories, :issues, :issue_statuses, :changesets, :changes, 24 :repositories, :issues, :issue_statuses, :changesets, :changes,
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers 25 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers
28 26
29 PRJ_ID = 3 27 PRJ_ID = 3
30 NUM_REV = 11 28 NUM_REV = 11
31 29
32 def setup 30 def setup
33 @controller = RepositoriesController.new
34 @request = ActionController::TestRequest.new
35 @response = ActionController::TestResponse.new
36 Setting.default_language = 'en' 31 Setting.default_language = 'en'
37 User.current = nil 32 User.current = nil
38 33
39 @project = Project.find(PRJ_ID) 34 @project = Project.find(PRJ_ID)
40 @repository = Repository::Subversion.create(:project => @project, 35 @repository = Repository::Subversion.create(:project => @project,
41 :url => self.class.subversion_repository_url) 36 :url => self.class.subversion_repository_url)
42 assert @repository 37 assert @repository
43 end 38 end
44 39
45 if repository_configured?('subversion') 40 if repository_configured?('subversion')
41 def test_new
42 @request.session[:user_id] = 1
43 @project.repository.destroy
44 get :new, :project_id => 'subproject1', :repository_scm => 'Subversion'
45 assert_response :success
46 assert_template 'new'
47 assert_kind_of Repository::Subversion, assigns(:repository)
48 assert assigns(:repository).new_record?
49 end
50
46 def test_show 51 def test_show
47 assert_equal 0, @repository.changesets.count 52 assert_equal 0, @repository.changesets.count
48 @repository.fetch_changesets 53 @repository.fetch_changesets
49 @project.reload 54 @project.reload
50 assert_equal NUM_REV, @repository.changesets.count 55 assert_equal NUM_REV, @repository.changesets.count
51 get :show, :id => PRJ_ID 56 get :show, :id => PRJ_ID
52 assert_response :success 57 assert_response :success
53 assert_template 'show' 58 assert_template 'show'
54 assert_not_nil assigns(:entries) 59 assert_not_nil assigns(:entries)
55 assert_not_nil assigns(:changesets) 60 assert_not_nil assigns(:changesets)
56 end 61
57 62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
58 def test_browse_root 63 assert_not_nil entry
59 assert_equal 0, @repository.changesets.count 64 assert_equal 'dir', entry.kind
60 @repository.fetch_changesets 65 assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]'
61 @project.reload 66
62 assert_equal NUM_REV, @repository.changesets.count 67 assert_tag 'input', :attributes => {:name => 'rev'}
63 get :show, :id => PRJ_ID 68 assert_tag 'a', :content => 'Statistics'
69 assert_tag 'a', :content => 'Atom'
70 assert_tag :tag => 'a',
71 :attributes => {:href => '/projects/subproject1/repository'},
72 :content => 'root'
73 end
74
75 def test_show_non_default
76 Repository::Subversion.create(:project => @project,
77 :url => self.class.subversion_repository_url,
78 :is_default => false, :identifier => 'svn')
79
80 get :show, :id => PRJ_ID, :repository_id => 'svn'
64 assert_response :success 81 assert_response :success
65 assert_template 'show' 82 assert_template 'show'
66 assert_not_nil assigns(:entries) 83 assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]'
67 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} 84 # Repository menu should link to the main repo
68 assert_equal 'dir', entry.kind 85 assert_select '#main-menu a[href=/projects/subproject1/repository]'
69 end 86 end
70 87
71 def test_browse_directory 88 def test_browse_directory
72 assert_equal 0, @repository.changesets.count 89 assert_equal 0, @repository.changesets.count
73 @repository.fetch_changesets 90 @repository.fetch_changesets
74 @project.reload 91 @project.reload
75 assert_equal NUM_REV, @repository.changesets.count 92 assert_equal NUM_REV, @repository.changesets.count
76 get :show, :id => PRJ_ID, :path => ['subversion_test'] 93 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param]
77 assert_response :success 94 assert_response :success
78 assert_template 'show' 95 assert_template 'show'
79 assert_not_nil assigns(:entries) 96 assert_not_nil assigns(:entries)
80 assert_equal [ 97 assert_equal [
81 '[folder_with_brackets]', 'folder', '.project', 98 '[folder_with_brackets]', 'folder', '.project',
91 def test_browse_at_given_revision 108 def test_browse_at_given_revision
92 assert_equal 0, @repository.changesets.count 109 assert_equal 0, @repository.changesets.count
93 @repository.fetch_changesets 110 @repository.fetch_changesets
94 @project.reload 111 @project.reload
95 assert_equal NUM_REV, @repository.changesets.count 112 assert_equal NUM_REV, @repository.changesets.count
96 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4 113 get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param],
114 :rev => 4
97 assert_response :success 115 assert_response :success
98 assert_template 'show' 116 assert_template 'show'
99 assert_not_nil assigns(:entries) 117 assert_not_nil assigns(:entries)
100 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], 118 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
101 assigns(:entries).collect(&:name) 119 assigns(:entries).collect(&:name)
104 def test_file_changes 122 def test_file_changes
105 assert_equal 0, @repository.changesets.count 123 assert_equal 0, @repository.changesets.count
106 @repository.fetch_changesets 124 @repository.fetch_changesets
107 @project.reload 125 @project.reload
108 assert_equal NUM_REV, @repository.changesets.count 126 assert_equal NUM_REV, @repository.changesets.count
109 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ] 127 get :changes, :id => PRJ_ID,
128 :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param]
110 assert_response :success 129 assert_response :success
111 assert_template 'changes' 130 assert_template 'changes'
112 131
113 changesets = assigns(:changesets) 132 changesets = assigns(:changesets)
114 assert_not_nil changesets 133 assert_not_nil changesets
128 def test_directory_changes 147 def test_directory_changes
129 assert_equal 0, @repository.changesets.count 148 assert_equal 0, @repository.changesets.count
130 @repository.fetch_changesets 149 @repository.fetch_changesets
131 @project.reload 150 @project.reload
132 assert_equal NUM_REV, @repository.changesets.count 151 assert_equal NUM_REV, @repository.changesets.count
133 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ] 152 get :changes, :id => PRJ_ID,
153 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
134 assert_response :success 154 assert_response :success
135 assert_template 'changes' 155 assert_template 'changes'
136 156
137 changesets = assigns(:changesets) 157 changesets = assigns(:changesets)
138 assert_not_nil changesets 158 assert_not_nil changesets
142 def test_entry 162 def test_entry
143 assert_equal 0, @repository.changesets.count 163 assert_equal 0, @repository.changesets.count
144 @repository.fetch_changesets 164 @repository.fetch_changesets
145 @project.reload 165 @project.reload
146 assert_equal NUM_REV, @repository.changesets.count 166 assert_equal NUM_REV, @repository.changesets.count
147 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] 167 get :entry, :id => PRJ_ID,
168 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
148 assert_response :success 169 assert_response :success
149 assert_template 'entry' 170 assert_template 'entry'
150 end 171 end
151 172
152 def test_entry_should_send_if_too_big 173 def test_entry_should_send_if_too_big
154 @repository.fetch_changesets 175 @repository.fetch_changesets
155 @project.reload 176 @project.reload
156 assert_equal NUM_REV, @repository.changesets.count 177 assert_equal NUM_REV, @repository.changesets.count
157 # no files in the test repo is larger than 1KB... 178 # no files in the test repo is larger than 1KB...
158 with_settings :file_max_size_displayed => 0 do 179 with_settings :file_max_size_displayed => 0 do
159 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] 180 get :entry, :id => PRJ_ID,
181 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
160 assert_response :success 182 assert_response :success
161 assert_template ''
162 assert_equal 'attachment; filename="helloworld.c"', 183 assert_equal 'attachment; filename="helloworld.c"',
163 @response.headers['Content-Disposition'] 184 @response.headers['Content-Disposition']
164 end 185 end
165 end 186 end
166 187
188 def test_entry_should_send_images_inline
189 get :entry, :id => PRJ_ID,
190 :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param]
191 assert_response :success
192 assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition']
193 end
194
167 def test_entry_at_given_revision 195 def test_entry_at_given_revision
168 assert_equal 0, @repository.changesets.count 196 assert_equal 0, @repository.changesets.count
169 @repository.fetch_changesets 197 @repository.fetch_changesets
170 @project.reload 198 @project.reload
171 assert_equal NUM_REV, @repository.changesets.count 199 assert_equal NUM_REV, @repository.changesets.count
172 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 200 get :entry, :id => PRJ_ID,
201 :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param],
202 :rev => 2
173 assert_response :success 203 assert_response :success
174 assert_template 'entry' 204 assert_template 'entry'
175 # this line was removed in r3 and file was moved in r6 205 # this line was removed in r3 and file was moved in r6
176 assert_tag :tag => 'td', :attributes => { :class => /line-code/}, 206 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
177 :content => /Here's the code/ 207 :content => /Here's the code/
180 def test_entry_not_found 210 def test_entry_not_found
181 assert_equal 0, @repository.changesets.count 211 assert_equal 0, @repository.changesets.count
182 @repository.fetch_changesets 212 @repository.fetch_changesets
183 @project.reload 213 @project.reload
184 assert_equal NUM_REV, @repository.changesets.count 214 assert_equal NUM_REV, @repository.changesets.count
185 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c'] 215 get :entry, :id => PRJ_ID,
216 :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param]
186 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, 217 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
187 :content => /The entry or revision was not found in the repository/ 218 :content => /The entry or revision was not found in the repository/
188 end 219 end
189 220
190 def test_entry_download 221 def test_entry_download
191 assert_equal 0, @repository.changesets.count 222 assert_equal 0, @repository.changesets.count
192 @repository.fetch_changesets 223 @repository.fetch_changesets
193 @project.reload 224 @project.reload
194 assert_equal NUM_REV, @repository.changesets.count 225 assert_equal NUM_REV, @repository.changesets.count
195 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' 226 get :raw, :id => PRJ_ID,
196 assert_response :success 227 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
197 assert_template '' 228 assert_response :success
198 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] 229 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
199 end 230 end
200 231
201 def test_directory_entry 232 def test_directory_entry
202 assert_equal 0, @repository.changesets.count 233 assert_equal 0, @repository.changesets.count
203 @repository.fetch_changesets 234 @repository.fetch_changesets
204 @project.reload 235 @project.reload
205 assert_equal NUM_REV, @repository.changesets.count 236 assert_equal NUM_REV, @repository.changesets.count
206 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder'] 237 get :entry, :id => PRJ_ID,
238 :path => repository_path_hash(['subversion_test', 'folder'])[:param]
207 assert_response :success 239 assert_response :success
208 assert_template 'show' 240 assert_template 'show'
209 assert_not_nil assigns(:entry) 241 assert_not_nil assigns(:entry)
210 assert_equal 'folder', assigns(:entry).name 242 assert_equal 'folder', assigns(:entry).name
211 end 243 end
213 # TODO: this test needs fixtures. 245 # TODO: this test needs fixtures.
214 def test_revision 246 def test_revision
215 get :revision, :id => 1, :rev => 2 247 get :revision, :id => 1, :rev => 2
216 assert_response :success 248 assert_response :success
217 assert_template 'revision' 249 assert_template 'revision'
218 assert_tag :tag => 'ul', 250
219 :child => { :tag => 'li', 251 assert_select 'ul' do
220 # link to the entry at rev 2 252 assert_select 'li' do
221 :child => { :tag => 'a', 253 # link to the entry at rev 2
222 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, 254 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo'
223 :content => 'repo', 255 # link to partial diff
224 # link to partial diff 256 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo'
225 :sibling => { :tag => 'a', 257 end
226 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } 258 end
227 }
228 }
229 }
230 end 259 end
231 260
232 def test_invalid_revision 261 def test_invalid_revision
233 assert_equal 0, @repository.changesets.count 262 assert_equal 0, @repository.changesets.count
234 @repository.fetch_changesets 263 @repository.fetch_changesets
264 r.update_attribute :url, (r.url + '/test/some') 293 r.update_attribute :url, (r.url + '/test/some')
265 294
266 get :revision, :id => 1, :rev => 2 295 get :revision, :id => 1, :rev => 2
267 assert_response :success 296 assert_response :success
268 assert_template 'revision' 297 assert_template 'revision'
269 assert_tag :tag => 'ul', 298
270 :child => { :tag => 'li', 299 assert_select 'ul' do
271 # link to the entry at rev 2 300 assert_select 'li' do
272 :child => { :tag => 'a', 301 # link to the entry at rev 2
273 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, 302 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo', :text => 'repo'
274 :content => 'repo', 303 # link to partial diff
275 # link to partial diff 304 assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo'
276 :sibling => { :tag => 'a', 305 end
277 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } 306 end
278 }
279 }
280 }
281 end 307 end
282 308
283 def test_revision_diff 309 def test_revision_diff
284 assert_equal 0, @repository.changesets.count 310 assert_equal 0, @repository.changesets.count
285 @repository.fetch_changesets 311 @repository.fetch_changesets
287 assert_equal NUM_REV, @repository.changesets.count 313 assert_equal NUM_REV, @repository.changesets.count
288 ['inline', 'sbs'].each do |dt| 314 ['inline', 'sbs'].each do |dt|
289 get :diff, :id => PRJ_ID, :rev => 3, :type => dt 315 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
290 assert_response :success 316 assert_response :success
291 assert_template 'diff' 317 assert_template 'diff'
292 assert_tag :tag => 'h2', 318 assert_select 'h2', :text => /Revision 3/
293 :content => / 3/ 319 assert_select 'th.filename', :text => 'subversion_test/textfile.txt'
294 end 320 end
321 end
322
323 def test_revision_diff_raw_format
324 assert_equal 0, @repository.changesets.count
325 @repository.fetch_changesets
326 @project.reload
327 assert_equal NUM_REV, @repository.changesets.count
328
329 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
330 assert_response :success
331 assert_equal 'text/x-patch', @response.content_type
332 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
295 end 333 end
296 334
297 def test_directory_diff 335 def test_directory_diff
298 assert_equal 0, @repository.changesets.count 336 assert_equal 0, @repository.changesets.count
299 @repository.fetch_changesets 337 @repository.fetch_changesets
300 @project.reload 338 @project.reload
301 assert_equal NUM_REV, @repository.changesets.count 339 assert_equal NUM_REV, @repository.changesets.count
302 ['inline', 'sbs'].each do |dt| 340 ['inline', 'sbs'].each do |dt|
303 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, 341 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
304 :path => ['subversion_test', 'folder'], :type => dt 342 :path => repository_path_hash(['subversion_test', 'folder'])[:param],
343 :type => dt
305 assert_response :success 344 assert_response :success
306 assert_template 'diff' 345 assert_template 'diff'
307 346
308 diff = assigns(:diff) 347 diff = assigns(:diff)
309 assert_not_nil diff 348 assert_not_nil diff
316 def test_annotate 355 def test_annotate
317 assert_equal 0, @repository.changesets.count 356 assert_equal 0, @repository.changesets.count
318 @repository.fetch_changesets 357 @repository.fetch_changesets
319 @project.reload 358 @project.reload
320 assert_equal NUM_REV, @repository.changesets.count 359 assert_equal NUM_REV, @repository.changesets.count
321 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] 360 get :annotate, :id => PRJ_ID,
361 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
322 assert_response :success 362 assert_response :success
323 assert_template 'annotate' 363 assert_template 'annotate'
364
365 assert_select 'tr' do
366 assert_select 'th.line-num', :text => '1'
367 assert_select 'td.revision', :text => '4'
368 assert_select 'td.author', :text => 'jp'
369 assert_select 'td', :text => /stdio.h/
370 end
371 # Same revision
372 assert_select 'tr' do
373 assert_select 'th.line-num', :text => '2'
374 assert_select 'td.revision', :text => ''
375 assert_select 'td.author', :text => ''
376 end
324 end 377 end
325 378
326 def test_annotate_at_given_revision 379 def test_annotate_at_given_revision
327 assert_equal 0, @repository.changesets.count 380 assert_equal 0, @repository.changesets.count
328 @repository.fetch_changesets 381 @repository.fetch_changesets
329 @project.reload 382 @project.reload
330 assert_equal NUM_REV, @repository.changesets.count 383 assert_equal NUM_REV, @repository.changesets.count
331 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c'] 384 get :annotate, :id => PRJ_ID, :rev => 8,
385 :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param]
332 assert_response :success 386 assert_response :success
333 assert_template 'annotate' 387 assert_template 'annotate'
334 assert_tag :tag => 'h2', :content => /@ 8/ 388 assert_tag :tag => 'h2', :content => /@ 8/
335 end 389 end
336 390
337 def test_destroy_valid_repository 391 def test_destroy_valid_repository
338 @request.session[:user_id] = 1 # admin 392 @request.session[:user_id] = 1 # admin
339 assert_equal 0, @repository.changesets.count 393 assert_equal 0, @repository.changesets.count
340 @repository.fetch_changesets 394 @repository.fetch_changesets
341 @project.reload 395 assert_equal NUM_REV, @repository.changesets.count
342 assert_equal NUM_REV, @repository.changesets.count 396
343 397 assert_difference 'Repository.count', -1 do
344 get :destroy, :id => PRJ_ID 398 delete :destroy, :id => @repository.id
399 end
345 assert_response 302 400 assert_response 302
346 @project.reload 401 @project.reload
347 assert_nil @project.repository 402 assert_nil @project.repository
348 end 403 end
349 404
350 def test_destroy_invalid_repository 405 def test_destroy_invalid_repository
351 @request.session[:user_id] = 1 # admin 406 @request.session[:user_id] = 1 # admin
352 assert_equal 0, @repository.changesets.count 407 @project.repository.destroy
353 @repository.fetch_changesets 408 @repository = Repository::Subversion.create!(
354 @project.reload
355 assert_equal NUM_REV, @repository.changesets.count
356
357 get :destroy, :id => PRJ_ID
358 assert_response 302
359 @project.reload
360 assert_nil @project.repository
361
362 @repository = Repository::Subversion.create(
363 :project => @project, 409 :project => @project,
364 :url => "file:///invalid") 410 :url => "file:///invalid")
365 assert @repository 411 @repository.fetch_changesets
366 @repository.fetch_changesets 412 assert_equal 0, @repository.changesets.count
367 @project.reload 413
368 assert_equal 0, @repository.changesets.count 414 assert_difference 'Repository.count', -1 do
369 415 delete :destroy, :id => @repository.id
370 get :destroy, :id => PRJ_ID 416 end
371 assert_response 302 417 assert_response 302
372 @project.reload 418 @project.reload
373 assert_nil @project.repository 419 assert_nil @project.repository
374 end 420 end
375 else 421 else