annotate test/functional/repositories_mercurial_controller_test.rb @ 669:202986dd17e4 live bibliography_plugin_alpha

Merge from branch "cannam_integration"
author Chris Cannam
date Fri, 09 Sep 2011 16:56:21 +0100
parents 851510f1b535
children 5e80956cc792
rev   line source
Chris@441 1 # Redmine - project management software
Chris@441 2 # Copyright (C) 2006-2011 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 require 'repositories_controller'
Chris@0 20
Chris@0 21 # Re-raise errors caught by the controller.
Chris@0 22 class RepositoriesController; def rescue_action(e) raise e end; end
Chris@0 23
Chris@0 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
Chris@0 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
Chris@0 26
Chris@0 27 # No '..' in the repository path
Chris@441 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
Chris@441 29 '/tmp/test/mercurial_repository'
Chris@441 30 CHAR_1_HEX = "\xc3\x9c"
Chris@441 31 PRJ_ID = 3
Chris@441 32
Chris@441 33 ruby19_non_utf8_pass =
Chris@441 34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
Chris@0 35
Chris@0 36 def setup
Chris@0 37 @controller = RepositoriesController.new
Chris@0 38 @request = ActionController::TestRequest.new
Chris@0 39 @response = ActionController::TestResponse.new
Chris@0 40 User.current = nil
Chris@507 41 @project = Project.find(PRJ_ID)
Chris@441 42 @repository = Repository::Mercurial.create(
Chris@507 43 :project => @project,
Chris@441 44 :url => REPOSITORY_PATH,
Chris@441 45 :path_encoding => 'ISO-8859-1'
Chris@441 46 )
Chris@119 47 assert @repository
Chris@245 48 @diff_c_support = true
Chris@441 49 @char_1 = CHAR_1_HEX.dup
Chris@441 50 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
Chris@441 51 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
Chris@441 52 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
Chris@441 53 if @char_1.respond_to?(:force_encoding)
Chris@441 54 @char_1.force_encoding('UTF-8')
Chris@441 55 @tag_char_1.force_encoding('UTF-8')
Chris@441 56 @branch_char_0.force_encoding('UTF-8')
Chris@441 57 @branch_char_1.force_encoding('UTF-8')
Chris@441 58 end
Chris@0 59 end
Chris@119 60
Chris@441 61 if ruby19_non_utf8_pass
Chris@441 62 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
Chris@441 63 "and Encoding.default_external is not UTF-8. " +
Chris@441 64 "Current value is '#{Encoding.default_external.to_s}'"
Chris@441 65 def test_fake; assert true end
Chris@441 66 elsif File.directory?(REPOSITORY_PATH)
Chris@0 67 def test_show_root
Chris@441 68 @repository.fetch_changesets
Chris@441 69 @repository.reload
Chris@441 70 get :show, :id => PRJ_ID
Chris@0 71 assert_response :success
Chris@0 72 assert_template 'show'
Chris@0 73 assert_not_nil assigns(:entries)
Chris@119 74 assert_equal 4, assigns(:entries).size
Chris@119 75 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@0 76 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@119 77 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@441 78 assert_not_nil assigns(:changesets)
Chris@441 79 assigns(:changesets).size > 0
Chris@0 80 end
Chris@128 81
Chris@0 82 def test_show_directory
Chris@441 83 @repository.fetch_changesets
Chris@441 84 @repository.reload
Chris@441 85 get :show, :id => PRJ_ID, :path => ['images']
Chris@0 86 assert_response :success
Chris@0 87 assert_template 'show'
Chris@0 88 assert_not_nil assigns(:entries)
Chris@0 89 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 90 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 91 assert_not_nil entry
Chris@0 92 assert_equal 'file', entry.kind
Chris@0 93 assert_equal 'images/edit.png', entry.path
Chris@441 94 assert_not_nil assigns(:changesets)
Chris@441 95 assigns(:changesets).size > 0
Chris@0 96 end
Chris@119 97
Chris@0 98 def test_show_at_given_revision
Chris@441 99 @repository.fetch_changesets
Chris@441 100 @repository.reload
Chris@119 101 [0, '0', '0885933ad4f6'].each do |r1|
Chris@441 102 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
Chris@119 103 assert_response :success
Chris@119 104 assert_template 'show'
Chris@119 105 assert_not_nil assigns(:entries)
Chris@119 106 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@441 107 assert_not_nil assigns(:changesets)
Chris@441 108 assigns(:changesets).size > 0
Chris@119 109 end
Chris@0 110 end
Chris@119 111
Chris@119 112 def test_show_directory_sql_escape_percent
Chris@441 113 @repository.fetch_changesets
Chris@441 114 @repository.reload
Chris@119 115 [13, '13', '3a330eb32958'].each do |r1|
Chris@441 116 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
Chris@441 117 :rev => r1
Chris@119 118 assert_response :success
Chris@119 119 assert_template 'show'
Chris@119 120
Chris@119 121 assert_not_nil assigns(:entries)
Chris@441 122 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
Chris@441 123 assigns(:entries).collect(&:name)
Chris@119 124 changesets = assigns(:changesets)
Chris@441 125 assert_not_nil changesets
Chris@441 126 assigns(:changesets).size > 0
Chris@441 127 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
Chris@441 128 end
Chris@441 129 end
Chris@119 130
Chris@441 131 def test_show_directory_latin_1_path
Chris@441 132 @repository.fetch_changesets
Chris@441 133 @repository.reload
Chris@441 134 [21, '21', 'adf805632193'].each do |r1|
Chris@441 135 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
Chris@441 136 assert_response :success
Chris@441 137 assert_template 'show'
Chris@441 138
Chris@441 139 assert_not_nil assigns(:entries)
Chris@441 140 assert_equal ["make-latin-1-file.rb",
Chris@441 141 "test-#{@char_1}-1.txt",
Chris@441 142 "test-#{@char_1}-2.txt",
Chris@441 143 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
Chris@441 144 changesets = assigns(:changesets)
Chris@441 145 assert_not_nil changesets
Chris@441 146 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
Chris@441 147 end
Chris@441 148 end
Chris@441 149
Chris@441 150 def test_show_branch
Chris@441 151 @repository.fetch_changesets
Chris@441 152 @repository.reload
Chris@441 153 [
Chris@441 154 'default',
Chris@441 155 @branch_char_1,
Chris@441 156 'branch (1)[2]&,%.-3_4',
Chris@441 157 @branch_char_0,
Chris@441 158 'test_branch.latin-1',
Chris@441 159 'test-branch-00',
Chris@441 160 ].each do |bra|
Chris@441 161 get :show, :id => PRJ_ID, :rev => bra
Chris@441 162 assert_response :success
Chris@441 163 assert_template 'show'
Chris@441 164 assert_not_nil assigns(:entries)
Chris@441 165 assert assigns(:entries).size > 0
Chris@441 166 assert_not_nil assigns(:changesets)
Chris@441 167 assigns(:changesets).size > 0
Chris@441 168 end
Chris@441 169 end
Chris@441 170
Chris@441 171 def test_show_tag
Chris@441 172 @repository.fetch_changesets
Chris@441 173 @repository.reload
Chris@441 174 [
Chris@441 175 @tag_char_1,
Chris@441 176 'tag_test.00',
Chris@441 177 'tag-init-revision'
Chris@441 178 ].each do |tag|
Chris@441 179 get :show, :id => PRJ_ID, :rev => tag
Chris@441 180 assert_response :success
Chris@441 181 assert_template 'show'
Chris@441 182 assert_not_nil assigns(:entries)
Chris@441 183 assert assigns(:entries).size > 0
Chris@441 184 assert_not_nil assigns(:changesets)
Chris@441 185 assigns(:changesets).size > 0
Chris@119 186 end
Chris@119 187 end
Chris@119 188
Chris@0 189 def test_changes
Chris@441 190 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
Chris@0 191 assert_response :success
Chris@0 192 assert_template 'changes'
Chris@0 193 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@0 194 end
Chris@441 195
Chris@0 196 def test_entry_show
Chris@441 197 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 198 assert_response :success
Chris@0 199 assert_template 'entry'
Chris@119 200 # Line 10
Chris@0 201 assert_tag :tag => 'th',
Chris@119 202 :content => '10',
Chris@119 203 :attributes => { :class => 'line-num' },
Chris@0 204 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
Chris@0 205 end
Chris@441 206
Chris@441 207 def test_entry_show_latin_1_path
Chris@441 208 [21, '21', 'adf805632193'].each do |r1|
Chris@441 209 get :entry, :id => PRJ_ID,
Chris@441 210 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
Chris@441 211 assert_response :success
Chris@441 212 assert_template 'entry'
Chris@441 213 assert_tag :tag => 'th',
Chris@441 214 :content => '1',
Chris@441 215 :attributes => { :class => 'line-num' },
Chris@441 216 :sibling => { :tag => 'td',
Chris@441 217 :content => /Mercurial is a distributed version control system/ }
Chris@441 218 end
Chris@441 219 end
Chris@441 220
Chris@441 221 def test_entry_show_latin_1_contents
Chris@441 222 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@441 223 [27, '27', '7bbf4c738e71'].each do |r1|
Chris@441 224 get :entry, :id => PRJ_ID,
Chris@441 225 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
Chris@441 226 assert_response :success
Chris@441 227 assert_template 'entry'
Chris@441 228 assert_tag :tag => 'th',
Chris@441 229 :content => '1',
Chris@441 230 :attributes => { :class => 'line-num' },
Chris@441 231 :sibling => { :tag => 'td',
Chris@441 232 :content => /test-#{@char_1}.txt/ }
Chris@441 233 end
Chris@441 234 end
Chris@441 235 end
Chris@441 236
Chris@0 237 def test_entry_download
Chris@441 238 get :entry, :id => PRJ_ID,
Chris@441 239 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
Chris@0 240 assert_response :success
Chris@0 241 # File content
Chris@0 242 assert @response.body.include?('WITHOUT ANY WARRANTY')
Chris@0 243 end
Chris@0 244
Chris@441 245 def test_entry_binary_force_download
Chris@441 246 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
Chris@441 247 assert_response :success
Chris@441 248 assert_equal 'image/png', @response.content_type
Chris@441 249 end
Chris@441 250
Chris@0 251 def test_directory_entry
Chris@441 252 get :entry, :id => PRJ_ID, :path => ['sources']
Chris@0 253 assert_response :success
Chris@0 254 assert_template 'show'
Chris@0 255 assert_not_nil assigns(:entry)
Chris@0 256 assert_equal 'sources', assigns(:entry).name
Chris@0 257 end
Chris@441 258
Chris@0 259 def test_diff
Chris@119 260 @repository.fetch_changesets
Chris@119 261 @repository.reload
Chris@119 262 [4, '4', 'def6d2f1254a'].each do |r1|
Chris@119 263 # Full diff of changeset 4
Chris@441 264 get :diff, :id => PRJ_ID, :rev => r1
Chris@119 265 assert_response :success
Chris@119 266 assert_template 'diff'
Chris@245 267 if @diff_c_support
Chris@119 268 # Line 22 removed
Chris@119 269 assert_tag :tag => 'th',
Chris@119 270 :content => '22',
Chris@441 271 :sibling => { :tag => 'td',
Chris@119 272 :attributes => { :class => /diff_out/ },
Chris@119 273 :content => /def remove/ }
Chris@119 274 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
Chris@119 275 end
Chris@119 276 end
Chris@0 277 end
Chris@119 278
Chris@119 279 def test_diff_two_revs
Chris@119 280 @repository.fetch_changesets
Chris@119 281 @repository.reload
Chris@119 282 [2, '400bb8672109', '400', 400].each do |r1|
Chris@119 283 [4, 'def6d2f1254a'].each do |r2|
Chris@441 284 get :diff, :id => PRJ_ID, :rev => r1,
Chris@441 285 :rev_to => r2
Chris@119 286 assert_response :success
Chris@119 287 assert_template 'diff'
Chris@119 288
Chris@119 289 diff = assigns(:diff)
Chris@119 290 assert_not_nil diff
Chris@119 291 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
Chris@119 292 end
Chris@119 293 end
Chris@119 294 end
Chris@119 295
Chris@441 296 def test_diff_latin_1_path
Chris@441 297 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@441 298 [21, 'adf805632193'].each do |r1|
Chris@441 299 get :diff, :id => PRJ_ID, :rev => r1
Chris@441 300 assert_response :success
Chris@441 301 assert_template 'diff'
Chris@441 302 assert_tag :tag => 'thead',
Chris@441 303 :descendant => {
Chris@441 304 :tag => 'th',
Chris@441 305 :attributes => { :class => 'filename' } ,
Chris@441 306 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
Chris@441 307 },
Chris@441 308 :sibling => {
Chris@441 309 :tag => 'tbody',
Chris@441 310 :descendant => {
Chris@441 311 :tag => 'td',
Chris@441 312 :attributes => { :class => /diff_in/ },
Chris@441 313 :content => /It is written in Python/
Chris@441 314 }
Chris@441 315 }
Chris@441 316 end
Chris@441 317 end
Chris@441 318 end
Chris@441 319
Chris@0 320 def test_annotate
Chris@441 321 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
Chris@0 322 assert_response :success
Chris@0 323 assert_template 'annotate'
Chris@119 324 # Line 23, revision 4:def6d2f1254a
Chris@119 325 assert_tag :tag => 'th',
Chris@119 326 :content => '23',
Chris@119 327 :attributes => { :class => 'line-num' },
Chris@119 328 :sibling =>
Chris@119 329 {
Chris@119 330 :tag => 'td',
Chris@119 331 :attributes => { :class => 'revision' },
Chris@119 332 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
Chris@119 333 }
Chris@119 334 assert_tag :tag => 'th',
Chris@119 335 :content => '23',
Chris@119 336 :attributes => { :class => 'line-num' },
Chris@119 337 :sibling =>
Chris@119 338 {
Chris@119 339 :tag => 'td' ,
Chris@119 340 :content => 'jsmith' ,
Chris@119 341 :attributes => { :class => 'author' },
Chris@119 342 }
Chris@119 343 assert_tag :tag => 'th',
Chris@119 344 :content => '23',
Chris@119 345 :attributes => { :class => 'line-num' },
Chris@0 346 :sibling => { :tag => 'td', :content => /watcher =/ }
Chris@0 347 end
Chris@119 348
Chris@507 349 def test_annotate_not_in_tip
Chris@507 350 @repository.fetch_changesets
Chris@507 351 @repository.reload
Chris@507 352 assert @repository.changesets.size > 0
Chris@507 353
Chris@507 354 get :annotate, :id => PRJ_ID,
Chris@507 355 :path => ['sources', 'welcome_controller.rb']
Chris@507 356 assert_response 404
Chris@507 357 assert_error_tag :content => /was not found/
Chris@507 358 end
Chris@507 359
Chris@210 360 def test_annotate_at_given_revision
Chris@210 361 @repository.fetch_changesets
Chris@210 362 @repository.reload
Chris@210 363 [2, '400bb8672109', '400', 400].each do |r1|
Chris@441 364 get :annotate, :id => PRJ_ID, :rev => r1,
Chris@441 365 :path => ['sources', 'watchers_controller.rb']
Chris@210 366 assert_response :success
Chris@210 367 assert_template 'annotate'
Chris@210 368 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
Chris@210 369 end
Chris@210 370 end
Chris@210 371
Chris@441 372 def test_annotate_latin_1_path
Chris@441 373 [21, '21', 'adf805632193'].each do |r1|
Chris@441 374 get :annotate, :id => PRJ_ID,
Chris@441 375 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
Chris@441 376 assert_response :success
Chris@441 377 assert_template 'annotate'
Chris@441 378 assert_tag :tag => 'th',
Chris@441 379 :content => '1',
Chris@441 380 :attributes => { :class => 'line-num' },
Chris@441 381 :sibling =>
Chris@441 382 {
Chris@441 383 :tag => 'td',
Chris@441 384 :attributes => { :class => 'revision' },
Chris@441 385 :child => { :tag => 'a', :content => '20:709858aafd1b' }
Chris@441 386 }
Chris@441 387 assert_tag :tag => 'th',
Chris@441 388 :content => '1',
Chris@441 389 :attributes => { :class => 'line-num' },
Chris@441 390 :sibling =>
Chris@441 391 {
Chris@441 392 :tag => 'td' ,
Chris@441 393 :content => 'jsmith' ,
Chris@441 394 :attributes => { :class => 'author' },
Chris@441 395 }
Chris@441 396 assert_tag :tag => 'th',
Chris@441 397 :content => '1',
Chris@441 398 :attributes => { :class => 'line-num' },
Chris@441 399 :sibling => { :tag => 'td',
Chris@441 400 :content => /Mercurial is a distributed version control system/ }
Chris@441 401
Chris@441 402 end
Chris@441 403 end
Chris@441 404
Chris@441 405 def test_annotate_latin_1_contents
Chris@441 406 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
Chris@441 407 [27, '7bbf4c738e71'].each do |r1|
Chris@441 408 get :annotate, :id => PRJ_ID,
Chris@441 409 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
Chris@441 410 assert_tag :tag => 'th',
Chris@441 411 :content => '1',
Chris@441 412 :attributes => { :class => 'line-num' },
Chris@441 413 :sibling => { :tag => 'td',
Chris@441 414 :content => /test-#{@char_1}.txt/ }
Chris@441 415 end
Chris@441 416 end
Chris@441 417 end
Chris@441 418
Chris@119 419 def test_empty_revision
Chris@119 420 @repository.fetch_changesets
Chris@119 421 @repository.reload
Chris@119 422 ['', ' ', nil].each do |r|
Chris@441 423 get :revision, :id => PRJ_ID, :rev => r
Chris@128 424 assert_response 404
Chris@119 425 assert_error_tag :content => /was not found/
Chris@119 426 end
Chris@119 427 end
Chris@507 428
Chris@507 429 def test_destroy_valid_repository
Chris@507 430 @request.session[:user_id] = 1 # admin
Chris@507 431 @repository.fetch_changesets
Chris@507 432 @repository.reload
Chris@507 433 assert @repository.changesets.count > 0
Chris@507 434
Chris@507 435 get :destroy, :id => PRJ_ID
Chris@507 436 assert_response 302
Chris@507 437 @project.reload
Chris@507 438 assert_nil @project.repository
Chris@507 439 end
Chris@507 440
Chris@507 441 def test_destroy_invalid_repository
Chris@507 442 @request.session[:user_id] = 1 # admin
Chris@507 443 @repository.fetch_changesets
Chris@507 444 @repository.reload
Chris@507 445 assert @repository.changesets.count > 0
Chris@507 446
Chris@507 447 get :destroy, :id => PRJ_ID
Chris@507 448 assert_response 302
Chris@507 449 @project.reload
Chris@507 450 assert_nil @project.repository
Chris@507 451
Chris@507 452 @repository = Repository::Mercurial.create(
Chris@507 453 :project => Project.find(PRJ_ID),
Chris@507 454 :url => "/invalid",
Chris@507 455 :path_encoding => 'ISO-8859-1'
Chris@507 456 )
Chris@507 457 assert @repository
Chris@507 458 @repository.fetch_changesets
Chris@507 459 @repository.reload
Chris@507 460 assert_equal 0, @repository.changesets.count
Chris@507 461
Chris@507 462 get :destroy, :id => PRJ_ID
Chris@507 463 assert_response 302
Chris@507 464 @project.reload
Chris@507 465 assert_nil @project.repository
Chris@507 466 end
Chris@0 467 else
Chris@0 468 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 469 def test_fake; assert true end
Chris@0 470 end
Chris@0 471 end