annotate .svn/pristine/74/74843b67cd322d5f1fa051b32a2e14dd00a341ce.svn-base @ 1298:4f746d8966dd redmine_2.3_integration

Merge from redmine-2.3 branch to create new branch redmine-2.3-integration
author Chris Cannam
date Fri, 14 Jun 2013 09:28:30 +0100
parents 622f24f53b42
children
rev   line source
Chris@1295 1 # Redmine - project management software
Chris@1295 2 # Copyright (C) 2006-2012 Jean-Philippe Lang
Chris@1295 3 #
Chris@1295 4 # This program is free software; you can redistribute it and/or
Chris@1295 5 # modify it under the terms of the GNU General Public License
Chris@1295 6 # as published by the Free Software Foundation; either version 2
Chris@1295 7 # of the License, or (at your option) any later version.
Chris@1295 8 #
Chris@1295 9 # This program is distributed in the hope that it will be useful,
Chris@1295 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
Chris@1295 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Chris@1295 12 # GNU General Public License for more details.
Chris@1295 13 #
Chris@1295 14 # You should have received a copy of the GNU General Public License
Chris@1295 15 # along with this program; if not, write to the Free Software
Chris@1295 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
Chris@1295 17
Chris@1295 18 require File.expand_path('../../test_helper', __FILE__)
Chris@1295 19
Chris@1295 20 class RepositoriesGitControllerTest < ActionController::TestCase
Chris@1295 21 tests RepositoriesController
Chris@1295 22
Chris@1295 23 fixtures :projects, :users, :roles, :members, :member_roles,
Chris@1295 24 :repositories, :enabled_modules
Chris@1295 25
Chris@1295 26 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
Chris@1295 27 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@1295 28 PRJ_ID = 3
Chris@1295 29 CHAR_1_HEX = "\xc3\x9c"
Chris@1295 30 NUM_REV = 28
Chris@1295 31
Chris@1295 32 ## Git, Mercurial and CVS path encodings are binary.
Chris@1295 33 ## Subversion supports URL encoding for path.
Chris@1295 34 ## Redmine Mercurial adapter and extension use URL encoding.
Chris@1295 35 ## Git accepts only binary path in command line parameter.
Chris@1295 36 ## So, there is no way to use binary command line parameter in JRuby.
Chris@1295 37 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
Chris@1295 38 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
Chris@1295 39
Chris@1295 40 def setup
Chris@1295 41 @ruby19_non_utf8_pass =
Chris@1295 42 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
Chris@1295 43
Chris@1295 44 User.current = nil
Chris@1295 45 @project = Project.find(PRJ_ID)
Chris@1295 46 @repository = Repository::Git.create(
Chris@1295 47 :project => @project,
Chris@1295 48 :url => REPOSITORY_PATH,
Chris@1295 49 :path_encoding => 'ISO-8859-1'
Chris@1295 50 )
Chris@1295 51 assert @repository
Chris@1295 52 @char_1 = CHAR_1_HEX.dup
Chris@1295 53 if @char_1.respond_to?(:force_encoding)
Chris@1295 54 @char_1.force_encoding('UTF-8')
Chris@1295 55 end
Chris@1295 56 end
Chris@1295 57
Chris@1295 58 def test_create_and_update
Chris@1295 59 @request.session[:user_id] = 1
Chris@1295 60 assert_difference 'Repository.count' do
Chris@1295 61 post :create, :project_id => 'subproject1',
Chris@1295 62 :repository_scm => 'Git',
Chris@1295 63 :repository => {
Chris@1295 64 :url => '/test',
Chris@1295 65 :is_default => '0',
Chris@1295 66 :identifier => 'test-create',
Chris@1295 67 :extra_report_last_commit => '1',
Chris@1295 68 }
Chris@1295 69 end
Chris@1295 70 assert_response 302
Chris@1295 71 repository = Repository.first(:order => 'id DESC')
Chris@1295 72 assert_kind_of Repository::Git, repository
Chris@1295 73 assert_equal '/test', repository.url
Chris@1295 74 assert_equal true, repository.extra_report_last_commit
Chris@1295 75
Chris@1295 76 put :update, :id => repository.id,
Chris@1295 77 :repository => {
Chris@1295 78 :extra_report_last_commit => '0'
Chris@1295 79 }
Chris@1295 80 assert_response 302
Chris@1295 81 repo2 = Repository.find(repository.id)
Chris@1295 82 assert_equal false, repo2.extra_report_last_commit
Chris@1295 83 end
Chris@1295 84
Chris@1295 85 if File.directory?(REPOSITORY_PATH)
Chris@1295 86 ## Ruby uses ANSI api to fork a process on Windows.
Chris@1295 87 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
Chris@1295 88 ## and these are incompatible with ASCII.
Chris@1295 89 ## Git for Windows (msysGit) changed internal API from ANSI to Unicode in 1.7.10
Chris@1295 90 ## http://code.google.com/p/msysgit/issues/detail?id=80
Chris@1295 91 ## So, Latin-1 path tests fail on Japanese Windows
Chris@1295 92 WINDOWS_PASS = (Redmine::Platform.mswin? &&
Chris@1295 93 Redmine::Scm::Adapters::GitAdapter.client_version_above?([1, 7, 10]))
Chris@1295 94 WINDOWS_SKIP_STR = "TODO: This test fails in Git for Windows above 1.7.10"
Chris@1295 95
Chris@1295 96 def test_get_new
Chris@1295 97 @request.session[:user_id] = 1
Chris@1295 98 @project.repository.destroy
Chris@1295 99 get :new, :project_id => 'subproject1', :repository_scm => 'Git'
Chris@1295 100 assert_response :success
Chris@1295 101 assert_template 'new'
Chris@1295 102 assert_kind_of Repository::Git, assigns(:repository)
Chris@1295 103 assert assigns(:repository).new_record?
Chris@1295 104 end
Chris@1295 105
Chris@1295 106 def test_browse_root
Chris@1295 107 assert_equal 0, @repository.changesets.count
Chris@1295 108 @repository.fetch_changesets
Chris@1295 109 @project.reload
Chris@1295 110 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 111
Chris@1295 112 get :show, :id => PRJ_ID
Chris@1295 113 assert_response :success
Chris@1295 114 assert_template 'show'
Chris@1295 115 assert_not_nil assigns(:entries)
Chris@1295 116 assert_equal 9, assigns(:entries).size
Chris@1295 117 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@1295 118 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
Chris@1295 119 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@1295 120 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@1295 121 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
Chris@1295 122 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
Chris@1295 123 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
Chris@1295 124 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
Chris@1295 125 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
Chris@1295 126 assert_not_nil assigns(:changesets)
Chris@1295 127 assert assigns(:changesets).size > 0
Chris@1295 128 end
Chris@1295 129
Chris@1295 130 def test_browse_branch
Chris@1295 131 assert_equal 0, @repository.changesets.count
Chris@1295 132 @repository.fetch_changesets
Chris@1295 133 @project.reload
Chris@1295 134 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 135 get :show, :id => PRJ_ID, :rev => 'test_branch'
Chris@1295 136 assert_response :success
Chris@1295 137 assert_template 'show'
Chris@1295 138 assert_not_nil assigns(:entries)
Chris@1295 139 assert_equal 4, assigns(:entries).size
Chris@1295 140 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@1295 141 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@1295 142 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@1295 143 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
Chris@1295 144 assert_not_nil assigns(:changesets)
Chris@1295 145 assert assigns(:changesets).size > 0
Chris@1295 146 end
Chris@1295 147
Chris@1295 148 def test_browse_tag
Chris@1295 149 assert_equal 0, @repository.changesets.count
Chris@1295 150 @repository.fetch_changesets
Chris@1295 151 @project.reload
Chris@1295 152 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 153 [
Chris@1295 154 "tag00.lightweight",
Chris@1295 155 "tag01.annotated",
Chris@1295 156 ].each do |t1|
Chris@1295 157 get :show, :id => PRJ_ID, :rev => t1
Chris@1295 158 assert_response :success
Chris@1295 159 assert_template 'show'
Chris@1295 160 assert_not_nil assigns(:entries)
Chris@1295 161 assert assigns(:entries).size > 0
Chris@1295 162 assert_not_nil assigns(:changesets)
Chris@1295 163 assert assigns(:changesets).size > 0
Chris@1295 164 end
Chris@1295 165 end
Chris@1295 166
Chris@1295 167 def test_browse_directory
Chris@1295 168 assert_equal 0, @repository.changesets.count
Chris@1295 169 @repository.fetch_changesets
Chris@1295 170 @project.reload
Chris@1295 171 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 172 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param]
Chris@1295 173 assert_response :success
Chris@1295 174 assert_template 'show'
Chris@1295 175 assert_not_nil assigns(:entries)
Chris@1295 176 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
Chris@1295 177 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@1295 178 assert_not_nil entry
Chris@1295 179 assert_equal 'file', entry.kind
Chris@1295 180 assert_equal 'images/edit.png', entry.path
Chris@1295 181 assert_not_nil assigns(:changesets)
Chris@1295 182 assert assigns(:changesets).size > 0
Chris@1295 183 end
Chris@1295 184
Chris@1295 185 def test_browse_at_given_revision
Chris@1295 186 assert_equal 0, @repository.changesets.count
Chris@1295 187 @repository.fetch_changesets
Chris@1295 188 @project.reload
Chris@1295 189 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 190 get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param],
Chris@1295 191 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
Chris@1295 192 assert_response :success
Chris@1295 193 assert_template 'show'
Chris@1295 194 assert_not_nil assigns(:entries)
Chris@1295 195 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@1295 196 assert_not_nil assigns(:changesets)
Chris@1295 197 assert assigns(:changesets).size > 0
Chris@1295 198 end
Chris@1295 199
Chris@1295 200 def test_changes
Chris@1295 201 get :changes, :id => PRJ_ID,
Chris@1295 202 :path => repository_path_hash(['images', 'edit.png'])[:param]
Chris@1295 203 assert_response :success
Chris@1295 204 assert_template 'changes'
Chris@1295 205 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@1295 206 end
Chris@1295 207
Chris@1295 208 def test_entry_show
Chris@1295 209 get :entry, :id => PRJ_ID,
Chris@1295 210 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
Chris@1295 211 assert_response :success
Chris@1295 212 assert_template 'entry'
Chris@1295 213 # Line 19
Chris@1295 214 assert_tag :tag => 'th',
Chris@1295 215 :content => '11',
Chris@1295 216 :attributes => { :class => 'line-num' },
Chris@1295 217 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
Chris@1295 218 end
Chris@1295 219
Chris@1295 220 def test_entry_show_latin_1
Chris@1295 221 if @ruby19_non_utf8_pass
Chris@1295 222 puts_ruby19_non_utf8_pass()
Chris@1295 223 elsif WINDOWS_PASS
Chris@1295 224 puts WINDOWS_SKIP_STR
Chris@1295 225 elsif JRUBY_SKIP
Chris@1295 226 puts JRUBY_SKIP_STR
Chris@1295 227 else
Chris@1295 228 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@1295 229 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
Chris@1295 230 get :entry, :id => PRJ_ID,
Chris@1295 231 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
Chris@1295 232 :rev => r1
Chris@1295 233 assert_response :success
Chris@1295 234 assert_template 'entry'
Chris@1295 235 assert_tag :tag => 'th',
Chris@1295 236 :content => '1',
Chris@1295 237 :attributes => { :class => 'line-num' },
Chris@1295 238 :sibling => { :tag => 'td',
Chris@1295 239 :content => /test-#{@char_1}.txt/ }
Chris@1295 240 end
Chris@1295 241 end
Chris@1295 242 end
Chris@1295 243 end
Chris@1295 244
Chris@1295 245 def test_entry_download
Chris@1295 246 get :entry, :id => PRJ_ID,
Chris@1295 247 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
Chris@1295 248 :format => 'raw'
Chris@1295 249 assert_response :success
Chris@1295 250 # File content
Chris@1295 251 assert @response.body.include?('WITHOUT ANY WARRANTY')
Chris@1295 252 end
Chris@1295 253
Chris@1295 254 def test_directory_entry
Chris@1295 255 get :entry, :id => PRJ_ID,
Chris@1295 256 :path => repository_path_hash(['sources'])[:param]
Chris@1295 257 assert_response :success
Chris@1295 258 assert_template 'show'
Chris@1295 259 assert_not_nil assigns(:entry)
Chris@1295 260 assert_equal 'sources', assigns(:entry).name
Chris@1295 261 end
Chris@1295 262
Chris@1295 263 def test_diff
Chris@1295 264 assert_equal true, @repository.is_default
Chris@1295 265 assert_nil @repository.identifier
Chris@1295 266 assert_equal 0, @repository.changesets.count
Chris@1295 267 @repository.fetch_changesets
Chris@1295 268 @project.reload
Chris@1295 269 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 270 # Full diff of changeset 2f9c0091
Chris@1295 271 ['inline', 'sbs'].each do |dt|
Chris@1295 272 get :diff,
Chris@1295 273 :id => PRJ_ID,
Chris@1295 274 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
Chris@1295 275 :type => dt
Chris@1295 276 assert_response :success
Chris@1295 277 assert_template 'diff'
Chris@1295 278 # Line 22 removed
Chris@1295 279 assert_tag :tag => 'th',
Chris@1295 280 :content => /22/,
Chris@1295 281 :sibling => { :tag => 'td',
Chris@1295 282 :attributes => { :class => /diff_out/ },
Chris@1295 283 :content => /def remove/ }
Chris@1295 284 assert_tag :tag => 'h2', :content => /2f9c0091/
Chris@1295 285 end
Chris@1295 286 end
Chris@1295 287
Chris@1295 288 def test_diff_with_rev_and_path
Chris@1295 289 assert_equal 0, @repository.changesets.count
Chris@1295 290 @repository.fetch_changesets
Chris@1295 291 @project.reload
Chris@1295 292 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 293 with_settings :diff_max_lines_displayed => 1000 do
Chris@1295 294 # Full diff of changeset 2f9c0091
Chris@1295 295 ['inline', 'sbs'].each do |dt|
Chris@1295 296 get :diff,
Chris@1295 297 :id => PRJ_ID,
Chris@1295 298 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
Chris@1295 299 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
Chris@1295 300 :type => dt
Chris@1295 301 assert_response :success
Chris@1295 302 assert_template 'diff'
Chris@1295 303 # Line 22 removed
Chris@1295 304 assert_tag :tag => 'th',
Chris@1295 305 :content => '22',
Chris@1295 306 :sibling => { :tag => 'td',
Chris@1295 307 :attributes => { :class => /diff_out/ },
Chris@1295 308 :content => /def remove/ }
Chris@1295 309 assert_tag :tag => 'h2', :content => /2f9c0091/
Chris@1295 310 end
Chris@1295 311 end
Chris@1295 312 end
Chris@1295 313
Chris@1295 314 def test_diff_truncated
Chris@1295 315 assert_equal 0, @repository.changesets.count
Chris@1295 316 @repository.fetch_changesets
Chris@1295 317 @project.reload
Chris@1295 318 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 319
Chris@1295 320 with_settings :diff_max_lines_displayed => 5 do
Chris@1295 321 # Truncated diff of changeset 2f9c0091
Chris@1295 322 with_cache do
Chris@1295 323 with_settings :default_language => 'en' do
Chris@1295 324 get :diff, :id => PRJ_ID, :type => 'inline',
Chris@1295 325 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@1295 326 assert_response :success
Chris@1295 327 assert @response.body.include?("... This diff was truncated")
Chris@1295 328 end
Chris@1295 329 with_settings :default_language => 'fr' do
Chris@1295 330 get :diff, :id => PRJ_ID, :type => 'inline',
Chris@1295 331 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@1295 332 assert_response :success
Chris@1295 333 assert ! @response.body.include?("... This diff was truncated")
Chris@1295 334 assert @response.body.include?("... Ce diff")
Chris@1295 335 end
Chris@1295 336 end
Chris@1295 337 end
Chris@1295 338 end
Chris@1295 339
Chris@1295 340 def test_diff_two_revs
Chris@1295 341 assert_equal 0, @repository.changesets.count
Chris@1295 342 @repository.fetch_changesets
Chris@1295 343 @project.reload
Chris@1295 344 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 345 ['inline', 'sbs'].each do |dt|
Chris@1295 346 get :diff,
Chris@1295 347 :id => PRJ_ID,
Chris@1295 348 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
Chris@1295 349 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
Chris@1295 350 :type => dt
Chris@1295 351 assert_response :success
Chris@1295 352 assert_template 'diff'
Chris@1295 353 diff = assigns(:diff)
Chris@1295 354 assert_not_nil diff
Chris@1295 355 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
Chris@1295 356 assert_tag :tag => "form",
Chris@1295 357 :attributes => {
Chris@1295 358 :action => "/projects/subproject1/repository/revisions/" +
Chris@1295 359 "61b685fbe55ab05b5ac68402d5720c1a6ac973d1/diff"
Chris@1295 360 }
Chris@1295 361 assert_tag :tag => 'input',
Chris@1295 362 :attributes => {
Chris@1295 363 :id => "rev_to",
Chris@1295 364 :name => "rev_to",
Chris@1295 365 :type => "hidden",
Chris@1295 366 :value => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@1295 367 }
Chris@1295 368 end
Chris@1295 369 end
Chris@1295 370
Chris@1295 371 def test_diff_path_in_subrepo
Chris@1295 372 repo = Repository::Git.create(
Chris@1295 373 :project => @project,
Chris@1295 374 :url => REPOSITORY_PATH,
Chris@1295 375 :identifier => 'test-diff-path',
Chris@1295 376 :path_encoding => 'ISO-8859-1'
Chris@1295 377 );
Chris@1295 378 assert repo
Chris@1295 379 assert_equal false, repo.is_default
Chris@1295 380 assert_equal 'test-diff-path', repo.identifier
Chris@1295 381 get :diff,
Chris@1295 382 :id => PRJ_ID,
Chris@1295 383 :repository_id => 'test-diff-path',
Chris@1295 384 :rev => '61b685fbe55ab05b',
Chris@1295 385 :rev_to => '2f9c0091c754a91a',
Chris@1295 386 :type => 'inline'
Chris@1295 387 assert_response :success
Chris@1295 388 assert_template 'diff'
Chris@1295 389 diff = assigns(:diff)
Chris@1295 390 assert_not_nil diff
Chris@1295 391 assert_tag :tag => "form",
Chris@1295 392 :attributes => {
Chris@1295 393 :action => "/projects/subproject1/repository/test-diff-path/" +
Chris@1295 394 "revisions/61b685fbe55ab05b/diff"
Chris@1295 395 }
Chris@1295 396 assert_tag :tag => 'input',
Chris@1295 397 :attributes => {
Chris@1295 398 :id => "rev_to",
Chris@1295 399 :name => "rev_to",
Chris@1295 400 :type => "hidden",
Chris@1295 401 :value => '2f9c0091c754a91a'
Chris@1295 402 }
Chris@1295 403 end
Chris@1295 404
Chris@1295 405 def test_diff_latin_1
Chris@1295 406 if @ruby19_non_utf8_pass
Chris@1295 407 puts_ruby19_non_utf8_pass()
Chris@1295 408 else
Chris@1295 409 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@1295 410 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
Chris@1295 411 ['inline', 'sbs'].each do |dt|
Chris@1295 412 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
Chris@1295 413 assert_response :success
Chris@1295 414 assert_template 'diff'
Chris@1295 415 assert_tag :tag => 'thead',
Chris@1295 416 :descendant => {
Chris@1295 417 :tag => 'th',
Chris@1295 418 :attributes => { :class => 'filename' } ,
Chris@1295 419 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
Chris@1295 420 },
Chris@1295 421 :sibling => {
Chris@1295 422 :tag => 'tbody',
Chris@1295 423 :descendant => {
Chris@1295 424 :tag => 'td',
Chris@1295 425 :attributes => { :class => /diff_in/ },
Chris@1295 426 :content => /test-#{@char_1}.txt/
Chris@1295 427 }
Chris@1295 428 }
Chris@1295 429 end
Chris@1295 430 end
Chris@1295 431 end
Chris@1295 432 end
Chris@1295 433 end
Chris@1295 434
Chris@1295 435 def test_diff_should_show_filenames
Chris@1295 436 get :diff, :id => PRJ_ID, :rev => 'deff712f05a90d96edbd70facc47d944be5897e3', :type => 'inline'
Chris@1295 437 assert_response :success
Chris@1295 438 assert_template 'diff'
Chris@1295 439 # modified file
Chris@1295 440 assert_select 'th.filename', :text => 'sources/watchers_controller.rb'
Chris@1295 441 # deleted file
Chris@1295 442 assert_select 'th.filename', :text => 'test.txt'
Chris@1295 443 end
Chris@1295 444
Chris@1295 445 def test_save_diff_type
Chris@1295 446 user1 = User.find(1)
Chris@1295 447 user1.pref[:diff_type] = nil
Chris@1295 448 user1.preference.save
Chris@1295 449 user = User.find(1)
Chris@1295 450 assert_nil user.pref[:diff_type]
Chris@1295 451
Chris@1295 452 @request.session[:user_id] = 1 # admin
Chris@1295 453 get :diff,
Chris@1295 454 :id => PRJ_ID,
Chris@1295 455 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@1295 456 assert_response :success
Chris@1295 457 assert_template 'diff'
Chris@1295 458 user.reload
Chris@1295 459 assert_equal "inline", user.pref[:diff_type]
Chris@1295 460 get :diff,
Chris@1295 461 :id => PRJ_ID,
Chris@1295 462 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
Chris@1295 463 :type => 'sbs'
Chris@1295 464 assert_response :success
Chris@1295 465 assert_template 'diff'
Chris@1295 466 user.reload
Chris@1295 467 assert_equal "sbs", user.pref[:diff_type]
Chris@1295 468 end
Chris@1295 469
Chris@1295 470 def test_annotate
Chris@1295 471 get :annotate, :id => PRJ_ID,
Chris@1295 472 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
Chris@1295 473 assert_response :success
Chris@1295 474 assert_template 'annotate'
Chris@1295 475
Chris@1295 476 # Line 23, changeset 2f9c0091
Chris@1295 477 assert_select 'tr' do
Chris@1295 478 assert_select 'th.line-num', :text => '23'
Chris@1295 479 assert_select 'td.revision', :text => /2f9c0091/
Chris@1295 480 assert_select 'td.author', :text => 'jsmith'
Chris@1295 481 assert_select 'td', :text => /remove_watcher/
Chris@1295 482 end
Chris@1295 483 end
Chris@1295 484
Chris@1295 485 def test_annotate_at_given_revision
Chris@1295 486 assert_equal 0, @repository.changesets.count
Chris@1295 487 @repository.fetch_changesets
Chris@1295 488 @project.reload
Chris@1295 489 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 490 get :annotate, :id => PRJ_ID, :rev => 'deff7',
Chris@1295 491 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param]
Chris@1295 492 assert_response :success
Chris@1295 493 assert_template 'annotate'
Chris@1295 494 assert_tag :tag => 'h2', :content => /@ deff712f/
Chris@1295 495 end
Chris@1295 496
Chris@1295 497 def test_annotate_binary_file
Chris@1295 498 get :annotate, :id => PRJ_ID,
Chris@1295 499 :path => repository_path_hash(['images', 'edit.png'])[:param]
Chris@1295 500 assert_response 500
Chris@1295 501 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
Chris@1295 502 :content => /cannot be annotated/
Chris@1295 503 end
Chris@1295 504
Chris@1295 505 def test_annotate_error_when_too_big
Chris@1295 506 with_settings :file_max_size_displayed => 1 do
Chris@1295 507 get :annotate, :id => PRJ_ID,
Chris@1295 508 :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param],
Chris@1295 509 :rev => 'deff712f'
Chris@1295 510 assert_response 500
Chris@1295 511 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
Chris@1295 512 :content => /exceeds the maximum text file size/
Chris@1295 513
Chris@1295 514 get :annotate, :id => PRJ_ID,
Chris@1295 515 :path => repository_path_hash(['README'])[:param],
Chris@1295 516 :rev => '7234cb2'
Chris@1295 517 assert_response :success
Chris@1295 518 assert_template 'annotate'
Chris@1295 519 end
Chris@1295 520 end
Chris@1295 521
Chris@1295 522 def test_annotate_latin_1
Chris@1295 523 if @ruby19_non_utf8_pass
Chris@1295 524 puts_ruby19_non_utf8_pass()
Chris@1295 525 elsif WINDOWS_PASS
Chris@1295 526 puts WINDOWS_SKIP_STR
Chris@1295 527 elsif JRUBY_SKIP
Chris@1295 528 puts JRUBY_SKIP_STR
Chris@1295 529 else
Chris@1295 530 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@1295 531 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
Chris@1295 532 get :annotate, :id => PRJ_ID,
Chris@1295 533 :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param],
Chris@1295 534 :rev => r1
Chris@1295 535 assert_tag :tag => 'th',
Chris@1295 536 :content => '1',
Chris@1295 537 :attributes => { :class => 'line-num' },
Chris@1295 538 :sibling => { :tag => 'td',
Chris@1295 539 :content => /test-#{@char_1}.txt/ }
Chris@1295 540 end
Chris@1295 541 end
Chris@1295 542 end
Chris@1295 543 end
Chris@1295 544
Chris@1295 545 def test_revisions
Chris@1295 546 assert_equal 0, @repository.changesets.count
Chris@1295 547 @repository.fetch_changesets
Chris@1295 548 @project.reload
Chris@1295 549 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 550 get :revisions, :id => PRJ_ID
Chris@1295 551 assert_response :success
Chris@1295 552 assert_template 'revisions'
Chris@1295 553 assert_tag :tag => 'form',
Chris@1295 554 :attributes => {
Chris@1295 555 :method => 'get',
Chris@1295 556 :action => '/projects/subproject1/repository/revision'
Chris@1295 557 }
Chris@1295 558 end
Chris@1295 559
Chris@1295 560 def test_revision
Chris@1295 561 assert_equal 0, @repository.changesets.count
Chris@1295 562 @repository.fetch_changesets
Chris@1295 563 @project.reload
Chris@1295 564 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 565 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
Chris@1295 566 get :revision, :id => PRJ_ID, :rev => r
Chris@1295 567 assert_response :success
Chris@1295 568 assert_template 'revision'
Chris@1295 569 end
Chris@1295 570 end
Chris@1295 571
Chris@1295 572 def test_empty_revision
Chris@1295 573 assert_equal 0, @repository.changesets.count
Chris@1295 574 @repository.fetch_changesets
Chris@1295 575 @project.reload
Chris@1295 576 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 577 ['', ' ', nil].each do |r|
Chris@1295 578 get :revision, :id => PRJ_ID, :rev => r
Chris@1295 579 assert_response 404
Chris@1295 580 assert_error_tag :content => /was not found/
Chris@1295 581 end
Chris@1295 582 end
Chris@1295 583
Chris@1295 584 def test_destroy_valid_repository
Chris@1295 585 @request.session[:user_id] = 1 # admin
Chris@1295 586 assert_equal 0, @repository.changesets.count
Chris@1295 587 @repository.fetch_changesets
Chris@1295 588 @project.reload
Chris@1295 589 assert_equal NUM_REV, @repository.changesets.count
Chris@1295 590
Chris@1295 591 assert_difference 'Repository.count', -1 do
Chris@1295 592 delete :destroy, :id => @repository.id
Chris@1295 593 end
Chris@1295 594 assert_response 302
Chris@1295 595 @project.reload
Chris@1295 596 assert_nil @project.repository
Chris@1295 597 end
Chris@1295 598
Chris@1295 599 def test_destroy_invalid_repository
Chris@1295 600 @request.session[:user_id] = 1 # admin
Chris@1295 601 @project.repository.destroy
Chris@1295 602 @repository = Repository::Git.create!(
Chris@1295 603 :project => @project,
Chris@1295 604 :url => "/invalid",
Chris@1295 605 :path_encoding => 'ISO-8859-1'
Chris@1295 606 )
Chris@1295 607 @repository.fetch_changesets
Chris@1295 608 @repository.reload
Chris@1295 609 assert_equal 0, @repository.changesets.count
Chris@1295 610
Chris@1295 611 assert_difference 'Repository.count', -1 do
Chris@1295 612 delete :destroy, :id => @repository.id
Chris@1295 613 end
Chris@1295 614 assert_response 302
Chris@1295 615 @project.reload
Chris@1295 616 assert_nil @project.repository
Chris@1295 617 end
Chris@1295 618
Chris@1295 619 private
Chris@1295 620
Chris@1295 621 def puts_ruby19_non_utf8_pass
Chris@1295 622 puts "TODO: This test fails in Ruby 1.9 " +
Chris@1295 623 "and Encoding.default_external is not UTF-8. " +
Chris@1295 624 "Current value is '#{Encoding.default_external.to_s}'"
Chris@1295 625 end
Chris@1295 626 else
Chris@1295 627 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
Chris@1295 628 def test_fake; assert true end
Chris@1295 629 end
Chris@1295 630
Chris@1295 631 private
Chris@1295 632 def with_cache(&block)
Chris@1295 633 before = ActionController::Base.perform_caching
Chris@1295 634 ActionController::Base.perform_caching = true
Chris@1295 635 block.call
Chris@1295 636 ActionController::Base.perform_caching = before
Chris@1295 637 end
Chris@1295 638 end