annotate test/functional/repositories_mercurial_controller_test.rb @ 857:a1a87bc044b8 feature_199

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