To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / test / functional / repositories_git_controller_test.rb @ 441:cbce1fd3b1b7
History | View | Annotate | Download (12.3 KB)
| 1 | 441:cbce1fd3b1b7 | Chris | # Redmine - project management software
|
|---|---|---|---|
| 2 | # Copyright (C) 2006-2011 Jean-Philippe Lang
|
||
| 3 | 0:513646585e45 | Chris | #
|
| 4 | # This program is free software; you can redistribute it and/or
|
||
| 5 | # modify it under the terms of the GNU General Public License
|
||
| 6 | # as published by the Free Software Foundation; either version 2
|
||
| 7 | # of the License, or (at your option) any later version.
|
||
| 8 | 441:cbce1fd3b1b7 | Chris | #
|
| 9 | 0:513646585e45 | Chris | # This program is distributed in the hope that it will be useful,
|
| 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
| 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
| 12 | # GNU General Public License for more details.
|
||
| 13 | 441:cbce1fd3b1b7 | Chris | #
|
| 14 | 0:513646585e45 | Chris | # You should have received a copy of the GNU General Public License
|
| 15 | # along with this program; if not, write to the Free Software
|
||
| 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||
| 17 | |||
| 18 | 119:8661b858af72 | Chris | require File.expand_path('../../test_helper', __FILE__) |
| 19 | 0:513646585e45 | Chris | require 'repositories_controller'
|
| 20 | |||
| 21 | # Re-raise errors caught by the controller.
|
||
| 22 | class RepositoriesController; def rescue_action(e) raise e end; end |
||
| 23 | |||
| 24 | class RepositoriesGitControllerTest < ActionController::TestCase |
||
| 25 | fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules |
||
| 26 | |||
| 27 | # No '..' in the repository path
|
||
| 28 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' |
||
| 29 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
||
| 30 | 441:cbce1fd3b1b7 | Chris | PRJ_ID = 3 |
| 31 | CHAR_1_HEX = "\xc3\x9c" |
||
| 32 | 0:513646585e45 | Chris | |
| 33 | def setup |
||
| 34 | 441:cbce1fd3b1b7 | Chris | @ruby19_non_utf8_pass =
|
| 35 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
||
| 36 | |||
| 37 | 0:513646585e45 | Chris | @controller = RepositoriesController.new |
| 38 | @request = ActionController::TestRequest.new |
||
| 39 | @response = ActionController::TestResponse.new |
||
| 40 | User.current = nil |
||
| 41 | 441:cbce1fd3b1b7 | Chris | @repository = Repository::Git.create( |
| 42 | :project => Project.find(3), |
||
| 43 | :url => REPOSITORY_PATH, |
||
| 44 | :path_encoding => 'ISO-8859-1' |
||
| 45 | ) |
||
| 46 | 119:8661b858af72 | Chris | assert @repository
|
| 47 | 441:cbce1fd3b1b7 | Chris | @char_1 = CHAR_1_HEX.dup |
| 48 | if @char_1.respond_to?(:force_encoding) |
||
| 49 | @char_1.force_encoding('UTF-8') |
||
| 50 | end
|
||
| 51 | 0:513646585e45 | Chris | end
|
| 52 | 119:8661b858af72 | Chris | |
| 53 | 0:513646585e45 | Chris | if File.directory?(REPOSITORY_PATH) |
| 54 | def test_browse_root |
||
| 55 | 441:cbce1fd3b1b7 | Chris | @repository.fetch_changesets
|
| 56 | @repository.reload
|
||
| 57 | get :show, :id => PRJ_ID |
||
| 58 | 0:513646585e45 | Chris | assert_response :success
|
| 59 | assert_template 'show'
|
||
| 60 | assert_not_nil assigns(:entries)
|
||
| 61 | 37:94944d00e43c | chris | assert_equal 9, assigns(:entries).size |
| 62 | 0:513646585e45 | Chris | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
| 63 | assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'} |
||
| 64 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
||
| 65 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
||
| 66 | assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} |
||
| 67 | assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} |
||
| 68 | assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} |
||
| 69 | 37:94944d00e43c | chris | assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} |
| 70 | assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} |
||
| 71 | 441:cbce1fd3b1b7 | Chris | assert_not_nil assigns(:changesets)
|
| 72 | assigns(:changesets).size > 0 |
||
| 73 | 0:513646585e45 | Chris | end
|
| 74 | |||
| 75 | def test_browse_branch |
||
| 76 | 441:cbce1fd3b1b7 | Chris | @repository.fetch_changesets
|
| 77 | @repository.reload
|
||
| 78 | get :show, :id => PRJ_ID, :rev => 'test_branch' |
||
| 79 | 0:513646585e45 | Chris | assert_response :success
|
| 80 | assert_template 'show'
|
||
| 81 | assert_not_nil assigns(:entries)
|
||
| 82 | assert_equal 4, assigns(:entries).size |
||
| 83 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
||
| 84 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
||
| 85 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
||
| 86 | assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} |
||
| 87 | 441:cbce1fd3b1b7 | Chris | assert_not_nil assigns(:changesets)
|
| 88 | assigns(:changesets).size > 0 |
||
| 89 | end
|
||
| 90 | |||
| 91 | def test_browse_tag |
||
| 92 | @repository.fetch_changesets
|
||
| 93 | @repository.reload
|
||
| 94 | [ |
||
| 95 | "tag00.lightweight",
|
||
| 96 | "tag01.annotated",
|
||
| 97 | ].each do |t1|
|
||
| 98 | get :show, :id => PRJ_ID, :rev => t1 |
||
| 99 | assert_response :success
|
||
| 100 | assert_template 'show'
|
||
| 101 | assert_not_nil assigns(:entries)
|
||
| 102 | assigns(:entries).size > 0 |
||
| 103 | assert_not_nil assigns(:changesets)
|
||
| 104 | assigns(:changesets).size > 0 |
||
| 105 | end
|
||
| 106 | 0:513646585e45 | Chris | end
|
| 107 | |||
| 108 | def test_browse_directory |
||
| 109 | 441:cbce1fd3b1b7 | Chris | @repository.fetch_changesets
|
| 110 | @repository.reload
|
||
| 111 | get :show, :id => PRJ_ID, :path => ['images'] |
||
| 112 | 0:513646585e45 | Chris | assert_response :success
|
| 113 | assert_template 'show'
|
||
| 114 | assert_not_nil assigns(:entries)
|
||
| 115 | assert_equal ['edit.png'], assigns(:entries).collect(&:name) |
||
| 116 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
||
| 117 | assert_not_nil entry |
||
| 118 | assert_equal 'file', entry.kind
|
||
| 119 | assert_equal 'images/edit.png', entry.path
|
||
| 120 | 441:cbce1fd3b1b7 | Chris | assert_not_nil assigns(:changesets)
|
| 121 | assigns(:changesets).size > 0 |
||
| 122 | 0:513646585e45 | Chris | end
|
| 123 | 441:cbce1fd3b1b7 | Chris | |
| 124 | 0:513646585e45 | Chris | def test_browse_at_given_revision |
| 125 | 441:cbce1fd3b1b7 | Chris | @repository.fetch_changesets
|
| 126 | @repository.reload
|
||
| 127 | get :show, :id => PRJ_ID, :path => ['images'], |
||
| 128 | :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' |
||
| 129 | 0:513646585e45 | Chris | assert_response :success
|
| 130 | assert_template 'show'
|
||
| 131 | assert_not_nil assigns(:entries)
|
||
| 132 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
||
| 133 | 441:cbce1fd3b1b7 | Chris | assert_not_nil assigns(:changesets)
|
| 134 | assigns(:changesets).size > 0 |
||
| 135 | 0:513646585e45 | Chris | end
|
| 136 | |||
| 137 | def test_changes |
||
| 138 | 441:cbce1fd3b1b7 | Chris | get :changes, :id => PRJ_ID, :path => ['images', 'edit.png'] |
| 139 | 0:513646585e45 | Chris | assert_response :success
|
| 140 | assert_template 'changes'
|
||
| 141 | assert_tag :tag => 'h2', :content => 'edit.png' |
||
| 142 | end
|
||
| 143 | 441:cbce1fd3b1b7 | Chris | |
| 144 | 0:513646585e45 | Chris | def test_entry_show |
| 145 | 441:cbce1fd3b1b7 | Chris | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
| 146 | 0:513646585e45 | Chris | assert_response :success
|
| 147 | assert_template 'entry'
|
||
| 148 | # Line 19
|
||
| 149 | assert_tag :tag => 'th', |
||
| 150 | 441:cbce1fd3b1b7 | Chris | :content => '11', |
| 151 | :attributes => { :class => 'line-num' }, |
||
| 152 | 0:513646585e45 | Chris | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
| 153 | end
|
||
| 154 | 441:cbce1fd3b1b7 | Chris | |
| 155 | def test_entry_show_latin_1 |
||
| 156 | if @ruby19_non_utf8_pass |
||
| 157 | puts_ruby19_non_utf8_pass() |
||
| 158 | else
|
||
| 159 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
||
| 160 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
||
| 161 | get :entry, :id => PRJ_ID, |
||
| 162 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
||
| 163 | assert_response :success
|
||
| 164 | assert_template 'entry'
|
||
| 165 | assert_tag :tag => 'th', |
||
| 166 | :content => '1', |
||
| 167 | :attributes => { :class => 'line-num' }, |
||
| 168 | :sibling => { :tag => 'td', |
||
| 169 | :content => /test-#{@char_1}.txt/ } |
||
| 170 | end
|
||
| 171 | end
|
||
| 172 | end
|
||
| 173 | end
|
||
| 174 | |||
| 175 | 0:513646585e45 | Chris | def test_entry_download |
| 176 | 441:cbce1fd3b1b7 | Chris | get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'], |
| 177 | :format => 'raw' |
||
| 178 | 0:513646585e45 | Chris | assert_response :success
|
| 179 | # File content
|
||
| 180 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
||
| 181 | end
|
||
| 182 | 441:cbce1fd3b1b7 | Chris | |
| 183 | 0:513646585e45 | Chris | def test_directory_entry |
| 184 | 441:cbce1fd3b1b7 | Chris | get :entry, :id => PRJ_ID, :path => ['sources'] |
| 185 | 0:513646585e45 | Chris | assert_response :success
|
| 186 | assert_template 'show'
|
||
| 187 | assert_not_nil assigns(:entry)
|
||
| 188 | assert_equal 'sources', assigns(:entry).name |
||
| 189 | end
|
||
| 190 | 119:8661b858af72 | Chris | |
| 191 | 0:513646585e45 | Chris | def test_diff |
| 192 | 119:8661b858af72 | Chris | @repository.fetch_changesets
|
| 193 | @repository.reload
|
||
| 194 | 0:513646585e45 | Chris | # Full diff of changeset 2f9c0091
|
| 195 | 441:cbce1fd3b1b7 | Chris | get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
| 196 | 0:513646585e45 | Chris | assert_response :success
|
| 197 | assert_template 'diff'
|
||
| 198 | # Line 22 removed
|
||
| 199 | assert_tag :tag => 'th', |
||
| 200 | :content => /22/, |
||
| 201 | 441:cbce1fd3b1b7 | Chris | :sibling => { :tag => 'td', |
| 202 | 0:513646585e45 | Chris | :attributes => { :class => /diff_out/ }, |
| 203 | :content => /def remove/ } |
||
| 204 | 119:8661b858af72 | Chris | assert_tag :tag => 'h2', :content => /2f9c0091/ |
| 205 | end
|
||
| 206 | |||
| 207 | def test_diff_two_revs |
||
| 208 | @repository.fetch_changesets
|
||
| 209 | @repository.reload
|
||
| 210 | 441:cbce1fd3b1b7 | Chris | get :diff, :id => PRJ_ID, |
| 211 | :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
||
| 212 | :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' |
||
| 213 | 119:8661b858af72 | Chris | assert_response :success
|
| 214 | assert_template 'diff'
|
||
| 215 | diff = assigns(:diff)
|
||
| 216 | assert_not_nil diff |
||
| 217 | assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/ |
||
| 218 | 0:513646585e45 | Chris | end
|
| 219 | |||
| 220 | 441:cbce1fd3b1b7 | Chris | def test_diff_latin_1 |
| 221 | if @ruby19_non_utf8_pass |
||
| 222 | puts_ruby19_non_utf8_pass() |
||
| 223 | else
|
||
| 224 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
||
| 225 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
||
| 226 | get :diff, :id => PRJ_ID, :rev => r1 |
||
| 227 | assert_response :success
|
||
| 228 | assert_template 'diff'
|
||
| 229 | assert_tag :tag => 'thead', |
||
| 230 | :descendant => {
|
||
| 231 | :tag => 'th', |
||
| 232 | :attributes => { :class => 'filename' } , |
||
| 233 | :content => /latin-1-dir\/test-#{@char_1}.txt/ , |
||
| 234 | }, |
||
| 235 | :sibling => {
|
||
| 236 | :tag => 'tbody', |
||
| 237 | :descendant => {
|
||
| 238 | :tag => 'td', |
||
| 239 | :attributes => { :class => /diff_in/ }, |
||
| 240 | :content => /test-#{@char_1}.txt/ |
||
| 241 | } |
||
| 242 | } |
||
| 243 | end
|
||
| 244 | end
|
||
| 245 | end
|
||
| 246 | end
|
||
| 247 | |||
| 248 | 0:513646585e45 | Chris | def test_annotate |
| 249 | 441:cbce1fd3b1b7 | Chris | get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'] |
| 250 | 0:513646585e45 | Chris | assert_response :success
|
| 251 | assert_template 'annotate'
|
||
| 252 | # Line 23, changeset 2f9c0091
|
||
| 253 | 441:cbce1fd3b1b7 | Chris | assert_tag :tag => 'th', :content => '24', |
| 254 | :sibling => {
|
||
| 255 | :tag => 'td', |
||
| 256 | :child => {
|
||
| 257 | :tag => 'a', |
||
| 258 | :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/ |
||
| 259 | } |
||
| 260 | }, |
||
| 261 | :sibling => { :tag => 'td', :content => /jsmith/ } |
||
| 262 | assert_tag :tag => 'th', :content => '24', |
||
| 263 | :sibling => {
|
||
| 264 | :tag => 'td', |
||
| 265 | :child => {
|
||
| 266 | :tag => 'a', |
||
| 267 | :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/ |
||
| 268 | } |
||
| 269 | }, |
||
| 270 | 0:513646585e45 | Chris | :sibling => { :tag => 'td', :content => /watcher =/ } |
| 271 | end
|
||
| 272 | 119:8661b858af72 | Chris | |
| 273 | 210:0579821a129a | Chris | def test_annotate_at_given_revision |
| 274 | @repository.fetch_changesets
|
||
| 275 | @repository.reload
|
||
| 276 | 441:cbce1fd3b1b7 | Chris | get :annotate, :id => PRJ_ID, :rev => 'deff7', |
| 277 | :path => ['sources', 'watchers_controller.rb'] |
||
| 278 | 210:0579821a129a | Chris | assert_response :success
|
| 279 | assert_template 'annotate'
|
||
| 280 | assert_tag :tag => 'h2', :content => /@ deff712f/ |
||
| 281 | end
|
||
| 282 | |||
| 283 | 0:513646585e45 | Chris | def test_annotate_binary_file |
| 284 | 441:cbce1fd3b1b7 | Chris | get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png'] |
| 285 | 0:513646585e45 | Chris | assert_response 500
|
| 286 | 37:94944d00e43c | chris | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
| 287 | 441:cbce1fd3b1b7 | Chris | :content => /cannot be annotated/ |
| 288 | end
|
||
| 289 | |||
| 290 | def test_annotate_latin_1 |
||
| 291 | if @ruby19_non_utf8_pass |
||
| 292 | puts_ruby19_non_utf8_pass() |
||
| 293 | else
|
||
| 294 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
||
| 295 | ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1| |
||
| 296 | get :annotate, :id => PRJ_ID, |
||
| 297 | :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1 |
||
| 298 | assert_tag :tag => 'th', |
||
| 299 | :content => '1', |
||
| 300 | :attributes => { :class => 'line-num' }, |
||
| 301 | :sibling => { :tag => 'td', |
||
| 302 | :content => /test-#{@char_1}.txt/ } |
||
| 303 | end
|
||
| 304 | end
|
||
| 305 | end
|
||
| 306 | 0:513646585e45 | Chris | end
|
| 307 | 119:8661b858af72 | Chris | |
| 308 | def test_revision |
||
| 309 | @repository.fetch_changesets
|
||
| 310 | @repository.reload
|
||
| 311 | ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r| |
||
| 312 | 441:cbce1fd3b1b7 | Chris | get :revision, :id => PRJ_ID, :rev => r |
| 313 | 119:8661b858af72 | Chris | assert_response :success
|
| 314 | assert_template 'revision'
|
||
| 315 | end
|
||
| 316 | end
|
||
| 317 | |||
| 318 | def test_empty_revision |
||
| 319 | @repository.fetch_changesets
|
||
| 320 | @repository.reload
|
||
| 321 | ['', ' ', nil].each do |r| |
||
| 322 | 441:cbce1fd3b1b7 | Chris | get :revision, :id => PRJ_ID, :rev => r |
| 323 | 128:07fa8a8b56a8 | Chris | assert_response 404
|
| 324 | 119:8661b858af72 | Chris | assert_error_tag :content => /was not found/ |
| 325 | end
|
||
| 326 | end
|
||
| 327 | 441:cbce1fd3b1b7 | Chris | |
| 328 | private |
||
| 329 | |||
| 330 | def puts_ruby19_non_utf8_pass |
||
| 331 | puts "TODO: This test fails in Ruby 1.9 " +
|
||
| 332 | "and Encoding.default_external is not UTF-8. " +
|
||
| 333 | "Current value is '#{Encoding.default_external.to_s}'"
|
||
| 334 | end
|
||
| 335 | 0:513646585e45 | Chris | else
|
| 336 | puts "Git test repository NOT FOUND. Skipping functional tests !!!"
|
||
| 337 | def test_fake; assert true end |
||
| 338 | end
|
||
| 339 | end |