annotate test/functional/repositories_subversion_controller_test.rb @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 0579821a129a
children cbce1fd3b1b7
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 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@0 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@0 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@245 30
Chris@0 31 def setup
Chris@0 32 @controller = RepositoriesController.new
Chris@0 33 @request = ActionController::TestRequest.new
Chris@0 34 @response = ActionController::TestResponse.new
Chris@0 35 Setting.default_language = 'en'
Chris@0 36 User.current = nil
Chris@245 37
Chris@245 38 @project = Project.find(PRJ_ID)
Chris@245 39 @repository = Repository::Subversion.create(:project => @project,
Chris@245 40 :url => "file://#{self.class.repository_path('subversion')}")
Chris@245 41 assert @repository
Chris@0 42 end
Chris@0 43
Chris@0 44 if repository_configured?('subversion')
Chris@0 45 def test_show
Chris@245 46 @repository.fetch_changesets
Chris@245 47 @repository.reload
Chris@245 48 get :show, :id => PRJ_ID
Chris@0 49 assert_response :success
Chris@0 50 assert_template 'show'
Chris@0 51 assert_not_nil assigns(:entries)
Chris@0 52 assert_not_nil assigns(:changesets)
Chris@0 53 end
Chris@0 54
Chris@0 55 def test_browse_root
Chris@245 56 @repository.fetch_changesets
Chris@245 57 @repository.reload
Chris@245 58 get :show, :id => PRJ_ID
Chris@0 59 assert_response :success
Chris@0 60 assert_template 'show'
Chris@0 61 assert_not_nil assigns(:entries)
Chris@0 62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
Chris@0 63 assert_equal 'dir', entry.kind
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_browse_directory
Chris@245 67 @repository.fetch_changesets
Chris@245 68 @repository.reload
Chris@245 69 get :show, :id => PRJ_ID, :path => ['subversion_test']
Chris@0 70 assert_response :success
Chris@0 71 assert_template 'show'
Chris@0 72 assert_not_nil assigns(:entries)
Chris@0 73 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name)
Chris@0 74 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
Chris@0 75 assert_equal 'file', entry.kind
Chris@0 76 assert_equal 'subversion_test/helloworld.c', entry.path
Chris@0 77 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
Chris@0 78 end
Chris@0 79
Chris@0 80 def test_browse_at_given_revision
Chris@245 81 @repository.fetch_changesets
Chris@245 82 @repository.reload
Chris@245 83 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4
Chris@0 84 assert_response :success
Chris@0 85 assert_template 'show'
Chris@0 86 assert_not_nil assigns(:entries)
Chris@0 87 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name)
Chris@0 88 end
Chris@0 89
Chris@0 90 def test_file_changes
Chris@245 91 @repository.fetch_changesets
Chris@245 92 @repository.reload
Chris@245 93 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
Chris@0 94 assert_response :success
Chris@0 95 assert_template 'changes'
Chris@0 96
Chris@0 97 changesets = assigns(:changesets)
Chris@0 98 assert_not_nil changesets
Chris@0 99 assert_equal %w(6 3 2), changesets.collect(&:revision)
Chris@0 100
Chris@0 101 # svn properties displayed with svn >= 1.5 only
Chris@0 102 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
Chris@0 103 assert_not_nil assigns(:properties)
Chris@0 104 assert_equal 'native', assigns(:properties)['svn:eol-style']
Chris@0 105 assert_tag :ul,
Chris@0 106 :child => { :tag => 'li',
Chris@0 107 :child => { :tag => 'b', :content => 'svn:eol-style' },
Chris@0 108 :child => { :tag => 'span', :content => 'native' } }
Chris@0 109 end
Chris@0 110 end
Chris@0 111
Chris@0 112 def test_directory_changes
Chris@245 113 @repository.fetch_changesets
Chris@245 114 @repository.reload
Chris@245 115 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ]
Chris@0 116 assert_response :success
Chris@0 117 assert_template 'changes'
Chris@0 118
Chris@0 119 changesets = assigns(:changesets)
Chris@0 120 assert_not_nil changesets
Chris@0 121 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
Chris@0 122 end
Chris@0 123
Chris@0 124 def test_entry
Chris@245 125 @repository.fetch_changesets
Chris@245 126 @repository.reload
Chris@245 127 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
Chris@0 128 assert_response :success
Chris@0 129 assert_template 'entry'
Chris@0 130 end
Chris@0 131
Chris@0 132 def test_entry_should_send_if_too_big
Chris@245 133 @repository.fetch_changesets
Chris@245 134 @repository.reload
Chris@0 135 # no files in the test repo is larger than 1KB...
Chris@0 136 with_settings :file_max_size_displayed => 0 do
Chris@245 137 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
Chris@0 138 assert_response :success
Chris@0 139 assert_template ''
Chris@0 140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
Chris@0 141 end
Chris@0 142 end
Chris@0 143
Chris@0 144 def test_entry_at_given_revision
Chris@245 145 @repository.fetch_changesets
Chris@245 146 @repository.reload
Chris@245 147 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
Chris@0 148 assert_response :success
Chris@0 149 assert_template 'entry'
Chris@0 150 # this line was removed in r3 and file was moved in r6
Chris@0 151 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
Chris@0 152 :content => /Here's the code/
Chris@0 153 end
Chris@0 154
Chris@0 155 def test_entry_not_found
Chris@245 156 @repository.fetch_changesets
Chris@245 157 @repository.reload
Chris@245 158 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c']
chris@37 159 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
Chris@0 160 :content => /The entry or revision was not found in the repository/
Chris@0 161 end
Chris@0 162
Chris@0 163 def test_entry_download
Chris@245 164 @repository.fetch_changesets
Chris@245 165 @repository.reload
Chris@245 166 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
Chris@0 167 assert_response :success
Chris@0 168 assert_template ''
Chris@0 169 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
Chris@0 170 end
Chris@0 171
Chris@0 172 def test_directory_entry
Chris@245 173 @repository.fetch_changesets
Chris@245 174 @repository.reload
Chris@245 175 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder']
Chris@0 176 assert_response :success
Chris@0 177 assert_template 'show'
Chris@0 178 assert_not_nil assigns(:entry)
Chris@0 179 assert_equal 'folder', assigns(:entry).name
Chris@0 180 end
Chris@0 181
Chris@245 182 # TODO: this test needs fixtures.
Chris@0 183 def test_revision
Chris@245 184 @repository.fetch_changesets
Chris@245 185 @repository.reload
Chris@0 186 get :revision, :id => 1, :rev => 2
Chris@0 187 assert_response :success
Chris@0 188 assert_template 'revision'
Chris@0 189 assert_tag :tag => 'ul',
Chris@0 190 :child => { :tag => 'li',
Chris@0 191 # link to the entry at rev 2
Chris@0 192 :child => { :tag => 'a',
Chris@0 193 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
Chris@0 194 :content => 'repo',
Chris@0 195 # link to partial diff
Chris@0 196 :sibling => { :tag => 'a',
Chris@0 197 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
Chris@0 198 }
Chris@0 199 }
Chris@0 200 }
Chris@0 201 end
Chris@0 202
Chris@119 203 def test_invalid_revision
Chris@245 204 @repository.fetch_changesets
Chris@245 205 @repository.reload
Chris@245 206 get :revision, :id => PRJ_ID, :rev => 'something_weird'
Chris@245 207 assert_response 404
Chris@245 208 assert_error_tag :content => /was not found/
Chris@245 209 end
Chris@245 210
Chris@245 211 def test_invalid_revision_diff
Chris@245 212 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
Chris@128 213 assert_response 404
Chris@119 214 assert_error_tag :content => /was not found/
Chris@119 215 end
Chris@119 216
Chris@119 217 def test_empty_revision
Chris@245 218 @repository.fetch_changesets
Chris@245 219 @repository.reload
Chris@119 220 ['', ' ', nil].each do |r|
Chris@245 221 get :revision, :id => PRJ_ID, :rev => r
Chris@128 222 assert_response 404
Chris@119 223 assert_error_tag :content => /was not found/
Chris@119 224 end
Chris@119 225 end
Chris@119 226
Chris@245 227 # TODO: this test needs fixtures.
Chris@0 228 def test_revision_with_repository_pointing_to_a_subdirectory
Chris@0 229 r = Project.find(1).repository
Chris@0 230 # Changes repository url to a subdirectory
Chris@0 231 r.update_attribute :url, (r.url + '/test/some')
Chris@0 232
Chris@0 233 get :revision, :id => 1, :rev => 2
Chris@0 234 assert_response :success
Chris@0 235 assert_template 'revision'
Chris@0 236 assert_tag :tag => 'ul',
Chris@0 237 :child => { :tag => 'li',
Chris@0 238 # link to the entry at rev 2
Chris@0 239 :child => { :tag => 'a',
Chris@0 240 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
Chris@0 241 :content => 'repo',
Chris@0 242 # link to partial diff
Chris@0 243 :sibling => { :tag => 'a',
Chris@0 244 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
Chris@0 245 }
Chris@0 246 }
Chris@0 247 }
Chris@0 248 end
Chris@0 249
Chris@0 250 def test_revision_diff
Chris@245 251 @repository.fetch_changesets
Chris@245 252 @repository.reload
Chris@245 253 get :diff, :id => PRJ_ID, :rev => 3
Chris@0 254 assert_response :success
Chris@0 255 assert_template 'diff'
Chris@119 256
Chris@119 257 assert_tag :tag => 'h2', :content => /3/
Chris@0 258 end
Chris@0 259
Chris@0 260 def test_directory_diff
Chris@245 261 @repository.fetch_changesets
Chris@245 262 @repository.reload
Chris@245 263 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder']
Chris@0 264 assert_response :success
Chris@0 265 assert_template 'diff'
Chris@0 266
Chris@0 267 diff = assigns(:diff)
Chris@0 268 assert_not_nil diff
Chris@0 269 # 2 files modified
Chris@0 270 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
Chris@119 271
Chris@119 272 assert_tag :tag => 'h2', :content => /2:6/
Chris@0 273 end
Chris@0 274
Chris@0 275 def test_annotate
Chris@245 276 @repository.fetch_changesets
Chris@245 277 @repository.reload
Chris@245 278 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
Chris@0 279 assert_response :success
Chris@0 280 assert_template 'annotate'
Chris@0 281 end
Chris@210 282
Chris@210 283 def test_annotate_at_given_revision
Chris@245 284 @repository.fetch_changesets
Chris@245 285 @repository.reload
Chris@245 286 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c']
Chris@210 287 assert_response :success
Chris@210 288 assert_template 'annotate'
Chris@210 289 assert_tag :tag => 'h2', :content => /@ 8/
Chris@210 290 end
Chris@0 291 else
Chris@0 292 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 293 def test_fake; assert true end
Chris@0 294 end
Chris@0 295 end