annotate .svn/pristine/e6/e6f6e2c99bf66cc9bd128bd8915a2d8bbb8c383a.svn-base @ 1524:82fac3dcf466 redmine-2.5-integration

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