annotate .svn/pristine/b5/b50241919b7b81279d644e95a3326c2189de1da8.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

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