annotate .svn/pristine/fe/fe2f213c294fbfcf1b3100eeeb0711ec3671f9df.svn-base @ 1517:dffacf8a6908 redmine-2.5

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