annotate test/functional/repositories_git_controller_test.rb @ 904:0a8317a50fa0 redmine-1.1

Close obsolete branch redmine-1.1
author Chris Cannam
date Fri, 14 Jan 2011 12:53:21 +0000
parents af80e5618e9b
children 07fa8a8b56a8
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@117 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 RepositoriesGitControllerTest < 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/git_repository'
Chris@0 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
Chris@0 30
Chris@0 31 def setup
Chris@0 32 @controller = RepositoriesController.new
Chris@0 33 @request = ActionController::TestRequest.new
Chris@0 34 @response = ActionController::TestResponse.new
Chris@0 35 User.current = nil
Chris@117 36 @repository = Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH)
Chris@117 37 assert @repository
Chris@0 38 end
Chris@117 39
Chris@0 40 if File.directory?(REPOSITORY_PATH)
Chris@0 41 def test_show
Chris@0 42 get :show, :id => 3
Chris@0 43 assert_response :success
Chris@0 44 assert_template 'show'
Chris@0 45 assert_not_nil assigns(:entries)
Chris@0 46 assert_not_nil assigns(:changesets)
Chris@0 47 end
Chris@0 48
Chris@0 49 def test_browse_root
Chris@0 50 get :show, :id => 3
Chris@0 51 assert_response :success
Chris@0 52 assert_template 'show'
Chris@0 53 assert_not_nil assigns(:entries)
chris@37 54 assert_equal 9, assigns(:entries).size
Chris@0 55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@0 56 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
Chris@0 57 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@0 58 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@0 59 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
Chris@0 60 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
Chris@0 61 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
chris@37 62 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
chris@37 63 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
Chris@0 64 end
Chris@0 65
Chris@0 66 def test_browse_branch
Chris@0 67 get :show, :id => 3, :rev => 'test_branch'
Chris@0 68 assert_response :success
Chris@0 69 assert_template 'show'
Chris@0 70 assert_not_nil assigns(:entries)
Chris@0 71 assert_equal 4, assigns(:entries).size
Chris@0 72 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
Chris@0 73 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
Chris@0 74 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
Chris@0 75 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
Chris@0 76 end
Chris@0 77
Chris@0 78 def test_browse_directory
Chris@0 79 get :show, :id => 3, :path => ['images']
Chris@0 80 assert_response :success
Chris@0 81 assert_template 'show'
Chris@0 82 assert_not_nil assigns(:entries)
Chris@0 83 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
Chris@0 84 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
Chris@0 85 assert_not_nil entry
Chris@0 86 assert_equal 'file', entry.kind
Chris@0 87 assert_equal 'images/edit.png', entry.path
Chris@0 88 end
Chris@0 89
Chris@0 90 def test_browse_at_given_revision
Chris@0 91 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
Chris@0 92 assert_response :success
Chris@0 93 assert_template 'show'
Chris@0 94 assert_not_nil assigns(:entries)
Chris@0 95 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
Chris@0 96 end
Chris@0 97
Chris@0 98 def test_changes
Chris@0 99 get :changes, :id => 3, :path => ['images', 'edit.png']
Chris@0 100 assert_response :success
Chris@0 101 assert_template 'changes'
Chris@0 102 assert_tag :tag => 'h2', :content => 'edit.png'
Chris@0 103 end
Chris@0 104
Chris@0 105 def test_entry_show
Chris@0 106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
Chris@0 107 assert_response :success
Chris@0 108 assert_template 'entry'
Chris@0 109 # Line 19
Chris@0 110 assert_tag :tag => 'th',
Chris@0 111 :content => /11/,
Chris@0 112 :attributes => { :class => /line-num/ },
Chris@0 113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
Chris@0 114 end
Chris@0 115
Chris@0 116 def test_entry_download
Chris@0 117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
Chris@0 118 assert_response :success
Chris@0 119 # File content
Chris@0 120 assert @response.body.include?('WITHOUT ANY WARRANTY')
Chris@0 121 end
Chris@0 122
Chris@0 123 def test_directory_entry
Chris@0 124 get :entry, :id => 3, :path => ['sources']
Chris@0 125 assert_response :success
Chris@0 126 assert_template 'show'
Chris@0 127 assert_not_nil assigns(:entry)
Chris@0 128 assert_equal 'sources', assigns(:entry).name
Chris@0 129 end
Chris@117 130
Chris@0 131 def test_diff
Chris@117 132 @repository.fetch_changesets
Chris@117 133 @repository.reload
Chris@117 134
Chris@0 135 # Full diff of changeset 2f9c0091
Chris@0 136 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@0 137 assert_response :success
Chris@0 138 assert_template 'diff'
Chris@0 139 # Line 22 removed
Chris@0 140 assert_tag :tag => 'th',
Chris@0 141 :content => /22/,
Chris@0 142 :sibling => { :tag => 'td',
Chris@0 143 :attributes => { :class => /diff_out/ },
Chris@0 144 :content => /def remove/ }
Chris@117 145 assert_tag :tag => 'h2', :content => /2f9c0091/
Chris@117 146 end
Chris@117 147
Chris@117 148 def test_diff_two_revs
Chris@117 149 @repository.fetch_changesets
Chris@117 150 @repository.reload
Chris@117 151
Chris@117 152 get :diff, :id => 3, :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
Chris@117 153 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
Chris@117 154 assert_response :success
Chris@117 155 assert_template 'diff'
Chris@117 156
Chris@117 157 diff = assigns(:diff)
Chris@117 158 assert_not_nil diff
Chris@117 159 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
Chris@0 160 end
Chris@0 161
Chris@0 162 def test_annotate
Chris@0 163 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
Chris@0 164 assert_response :success
Chris@0 165 assert_template 'annotate'
Chris@0 166 # Line 23, changeset 2f9c0091
Chris@0 167 assert_tag :tag => 'th', :content => /24/,
Chris@0 168 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } },
Chris@0 169 :sibling => { :tag => 'td', :content => /jsmith/ },
Chris@0 170 :sibling => { :tag => 'td', :content => /watcher =/ }
Chris@0 171 end
Chris@117 172
Chris@0 173 def test_annotate_binary_file
Chris@0 174 get :annotate, :id => 3, :path => ['images', 'edit.png']
Chris@0 175 assert_response 500
chris@37 176 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
Chris@0 177 :content => /can not be annotated/
Chris@0 178 end
Chris@117 179
Chris@117 180 def test_revision
Chris@117 181 @repository.fetch_changesets
Chris@117 182 @repository.reload
Chris@117 183 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
Chris@117 184 get :revision, :id => 3, :rev => r
Chris@117 185 assert_response :success
Chris@117 186 assert_template 'revision'
Chris@117 187 end
Chris@117 188 end
Chris@117 189
Chris@117 190 def test_empty_revision
Chris@117 191 @repository.fetch_changesets
Chris@117 192 @repository.reload
Chris@117 193 ['', ' ', nil].each do |r|
Chris@117 194 get :revision, :id => 1, :rev => r
Chris@117 195 assert_response 500
Chris@117 196 assert_error_tag :content => /was not found/
Chris@117 197 end
Chris@117 198 end
Chris@0 199 else
Chris@0 200 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
Chris@0 201 def test_fake; assert true end
Chris@0 202 end
Chris@0 203 end