annotate test/functional/repositories_mercurial_controller_test.rb @ 128:07fa8a8b56a8

Update to Redmine trunk rev 4732
author Chris Cannam
date Wed, 19 Jan 2011 15:04:22 +0000
parents 8661b858af72
children 5e974759e8b2 0579821a129a
rev   line source
Chris@0 1 # redMine - project management software
Chris@0 2 # Copyright (C) 2006-2008 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@0 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@0 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@0 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
Chris@0 29
Chris@0 30 def setup
Chris@0 31 @controller = RepositoriesController.new
Chris@0 32 @request = ActionController::TestRequest.new
Chris@0 33 @response = ActionController::TestResponse.new
Chris@0 34 User.current = nil
Chris@119 35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH)
Chris@119 36 assert @repository
Chris@0 37 end
Chris@119 38
Chris@0 39 if File.directory?(REPOSITORY_PATH)
Chris@0 40 def test_show
Chris@0 41 get :show, :id => 3
Chris@0 42 assert_response :success
Chris@0 43 assert_template 'show'
Chris@0 44 assert_not_nil assigns(:entries)
Chris@0 45 assert_not_nil assigns(:changesets)
Chris@0 46 end
Chris@128 47
Chris@0 48 def test_show_root
Chris@0 49 get :show, :id => 3
Chris@0 50 assert_response :success
Chris@0 51 assert_template 'show'
Chris@0 52 assert_not_nil assigns(:entries)
Chris@119 53 assert_equal 4, assigns(:entries).size
Chris@119 54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@0 55 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@119 56 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@0 57 end
Chris@128 58
Chris@0 59 def test_show_directory
Chris@0 60 get :show, :id => 3, :path => ['images']
Chris@0 61 assert_response :success
Chris@0 62 assert_template 'show'
Chris@0 63 assert_not_nil assigns(:entries)
Chris@0 64 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
Chris@0 65 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 66 assert_not_nil entry
Chris@0 67 assert_equal 'file', entry.kind
Chris@0 68 assert_equal 'images/edit.png', entry.path
Chris@0 69 end
Chris@119 70
Chris@0 71 def test_show_at_given_revision
Chris@119 72 [0, '0', '0885933ad4f6'].each do |r1|
Chris@119 73 get :show, :id => 3, :path => ['images'], :rev => r1
Chris@119 74 assert_response :success
Chris@119 75 assert_template 'show'
Chris@119 76 assert_not_nil assigns(:entries)
Chris@119 77 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@119 78 end
Chris@0 79 end
Chris@119 80
Chris@119 81 def test_show_directory_sql_escape_percent
Chris@119 82 [13, '13', '3a330eb32958'].each do |r1|
Chris@119 83 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
Chris@119 84 assert_response :success
Chris@119 85 assert_template 'show'
Chris@119 86
Chris@119 87 assert_not_nil assigns(:entries)
Chris@119 88 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
Chris@119 89 changesets = assigns(:changesets)
Chris@119 90
Chris@119 91 ## This is not yet implemented.
Chris@119 92 # assert_not_nil changesets
Chris@119 93 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
Chris@119 94 end
Chris@119 95 end
Chris@119 96
Chris@0 97 def test_changes
Chris@0 98 get :changes, :id => 3, :path => ['images', 'edit.png']
Chris@0 99 assert_response :success
Chris@0 100 assert_template 'changes'
Chris@0 101 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@0 102 end
Chris@0 103
Chris@0 104 def test_entry_show
Chris@0 105 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
Chris@0 106 assert_response :success
Chris@0 107 assert_template 'entry'
Chris@119 108 # Line 10
Chris@0 109 assert_tag :tag => 'th',
Chris@119 110 :content => '10',
Chris@119 111 :attributes => { :class => 'line-num' },
Chris@0 112 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
Chris@0 113 end
Chris@0 114
Chris@0 115 def test_entry_download
Chris@0 116 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
Chris@0 117 assert_response :success
Chris@0 118 # File content
Chris@0 119 assert @response.body.include?('WITHOUT ANY WARRANTY')
Chris@0 120 end
Chris@0 121
Chris@0 122 def test_directory_entry
Chris@0 123 get :entry, :id => 3, :path => ['sources']
Chris@0 124 assert_response :success
Chris@0 125 assert_template 'show'
Chris@0 126 assert_not_nil assigns(:entry)
Chris@0 127 assert_equal 'sources', assigns(:entry).name
Chris@0 128 end
Chris@0 129
Chris@0 130 def test_diff
Chris@119 131 @repository.fetch_changesets
Chris@119 132 @repository.reload
Chris@119 133
Chris@119 134 [4, '4', 'def6d2f1254a'].each do |r1|
Chris@119 135 # Full diff of changeset 4
Chris@128 136 get :diff, :id => 3, :rev => r1
Chris@119 137 assert_response :success
Chris@119 138 assert_template 'diff'
Chris@119 139
Chris@119 140 if @repository.scm.class.client_version_above?([1, 2])
Chris@119 141 # Line 22 removed
Chris@119 142 assert_tag :tag => 'th',
Chris@119 143 :content => '22',
Chris@119 144 :sibling => { :tag => 'td',
Chris@119 145 :attributes => { :class => /diff_out/ },
Chris@119 146 :content => /def remove/ }
Chris@119 147 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
Chris@119 148 end
Chris@119 149 end
Chris@0 150 end
Chris@119 151
Chris@119 152 def test_diff_two_revs
Chris@119 153 @repository.fetch_changesets
Chris@119 154 @repository.reload
Chris@119 155
Chris@119 156 [2, '400bb8672109', '400', 400].each do |r1|
Chris@119 157 [4, 'def6d2f1254a'].each do |r2|
Chris@119 158 get :diff, :id => 3, :rev => r1,
Chris@119 159 :rev_to => r2
Chris@119 160 assert_response :success
Chris@119 161 assert_template 'diff'
Chris@119 162
Chris@119 163 diff = assigns(:diff)
Chris@119 164 assert_not_nil diff
Chris@119 165 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
Chris@119 166 end
Chris@119 167 end
Chris@119 168 end
Chris@119 169
Chris@0 170 def test_annotate
Chris@0 171 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
Chris@0 172 assert_response :success
Chris@0 173 assert_template 'annotate'
Chris@119 174 # Line 23, revision 4:def6d2f1254a
Chris@119 175 assert_tag :tag => 'th',
Chris@119 176 :content => '23',
Chris@119 177 :attributes => { :class => 'line-num' },
Chris@119 178 :sibling =>
Chris@119 179 {
Chris@119 180 :tag => 'td',
Chris@119 181 :attributes => { :class => 'revision' },
Chris@119 182 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
Chris@119 183 }
Chris@119 184 assert_tag :tag => 'th',
Chris@119 185 :content => '23',
Chris@119 186 :attributes => { :class => 'line-num' },
Chris@119 187 :sibling =>
Chris@119 188 {
Chris@119 189 :tag => 'td' ,
Chris@119 190 :content => 'jsmith' ,
Chris@119 191 :attributes => { :class => 'author' },
Chris@119 192 }
Chris@119 193 assert_tag :tag => 'th',
Chris@119 194 :content => '23',
Chris@119 195 :attributes => { :class => 'line-num' },
Chris@0 196 :sibling => { :tag => 'td', :content => /watcher =/ }
Chris@0 197 end
Chris@119 198
Chris@119 199 def test_empty_revision
Chris@119 200 @repository.fetch_changesets
Chris@119 201 @repository.reload
Chris@119 202 ['', ' ', nil].each do |r|
Chris@128 203 get :revision, :id => 3, :rev => r
Chris@128 204 assert_response 404
Chris@119 205 assert_error_tag :content => /was not found/
Chris@119 206 end
Chris@119 207 end
Chris@0 208 else
Chris@0 209 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 210 def test_fake; assert true end
Chris@0 211 end
Chris@0 212 end