annotate .svn/pristine/ae/ae1f195964d1ff8b740bcbc54f3dee15904d207f.svn-base @ 1519:afce8026aaeb redmine-2.4-integration

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