Mercurial > hg > soundsoftware-site
comparison test/functional/repositories_subversion_controller_test.rb @ 524:1248a47e81b3 feature_36
Merge from branch "luisf"
author | luisf <luis.figueira@eecs.qmul.ac.uk> |
---|---|
date | Mon, 25 Jul 2011 14:39:38 +0100 |
parents | cbce1fd3b1b7 |
children | cbb26bc654de |
comparison
equal
deleted
inserted
replaced
519:3be6bc3c2a17 | 524:1248a47e81b3 |
---|---|
1 # redMine - project management software | 1 # Redmine - project management software |
2 # Copyright (C) 2006-2008 Jean-Philippe Lang | 2 # Copyright (C) 2006-2011 Jean-Philippe Lang |
3 # | 3 # |
4 # This program is free software; you can redistribute it and/or | 4 # This program is free software; you can redistribute it and/or |
5 # modify it under the terms of the GNU General Public License | 5 # modify it under the terms of the GNU General Public License |
6 # as published by the Free Software Foundation; either version 2 | 6 # as published by the Free Software Foundation; either version 2 |
7 # of the License, or (at your option) any later version. | 7 # of the License, or (at your option) any later version. |
8 # | 8 # |
9 # This program is distributed in the hope that it will be useful, | 9 # This program is distributed in the hope that it will be useful, |
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 # GNU General Public License for more details. | 12 # GNU General Public License for more details. |
13 # | 13 # |
14 # You should have received a copy of the GNU General Public License | 14 # You should have received a copy of the GNU General Public License |
15 # along with this program; if not, write to the Free Software | 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. | 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
17 | 17 |
18 require File.dirname(__FILE__) + '/../test_helper' | 18 require File.expand_path('../../test_helper', __FILE__) |
19 require 'repositories_controller' | 19 require 'repositories_controller' |
20 | 20 |
21 # Re-raise errors caught by the controller. | 21 # Re-raise errors caught by the controller. |
22 class RepositoriesController; def rescue_action(e) raise e end; end | 22 class RepositoriesController; def rescue_action(e) raise e end; end |
23 | 23 |
24 class RepositoriesSubversionControllerTest < ActionController::TestCase | 24 class RepositoriesSubversionControllerTest < ActionController::TestCase |
25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, | 25 fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
26 :repositories, :issues, :issue_statuses, :changesets, :changes, | 26 :repositories, :issues, :issue_statuses, :changesets, :changes, |
27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers | 27 :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers |
28 | |
29 PRJ_ID = 3 | |
28 | 30 |
29 def setup | 31 def setup |
30 @controller = RepositoriesController.new | 32 @controller = RepositoriesController.new |
31 @request = ActionController::TestRequest.new | 33 @request = ActionController::TestRequest.new |
32 @response = ActionController::TestResponse.new | 34 @response = ActionController::TestResponse.new |
33 Setting.default_language = 'en' | 35 Setting.default_language = 'en' |
34 User.current = nil | 36 User.current = nil |
37 | |
38 @project = Project.find(PRJ_ID) | |
39 @repository = Repository::Subversion.create(:project => @project, | |
40 :url => self.class.subversion_repository_url) | |
41 assert @repository | |
35 end | 42 end |
36 | 43 |
37 if repository_configured?('subversion') | 44 if repository_configured?('subversion') |
38 def test_show | 45 def test_show |
39 get :show, :id => 1 | 46 @repository.fetch_changesets |
47 @repository.reload | |
48 get :show, :id => PRJ_ID | |
40 assert_response :success | 49 assert_response :success |
41 assert_template 'show' | 50 assert_template 'show' |
42 assert_not_nil assigns(:entries) | 51 assert_not_nil assigns(:entries) |
43 assert_not_nil assigns(:changesets) | 52 assert_not_nil assigns(:changesets) |
44 end | 53 end |
45 | 54 |
46 def test_browse_root | 55 def test_browse_root |
47 get :show, :id => 1 | 56 @repository.fetch_changesets |
57 @repository.reload | |
58 get :show, :id => PRJ_ID | |
48 assert_response :success | 59 assert_response :success |
49 assert_template 'show' | 60 assert_template 'show' |
50 assert_not_nil assigns(:entries) | 61 assert_not_nil assigns(:entries) |
51 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} | 62 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} |
52 assert_equal 'dir', entry.kind | 63 assert_equal 'dir', entry.kind |
53 end | 64 end |
54 | 65 |
55 def test_browse_directory | 66 def test_browse_directory |
56 get :show, :id => 1, :path => ['subversion_test'] | 67 @repository.fetch_changesets |
57 assert_response :success | 68 @repository.reload |
58 assert_template 'show' | 69 get :show, :id => PRJ_ID, :path => ['subversion_test'] |
59 assert_not_nil assigns(:entries) | 70 assert_response :success |
60 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], assigns(:entries).collect(&:name) | 71 assert_template 'show' |
72 assert_not_nil assigns(:entries) | |
73 assert_equal ['[folder_with_brackets]', 'folder', '.project', 'helloworld.c', 'textfile.txt'], | |
74 assigns(:entries).collect(&:name) | |
61 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} | 75 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
62 assert_equal 'file', entry.kind | 76 assert_equal 'file', entry.kind |
63 assert_equal 'subversion_test/helloworld.c', entry.path | 77 assert_equal 'subversion_test/helloworld.c', entry.path |
64 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } | 78 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } |
65 end | 79 end |
66 | 80 |
67 def test_browse_at_given_revision | 81 def test_browse_at_given_revision |
68 get :show, :id => 1, :path => ['subversion_test'], :rev => 4 | 82 @repository.fetch_changesets |
69 assert_response :success | 83 @repository.reload |
70 assert_template 'show' | 84 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4 |
71 assert_not_nil assigns(:entries) | 85 assert_response :success |
72 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], assigns(:entries).collect(&:name) | 86 assert_template 'show' |
73 end | 87 assert_not_nil assigns(:entries) |
74 | 88 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], |
89 assigns(:entries).collect(&:name) | |
90 end | |
91 | |
75 def test_file_changes | 92 def test_file_changes |
76 get :changes, :id => 1, :path => ['subversion_test', 'folder', 'helloworld.rb' ] | 93 @repository.fetch_changesets |
94 @repository.reload | |
95 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ] | |
77 assert_response :success | 96 assert_response :success |
78 assert_template 'changes' | 97 assert_template 'changes' |
79 | 98 |
80 changesets = assigns(:changesets) | 99 changesets = assigns(:changesets) |
81 assert_not_nil changesets | 100 assert_not_nil changesets |
82 assert_equal %w(6 3 2), changesets.collect(&:revision) | 101 assert_equal %w(6 3 2), changesets.collect(&:revision) |
83 | 102 |
84 # svn properties displayed with svn >= 1.5 only | 103 # svn properties displayed with svn >= 1.5 only |
85 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) | 104 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) |
86 assert_not_nil assigns(:properties) | 105 assert_not_nil assigns(:properties) |
87 assert_equal 'native', assigns(:properties)['svn:eol-style'] | 106 assert_equal 'native', assigns(:properties)['svn:eol-style'] |
88 assert_tag :ul, | 107 assert_tag :ul, |
91 :child => { :tag => 'span', :content => 'native' } } | 110 :child => { :tag => 'span', :content => 'native' } } |
92 end | 111 end |
93 end | 112 end |
94 | 113 |
95 def test_directory_changes | 114 def test_directory_changes |
96 get :changes, :id => 1, :path => ['subversion_test', 'folder' ] | 115 @repository.fetch_changesets |
116 @repository.reload | |
117 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ] | |
97 assert_response :success | 118 assert_response :success |
98 assert_template 'changes' | 119 assert_template 'changes' |
99 | 120 |
100 changesets = assigns(:changesets) | 121 changesets = assigns(:changesets) |
101 assert_not_nil changesets | 122 assert_not_nil changesets |
102 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) | 123 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) |
103 end | 124 end |
104 | 125 |
105 def test_entry | 126 def test_entry |
106 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | 127 @repository.fetch_changesets |
128 @repository.reload | |
129 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] | |
107 assert_response :success | 130 assert_response :success |
108 assert_template 'entry' | 131 assert_template 'entry' |
109 end | 132 end |
110 | 133 |
111 def test_entry_should_send_if_too_big | 134 def test_entry_should_send_if_too_big |
135 @repository.fetch_changesets | |
136 @repository.reload | |
112 # no files in the test repo is larger than 1KB... | 137 # no files in the test repo is larger than 1KB... |
113 with_settings :file_max_size_displayed => 0 do | 138 with_settings :file_max_size_displayed => 0 do |
114 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'] | 139 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] |
115 assert_response :success | 140 assert_response :success |
116 assert_template '' | 141 assert_template '' |
117 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | 142 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
118 end | 143 end |
119 end | 144 end |
120 | 145 |
121 def test_entry_at_given_revision | 146 def test_entry_at_given_revision |
122 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 | 147 @repository.fetch_changesets |
148 @repository.reload | |
149 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2 | |
123 assert_response :success | 150 assert_response :success |
124 assert_template 'entry' | 151 assert_template 'entry' |
125 # this line was removed in r3 and file was moved in r6 | 152 # this line was removed in r3 and file was moved in r6 |
126 assert_tag :tag => 'td', :attributes => { :class => /line-code/}, | 153 assert_tag :tag => 'td', :attributes => { :class => /line-code/}, |
127 :content => /Here's the code/ | 154 :content => /Here's the code/ |
128 end | 155 end |
129 | 156 |
130 def test_entry_not_found | 157 def test_entry_not_found |
131 get :entry, :id => 1, :path => ['subversion_test', 'zzz.c'] | 158 @repository.fetch_changesets |
159 @repository.reload | |
160 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c'] | |
132 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, | 161 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
133 :content => /The entry or revision was not found in the repository/ | 162 :content => /The entry or revision was not found in the repository/ |
134 end | 163 end |
135 | 164 |
136 def test_entry_download | 165 def test_entry_download |
137 get :entry, :id => 1, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' | 166 @repository.fetch_changesets |
167 @repository.reload | |
168 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw' | |
138 assert_response :success | 169 assert_response :success |
139 assert_template '' | 170 assert_template '' |
140 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] | 171 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
141 end | 172 end |
142 | 173 |
143 def test_directory_entry | 174 def test_directory_entry |
144 get :entry, :id => 1, :path => ['subversion_test', 'folder'] | 175 @repository.fetch_changesets |
176 @repository.reload | |
177 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder'] | |
145 assert_response :success | 178 assert_response :success |
146 assert_template 'show' | 179 assert_template 'show' |
147 assert_not_nil assigns(:entry) | 180 assert_not_nil assigns(:entry) |
148 assert_equal 'folder', assigns(:entry).name | 181 assert_equal 'folder', assigns(:entry).name |
149 end | 182 end |
150 | 183 |
184 # TODO: this test needs fixtures. | |
151 def test_revision | 185 def test_revision |
186 @repository.fetch_changesets | |
187 @repository.reload | |
152 get :revision, :id => 1, :rev => 2 | 188 get :revision, :id => 1, :rev => 2 |
153 assert_response :success | 189 assert_response :success |
154 assert_template 'revision' | 190 assert_template 'revision' |
155 assert_tag :tag => 'ul', | 191 assert_tag :tag => 'ul', |
156 :child => { :tag => 'li', | 192 :child => { :tag => 'li', |
157 # link to the entry at rev 2 | 193 # link to the entry at rev 2 |
158 :child => { :tag => 'a', | 194 :child => { :tag => 'a', |
159 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, | 195 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'}, |
160 :content => 'repo', | 196 :content => 'repo', |
161 # link to partial diff | 197 # link to partial diff |
162 :sibling => { :tag => 'a', | 198 :sibling => { :tag => 'a', |
163 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } | 199 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' } |
164 } | 200 } |
165 } | 201 } |
166 } | 202 } |
167 end | 203 end |
168 | 204 |
205 def test_invalid_revision | |
206 @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 assert_response 404 | |
216 assert_error_tag :content => /was not found/ | |
217 end | |
218 | |
219 def test_empty_revision | |
220 @repository.fetch_changesets | |
221 @repository.reload | |
222 ['', ' ', nil].each do |r| | |
223 get :revision, :id => PRJ_ID, :rev => r | |
224 assert_response 404 | |
225 assert_error_tag :content => /was not found/ | |
226 end | |
227 end | |
228 | |
229 # TODO: this test needs fixtures. | |
169 def test_revision_with_repository_pointing_to_a_subdirectory | 230 def test_revision_with_repository_pointing_to_a_subdirectory |
170 r = Project.find(1).repository | 231 r = Project.find(1).repository |
171 # Changes repository url to a subdirectory | 232 # Changes repository url to a subdirectory |
172 r.update_attribute :url, (r.url + '/test/some') | 233 r.update_attribute :url, (r.url + '/test/some') |
173 | 234 |
174 get :revision, :id => 1, :rev => 2 | 235 get :revision, :id => 1, :rev => 2 |
175 assert_response :success | 236 assert_response :success |
176 assert_template 'revision' | 237 assert_template 'revision' |
177 assert_tag :tag => 'ul', | 238 assert_tag :tag => 'ul', |
178 :child => { :tag => 'li', | 239 :child => { :tag => 'li', |
179 # link to the entry at rev 2 | 240 # link to the entry at rev 2 |
180 :child => { :tag => 'a', | 241 :child => { :tag => 'a', |
181 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, | 242 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'}, |
182 :content => 'repo', | 243 :content => 'repo', |
183 # link to partial diff | 244 # link to partial diff |
184 :sibling => { :tag => 'a', | 245 :sibling => { :tag => 'a', |
185 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } | 246 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' } |
186 } | 247 } |
187 } | 248 } |
188 } | 249 } |
189 end | 250 end |
190 | 251 |
191 def test_revision_diff | 252 def test_revision_diff |
192 get :diff, :id => 1, :rev => 3 | 253 @repository.fetch_changesets |
254 @repository.reload | |
255 get :diff, :id => PRJ_ID, :rev => 3 | |
193 assert_response :success | 256 assert_response :success |
194 assert_template 'diff' | 257 assert_template 'diff' |
258 | |
259 assert_tag :tag => 'h2', :content => /3/ | |
195 end | 260 end |
196 | 261 |
197 def test_directory_diff | 262 def test_directory_diff |
198 get :diff, :id => 1, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] | 263 @repository.fetch_changesets |
264 @repository.reload | |
265 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, :path => ['subversion_test', 'folder'] | |
199 assert_response :success | 266 assert_response :success |
200 assert_template 'diff' | 267 assert_template 'diff' |
201 | 268 |
202 diff = assigns(:diff) | 269 diff = assigns(:diff) |
203 assert_not_nil diff | 270 assert_not_nil diff |
204 # 2 files modified | 271 # 2 files modified |
205 assert_equal 2, Redmine::UnifiedDiff.new(diff).size | 272 assert_equal 2, Redmine::UnifiedDiff.new(diff).size |
206 end | 273 |
207 | 274 assert_tag :tag => 'h2', :content => /2:6/ |
275 end | |
276 | |
208 def test_annotate | 277 def test_annotate |
209 get :annotate, :id => 1, :path => ['subversion_test', 'helloworld.c'] | 278 @repository.fetch_changesets |
279 @repository.reload | |
280 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'] | |
210 assert_response :success | 281 assert_response :success |
211 assert_template 'annotate' | 282 assert_template 'annotate' |
283 end | |
284 | |
285 def test_annotate_at_given_revision | |
286 @repository.fetch_changesets | |
287 @repository.reload | |
288 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c'] | |
289 assert_response :success | |
290 assert_template 'annotate' | |
291 assert_tag :tag => 'h2', :content => /@ 8/ | |
212 end | 292 end |
213 else | 293 else |
214 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" | 294 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" |
215 def test_fake; assert true end | 295 def test_fake; assert true end |
216 end | 296 end |