annotate test/functional/repositories_git_controller_test.rb @ 1628:9c5f8e24dadc live tip

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