annotate test/functional/repositories_subversion_controller_test.rb @ 853:969bb872d4bf feature_142

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