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