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_subversion_controller_test.rb @ 442:753f1380d6bc
History | View | Annotate | Download (10.9 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 RepositoriesSubversionControllerTest < ActionController::TestCase |
||
| 25 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
||
| 26 | :repositories, :issues, :issue_statuses, :changesets, :changes, |
||
| 27 | :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers |
||
| 28 | |||
| 29 | 245:051f544170fe | Chris | PRJ_ID = 3 |
| 30 | |||
| 31 | 0:513646585e45 | Chris | def setup |
| 32 | @controller = RepositoriesController.new |
||
| 33 | @request = ActionController::TestRequest.new |
||
| 34 | @response = ActionController::TestResponse.new |
||
| 35 | Setting.default_language = 'en' |
||
| 36 | User.current = nil |
||
| 37 | 245:051f544170fe | Chris | |
| 38 | @project = Project.find(PRJ_ID) |
||
| 39 | @repository = Repository::Subversion.create(:project => @project, |
||
| 40 | 441:cbce1fd3b1b7 | Chris | :url => self.class.subversion_repository_url) |
| 41 | 245:051f544170fe | Chris | assert @repository
|
| 42 | 0:513646585e45 | Chris | end
|
| 43 | |||
| 44 | if repository_configured?('subversion') |
||
| 45 | def test_show |
||
| 46 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 47 | @repository.reload
|
||
| 48 | get :show, :id => PRJ_ID |
||
| 49 | 0:513646585e45 | Chris | assert_response :success
|
| 50 | assert_template 'show'
|
||
| 51 | assert_not_nil assigns(:entries)
|
||
| 52 | assert_not_nil assigns(:changesets)
|
||
| 53 | end
|
||
| 54 | 441:cbce1fd3b1b7 | Chris | |
| 55 | 0:513646585e45 | Chris | def test_browse_root |
| 56 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 57 | @repository.reload
|
||
| 58 | get :show, :id => PRJ_ID |
||
| 59 | 0:513646585e45 | Chris | assert_response :success
|
| 60 | assert_template 'show'
|
||
| 61 | assert_not_nil assigns(:entries)
|
||
| 62 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} |
||
| 63 | assert_equal 'dir', entry.kind
|
||
| 64 | end
|
||
| 65 | 441:cbce1fd3b1b7 | Chris | |
| 66 | 0:513646585e45 | Chris | def test_browse_directory |
| 67 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 68 | @repository.reload
|
||
| 69 | get :show, :id => PRJ_ID, :path => ['subversion_test'] |
||
| 70 | 0:513646585e45 | Chris | assert_response :success
|
| 71 | assert_template 'show'
|
||
| 72 | assert_not_nil assigns(:entries)
|
||
| 73 | 441:cbce1fd3b1b7 | Chris | assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], |
| 74 | assigns(:entries).collect(&:name) |
||
| 75 | 0:513646585e45 | Chris | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
| 76 | assert_equal 'file', entry.kind
|
||
| 77 | assert_equal 'subversion_test/helloworld.c', entry.path
|
||
| 78 | assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } |
||
| 79 | end
|
||
| 80 | |||
| 81 | def test_browse_at_given_revision |
||
| 82 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 83 | @repository.reload
|
||
| 84 | get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4 |
||
| 85 | 0:513646585e45 | Chris | assert_response :success
|
| 86 | assert_template 'show'
|
||
| 87 | assert_not_nil assigns(:entries)
|
||
| 88 | 441:cbce1fd3b1b7 | Chris | assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], |
| 89 | assigns(:entries).collect(&:name) |
||
| 90 | 0:513646585e45 | Chris | end
|
| 91 | 441:cbce1fd3b1b7 | Chris | |
| 92 | 0:513646585e45 | Chris | def test_file_changes |
| 93 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 94 | @repository.reload
|
||
| 95 | get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ] |
||
| 96 | 0:513646585e45 | Chris | assert_response :success
|
| 97 | assert_template 'changes'
|
||
| 98 | 441:cbce1fd3b1b7 | Chris | |
| 99 | 0:513646585e45 | Chris | changesets = assigns(:changesets)
|
| 100 | assert_not_nil changesets |
||
| 101 | assert_equal %w(6 3 2), changesets.collect(&:revision) |
||
| 102 | 441:cbce1fd3b1b7 | Chris | |
| 103 | 0:513646585e45 | Chris | # svn properties displayed with svn >= 1.5 only
|
| 104 | if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) |
||
| 105 | assert_not_nil assigns(:properties)
|
||
| 106 | assert_equal 'native', assigns(:properties)['svn:eol-style'] |
||
| 107 | assert_tag :ul,
|
||
| 108 | :child => { :tag => 'li', |
||
| 109 | :child => { :tag => 'b', :content => 'svn:eol-style' }, |
||
| 110 | :child => { :tag => 'span', :content => 'native' } } |
||
| 111 | end
|
||
| 112 | end
|
||
| 113 | |||
| 114 | def test_directory_changes |
||
| 115 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 116 | @repository.reload
|
||
| 117 | get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ] |
||
| 118 | 0:513646585e45 | Chris | assert_response :success
|
| 119 | assert_template 'changes'
|
||
| 120 | 441:cbce1fd3b1b7 | Chris | |
| 121 | 0:513646585e45 | Chris | changesets = assigns(:changesets)
|
| 122 | assert_not_nil changesets |
||
| 123 | assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) |
||
| 124 | end
|
||
| 125 | 441:cbce1fd3b1b7 | Chris | |
| 126 | 0:513646585e45 | Chris | def test_entry |
| 127 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 128 | @repository.reload
|
||
| 129 | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] |
||
| 130 | 0:513646585e45 | Chris | assert_response :success
|
| 131 | assert_template 'entry'
|
||
| 132 | end
|
||
| 133 | 441:cbce1fd3b1b7 | Chris | |
| 134 | 0:513646585e45 | Chris | def test_entry_should_send_if_too_big |
| 135 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 136 | @repository.reload
|
||
| 137 | 0:513646585e45 | Chris | # no files in the test repo is larger than 1KB...
|
| 138 | with_settings :file_max_size_displayed => 0 do |
||
| 139 | 245:051f544170fe | Chris | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] |
| 140 | 0:513646585e45 | Chris | assert_response :success
|
| 141 | assert_template ''
|
||
| 142 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
||
| 143 | end
|
||
| 144 | end
|
||
| 145 | 441:cbce1fd3b1b7 | Chris | |
| 146 | 0:513646585e45 | Chris | def test_entry_at_given_revision |
| 147 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 148 | @repository.reload
|
||
| 149 | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 |
||
| 150 | 0:513646585e45 | Chris | assert_response :success
|
| 151 | assert_template 'entry'
|
||
| 152 | # this line was removed in r3 and file was moved in r6
|
||
| 153 | assert_tag :tag => 'td', :attributes => { :class => /line-code/}, |
||
| 154 | :content => /Here's the code/ |
||
| 155 | end
|
||
| 156 | 441:cbce1fd3b1b7 | Chris | |
| 157 | 0:513646585e45 | Chris | def test_entry_not_found |
| 158 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 159 | @repository.reload
|
||
| 160 | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c'] |
||
| 161 | 37:94944d00e43c | chris | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
| 162 | 0:513646585e45 | Chris | :content => /The entry or revision was not found in the repository/ |
| 163 | end
|
||
| 164 | 441:cbce1fd3b1b7 | Chris | |
| 165 | 0:513646585e45 | Chris | def test_entry_download |
| 166 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 167 | @repository.reload
|
||
| 168 | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' |
||
| 169 | 0:513646585e45 | Chris | assert_response :success
|
| 170 | assert_template ''
|
||
| 171 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
||
| 172 | end
|
||
| 173 | 441:cbce1fd3b1b7 | Chris | |
| 174 | 0:513646585e45 | Chris | def test_directory_entry |
| 175 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 176 | @repository.reload
|
||
| 177 | get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder'] |
||
| 178 | 0:513646585e45 | Chris | assert_response :success
|
| 179 | assert_template 'show'
|
||
| 180 | assert_not_nil assigns(:entry)
|
||
| 181 | assert_equal 'folder', assigns(:entry).name |
||
| 182 | end
|
||
| 183 | 441:cbce1fd3b1b7 | Chris | |
| 184 | 245:051f544170fe | Chris | # TODO: this test needs fixtures.
|
| 185 | 0:513646585e45 | Chris | def test_revision |
| 186 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 187 | @repository.reload
|
||
| 188 | 0:513646585e45 | Chris | get :revision, :id => 1, :rev => 2 |
| 189 | assert_response :success
|
||
| 190 | assert_template 'revision'
|
||
| 191 | assert_tag :tag => 'ul', |
||
| 192 | :child => { :tag => 'li', |
||
| 193 | # link to the entry at rev 2
|
||
| 194 | 441:cbce1fd3b1b7 | Chris | :child => { :tag => 'a', |
| 195 | 0:513646585e45 | Chris | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, |
| 196 | :content => 'repo', |
||
| 197 | # link to partial diff
|
||
| 198 | 441:cbce1fd3b1b7 | Chris | :sibling => { :tag => 'a', |
| 199 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } |
||
| 200 | 0:513646585e45 | Chris | } |
| 201 | } |
||
| 202 | } |
||
| 203 | end
|
||
| 204 | 441:cbce1fd3b1b7 | Chris | |
| 205 | 119:8661b858af72 | Chris | def test_invalid_revision |
| 206 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 207 | @repository.reload
|
||
| 208 | get :revision, :id => PRJ_ID, :rev => 'something_weird' |
||
| 209 | assert_response 404
|
||
| 210 | assert_error_tag :content => /was not found/ |
||
| 211 | end
|
||
| 212 | |||
| 213 | def test_invalid_revision_diff |
||
| 214 | get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird' |
||
| 215 | 128:07fa8a8b56a8 | Chris | assert_response 404
|
| 216 | 119:8661b858af72 | Chris | assert_error_tag :content => /was not found/ |
| 217 | end
|
||
| 218 | |||
| 219 | def test_empty_revision |
||
| 220 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 221 | @repository.reload
|
||
| 222 | 119:8661b858af72 | Chris | ['', ' ', nil].each do |r| |
| 223 | 245:051f544170fe | Chris | get :revision, :id => PRJ_ID, :rev => r |
| 224 | 128:07fa8a8b56a8 | Chris | assert_response 404
|
| 225 | 119:8661b858af72 | Chris | assert_error_tag :content => /was not found/ |
| 226 | end
|
||
| 227 | end
|
||
| 228 | |||
| 229 | 245:051f544170fe | Chris | # TODO: this test needs fixtures.
|
| 230 | 0:513646585e45 | Chris | def test_revision_with_repository_pointing_to_a_subdirectory |
| 231 | r = Project.find(1).repository |
||
| 232 | # Changes repository url to a subdirectory
|
||
| 233 | r.update_attribute :url, (r.url + '/test/some') |
||
| 234 | 441:cbce1fd3b1b7 | Chris | |
| 235 | 0:513646585e45 | Chris | get :revision, :id => 1, :rev => 2 |
| 236 | assert_response :success
|
||
| 237 | assert_template 'revision'
|
||
| 238 | assert_tag :tag => 'ul', |
||
| 239 | :child => { :tag => 'li', |
||
| 240 | # link to the entry at rev 2
|
||
| 241 | 441:cbce1fd3b1b7 | Chris | :child => { :tag => 'a', |
| 242 | 0:513646585e45 | Chris | :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, |
| 243 | :content => 'repo', |
||
| 244 | # link to partial diff
|
||
| 245 | 441:cbce1fd3b1b7 | Chris | :sibling => { :tag => 'a', |
| 246 | :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } |
||
| 247 | 0:513646585e45 | Chris | } |
| 248 | } |
||
| 249 | } |
||
| 250 | end
|
||
| 251 | 441:cbce1fd3b1b7 | Chris | |
| 252 | 0:513646585e45 | Chris | def test_revision_diff |
| 253 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 254 | @repository.reload
|
||
| 255 | get :diff, :id => PRJ_ID, :rev => 3 |
||
| 256 | 0:513646585e45 | Chris | assert_response :success
|
| 257 | assert_template 'diff'
|
||
| 258 | 119:8661b858af72 | Chris | |
| 259 | assert_tag :tag => 'h2', :content => /3/ |
||
| 260 | 0:513646585e45 | Chris | end
|
| 261 | |||
| 262 | def test_directory_diff |
||
| 263 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 264 | @repository.reload
|
||
| 265 | get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] |
||
| 266 | 0:513646585e45 | Chris | assert_response :success
|
| 267 | assert_template 'diff'
|
||
| 268 | 441:cbce1fd3b1b7 | Chris | |
| 269 | 0:513646585e45 | Chris | diff = assigns(:diff)
|
| 270 | assert_not_nil diff |
||
| 271 | # 2 files modified
|
||
| 272 | assert_equal 2, Redmine::UnifiedDiff.new(diff).size |
||
| 273 | 119:8661b858af72 | Chris | |
| 274 | assert_tag :tag => 'h2', :content => /2:6/ |
||
| 275 | 0:513646585e45 | Chris | end
|
| 276 | 441:cbce1fd3b1b7 | Chris | |
| 277 | 0:513646585e45 | Chris | def test_annotate |
| 278 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 279 | @repository.reload
|
||
| 280 | get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] |
||
| 281 | 0:513646585e45 | Chris | assert_response :success
|
| 282 | assert_template 'annotate'
|
||
| 283 | end
|
||
| 284 | 210:0579821a129a | Chris | |
| 285 | def test_annotate_at_given_revision |
||
| 286 | 245:051f544170fe | Chris | @repository.fetch_changesets
|
| 287 | @repository.reload
|
||
| 288 | get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c'] |
||
| 289 | 210:0579821a129a | Chris | assert_response :success
|
| 290 | assert_template 'annotate'
|
||
| 291 | assert_tag :tag => 'h2', :content => /@ 8/ |
||
| 292 | end
|
||
| 293 | 0:513646585e45 | Chris | else
|
| 294 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
|
||
| 295 | def test_fake; assert true end |
||
| 296 | end
|
||
| 297 | end |