annotate test/functional/repositories_subversion_controller_test.rb @ 1082:997f6d7738f7 bug_531

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