annotate .svn/pristine/9d/9d187222c850f9174b08bb5b8db4565b6a8d62a8.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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