annotate .svn/pristine/74/74843b67cd322d5f1fa051b32a2e14dd00a341ce.svn-base @ 1327:287f201c2802 redmine-2.2-integration

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