@@ -1,425 +1,425 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2013 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RepositoriesSubversionControllerTest < ActionController::TestCase |
|
21 | 21 | tests RepositoriesController |
|
22 | 22 | |
|
23 | 23 | fixtures :projects, :users, :roles, :members, :member_roles, :enabled_modules, |
|
24 | 24 | :repositories, :issues, :issue_statuses, :changesets, :changes, |
|
25 | 25 | :issue_categories, :enumerations, :custom_fields, :custom_values, :trackers |
|
26 | 26 | |
|
27 | 27 | PRJ_ID = 3 |
|
28 | 28 | NUM_REV = 11 |
|
29 | 29 | |
|
30 | 30 | def setup |
|
31 | 31 | Setting.default_language = 'en' |
|
32 | 32 | User.current = nil |
|
33 | 33 | |
|
34 | 34 | @project = Project.find(PRJ_ID) |
|
35 | 35 | @repository = Repository::Subversion.create(:project => @project, |
|
36 | 36 | :url => self.class.subversion_repository_url) |
|
37 | 37 | assert @repository |
|
38 | 38 | end |
|
39 | 39 | |
|
40 | 40 | if repository_configured?('subversion') |
|
41 | 41 | def test_new |
|
42 | 42 | @request.session[:user_id] = 1 |
|
43 | 43 | @project.repository.destroy |
|
44 | 44 | get :new, :project_id => 'subproject1', :repository_scm => 'Subversion' |
|
45 | 45 | assert_response :success |
|
46 | 46 | assert_template 'new' |
|
47 | 47 | assert_kind_of Repository::Subversion, assigns(:repository) |
|
48 | 48 | assert assigns(:repository).new_record? |
|
49 | 49 | end |
|
50 | 50 | |
|
51 | 51 | def test_show |
|
52 | 52 | assert_equal 0, @repository.changesets.count |
|
53 | 53 | @repository.fetch_changesets |
|
54 | 54 | @project.reload |
|
55 | 55 | assert_equal NUM_REV, @repository.changesets.count |
|
56 | 56 | get :show, :id => PRJ_ID |
|
57 | 57 | assert_response :success |
|
58 | 58 | assert_template 'show' |
|
59 | 59 | assert_not_nil assigns(:entries) |
|
60 | 60 | assert_not_nil assigns(:changesets) |
|
61 | 61 | |
|
62 | 62 | entry = assigns(:entries).detect {|e| e.name == 'subversion_test'} |
|
63 | 63 | assert_not_nil entry |
|
64 | 64 | assert_equal 'dir', entry.kind |
|
65 | 65 | assert_select 'tr.dir a[href=/projects/subproject1/repository/show/subversion_test]' |
|
66 | 66 | |
|
67 | 67 | assert_tag 'input', :attributes => {:name => 'rev'} |
|
68 | 68 | assert_tag 'a', :content => 'Statistics' |
|
69 | 69 | assert_tag 'a', :content => 'Atom' |
|
70 | 70 | assert_tag :tag => 'a', |
|
71 | 71 | :attributes => {:href => '/projects/subproject1/repository'}, |
|
72 | 72 | :content => 'root' |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | def test_show_non_default |
|
76 | 76 | Repository::Subversion.create(:project => @project, |
|
77 | 77 | :url => self.class.subversion_repository_url, |
|
78 | 78 | :is_default => false, :identifier => 'svn') |
|
79 | 79 | |
|
80 | 80 | get :show, :id => PRJ_ID, :repository_id => 'svn' |
|
81 | 81 | assert_response :success |
|
82 | 82 | assert_template 'show' |
|
83 | 83 | assert_select 'tr.dir a[href=/projects/subproject1/repository/svn/show/subversion_test]' |
|
84 | 84 | # Repository menu should link to the main repo |
|
85 | 85 | assert_select '#main-menu a[href=/projects/subproject1/repository]' |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def test_browse_directory |
|
89 | 89 | assert_equal 0, @repository.changesets.count |
|
90 | 90 | @repository.fetch_changesets |
|
91 | 91 | @project.reload |
|
92 | 92 | assert_equal NUM_REV, @repository.changesets.count |
|
93 | 93 | get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param] |
|
94 | 94 | assert_response :success |
|
95 | 95 | assert_template 'show' |
|
96 | 96 | assert_not_nil assigns(:entries) |
|
97 | 97 | assert_equal [ |
|
98 | 98 | '[folder_with_brackets]', 'folder', '.project', |
|
99 | 99 | 'helloworld.c', 'textfile.txt' |
|
100 | 100 | ], |
|
101 | 101 | assigns(:entries).collect(&:name) |
|
102 | 102 | entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'} |
|
103 | 103 | assert_equal 'file', entry.kind |
|
104 | 104 | assert_equal 'subversion_test/helloworld.c', entry.path |
|
105 | 105 | assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ } |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def test_browse_at_given_revision |
|
109 | 109 | assert_equal 0, @repository.changesets.count |
|
110 | 110 | @repository.fetch_changesets |
|
111 | 111 | @project.reload |
|
112 | 112 | assert_equal NUM_REV, @repository.changesets.count |
|
113 | 113 | get :show, :id => PRJ_ID, :path => repository_path_hash(['subversion_test'])[:param], |
|
114 | 114 | :rev => 4 |
|
115 | 115 | assert_response :success |
|
116 | 116 | assert_template 'show' |
|
117 | 117 | assert_not_nil assigns(:entries) |
|
118 | 118 | assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'], |
|
119 | 119 | assigns(:entries).collect(&:name) |
|
120 | 120 | end |
|
121 | 121 | |
|
122 | 122 | def test_file_changes |
|
123 | 123 | assert_equal 0, @repository.changesets.count |
|
124 | 124 | @repository.fetch_changesets |
|
125 | 125 | @project.reload |
|
126 | 126 | assert_equal NUM_REV, @repository.changesets.count |
|
127 | 127 | get :changes, :id => PRJ_ID, |
|
128 | 128 | :path => repository_path_hash(['subversion_test', 'folder', 'helloworld.rb'])[:param] |
|
129 | 129 | assert_response :success |
|
130 | 130 | assert_template 'changes' |
|
131 | 131 | |
|
132 | 132 | changesets = assigns(:changesets) |
|
133 | 133 | assert_not_nil changesets |
|
134 | 134 | assert_equal %w(6 3 2), changesets.collect(&:revision) |
|
135 | 135 | |
|
136 | 136 | # svn properties displayed with svn >= 1.5 only |
|
137 | 137 | if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0]) |
|
138 | 138 | assert_not_nil assigns(:properties) |
|
139 | 139 | assert_equal 'native', assigns(:properties)['svn:eol-style'] |
|
140 | 140 | assert_tag :ul, |
|
141 | 141 | :child => { :tag => 'li', |
|
142 | 142 | :child => { :tag => 'b', :content => 'svn:eol-style' }, |
|
143 | 143 | :child => { :tag => 'span', :content => 'native' } } |
|
144 | 144 | end |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | def test_directory_changes |
|
148 | 148 | assert_equal 0, @repository.changesets.count |
|
149 | 149 | @repository.fetch_changesets |
|
150 | 150 | @project.reload |
|
151 | 151 | assert_equal NUM_REV, @repository.changesets.count |
|
152 | 152 | get :changes, :id => PRJ_ID, |
|
153 | 153 | :path => repository_path_hash(['subversion_test', 'folder'])[:param] |
|
154 | 154 | assert_response :success |
|
155 | 155 | assert_template 'changes' |
|
156 | 156 | |
|
157 | 157 | changesets = assigns(:changesets) |
|
158 | 158 | assert_not_nil changesets |
|
159 | 159 | assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision) |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def test_entry |
|
163 | 163 | assert_equal 0, @repository.changesets.count |
|
164 | 164 | @repository.fetch_changesets |
|
165 | 165 | @project.reload |
|
166 | 166 | assert_equal NUM_REV, @repository.changesets.count |
|
167 | 167 | get :entry, :id => PRJ_ID, |
|
168 | 168 | :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] |
|
169 | 169 | assert_response :success |
|
170 | 170 | assert_template 'entry' |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def test_entry_should_send_if_too_big |
|
174 | 174 | assert_equal 0, @repository.changesets.count |
|
175 | 175 | @repository.fetch_changesets |
|
176 | 176 | @project.reload |
|
177 | 177 | assert_equal NUM_REV, @repository.changesets.count |
|
178 | 178 | # no files in the test repo is larger than 1KB... |
|
179 | 179 | with_settings :file_max_size_displayed => 0 do |
|
180 | 180 | get :entry, :id => PRJ_ID, |
|
181 | 181 | :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] |
|
182 | 182 | assert_response :success |
|
183 | 183 | assert_equal 'attachment; filename="helloworld.c"', |
|
184 | 184 | @response.headers['Content-Disposition'] |
|
185 | 185 | end |
|
186 | 186 | end |
|
187 | 187 | |
|
188 | 188 | def test_entry_should_send_images_inline |
|
189 | 189 | get :entry, :id => PRJ_ID, |
|
190 | 190 | :path => repository_path_hash(['subversion_test', 'folder', 'subfolder', 'rubylogo.gif'])[:param] |
|
191 | 191 | assert_response :success |
|
192 | 192 | assert_equal 'inline; filename="rubylogo.gif"', response.headers['Content-Disposition'] |
|
193 | 193 | end |
|
194 | 194 | |
|
195 | 195 | def test_entry_at_given_revision |
|
196 | 196 | assert_equal 0, @repository.changesets.count |
|
197 | 197 | @repository.fetch_changesets |
|
198 | 198 | @project.reload |
|
199 | 199 | assert_equal NUM_REV, @repository.changesets.count |
|
200 | 200 | get :entry, :id => PRJ_ID, |
|
201 | 201 | :path => repository_path_hash(['subversion_test', 'helloworld.rb'])[:param], |
|
202 | 202 | :rev => 2 |
|
203 | 203 | assert_response :success |
|
204 | 204 | assert_template 'entry' |
|
205 | 205 | # this line was removed in r3 and file was moved in r6 |
|
206 | 206 | assert_tag :tag => 'td', :attributes => { :class => /line-code/}, |
|
207 | 207 | :content => /Here's the code/ |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | def test_entry_not_found |
|
211 | 211 | assert_equal 0, @repository.changesets.count |
|
212 | 212 | @repository.fetch_changesets |
|
213 | 213 | @project.reload |
|
214 | 214 | assert_equal NUM_REV, @repository.changesets.count |
|
215 | 215 | get :entry, :id => PRJ_ID, |
|
216 | 216 | :path => repository_path_hash(['subversion_test', 'zzz.c'])[:param] |
|
217 | 217 | assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, |
|
218 | 218 | :content => /The entry or revision was not found in the repository/ |
|
219 | 219 | end |
|
220 | 220 | |
|
221 | 221 | def test_entry_download |
|
222 | 222 | assert_equal 0, @repository.changesets.count |
|
223 | 223 | @repository.fetch_changesets |
|
224 | 224 | @project.reload |
|
225 | 225 | assert_equal NUM_REV, @repository.changesets.count |
|
226 | 226 | get :raw, :id => PRJ_ID, |
|
227 | 227 | :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] |
|
228 | 228 | assert_response :success |
|
229 | 229 | assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition'] |
|
230 | 230 | end |
|
231 | 231 | |
|
232 | 232 | def test_directory_entry |
|
233 | 233 | assert_equal 0, @repository.changesets.count |
|
234 | 234 | @repository.fetch_changesets |
|
235 | 235 | @project.reload |
|
236 | 236 | assert_equal NUM_REV, @repository.changesets.count |
|
237 | 237 | get :entry, :id => PRJ_ID, |
|
238 | 238 | :path => repository_path_hash(['subversion_test', 'folder'])[:param] |
|
239 | 239 | assert_response :success |
|
240 | 240 | assert_template 'show' |
|
241 | 241 | assert_not_nil assigns(:entry) |
|
242 | 242 | assert_equal 'folder', assigns(:entry).name |
|
243 | 243 | end |
|
244 | 244 | |
|
245 | 245 | # TODO: this test needs fixtures. |
|
246 | 246 | def test_revision |
|
247 | 247 | get :revision, :id => 1, :rev => 2 |
|
248 | 248 | assert_response :success |
|
249 | 249 | assert_template 'revision' |
|
250 | 250 | |
|
251 | 251 | assert_select 'ul' do |
|
252 | 252 | assert_select 'li' do |
|
253 | 253 | # link to the entry at rev 2 |
|
254 | 254 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo', :text => 'repo' |
|
255 | 255 | # link to partial diff |
|
256 | 256 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' |
|
257 | 257 | end |
|
258 | 258 | end |
|
259 | 259 | end |
|
260 | 260 | |
|
261 | 261 | def test_invalid_revision |
|
262 | 262 | assert_equal 0, @repository.changesets.count |
|
263 | 263 | @repository.fetch_changesets |
|
264 | 264 | @project.reload |
|
265 | 265 | assert_equal NUM_REV, @repository.changesets.count |
|
266 | 266 | get :revision, :id => PRJ_ID, :rev => 'something_weird' |
|
267 | 267 | assert_response 404 |
|
268 | 268 | assert_error_tag :content => /was not found/ |
|
269 | 269 | end |
|
270 | 270 | |
|
271 | 271 | def test_invalid_revision_diff |
|
272 | 272 | get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird' |
|
273 | 273 | assert_response 404 |
|
274 | 274 | assert_error_tag :content => /was not found/ |
|
275 | 275 | end |
|
276 | 276 | |
|
277 | 277 | def test_empty_revision |
|
278 | 278 | assert_equal 0, @repository.changesets.count |
|
279 | 279 | @repository.fetch_changesets |
|
280 | 280 | @project.reload |
|
281 | 281 | assert_equal NUM_REV, @repository.changesets.count |
|
282 | 282 | ['', ' ', nil].each do |r| |
|
283 | 283 | get :revision, :id => PRJ_ID, :rev => r |
|
284 | 284 | assert_response 404 |
|
285 | 285 | assert_error_tag :content => /was not found/ |
|
286 | 286 | end |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | # TODO: this test needs fixtures. |
|
290 | 290 | def test_revision_with_repository_pointing_to_a_subdirectory |
|
291 | 291 | r = Project.find(1).repository |
|
292 | 292 | # Changes repository url to a subdirectory |
|
293 | 293 | r.update_attribute :url, (r.url + '/test/some') |
|
294 | 294 | |
|
295 | 295 | get :revision, :id => 1, :rev => 2 |
|
296 | 296 | assert_response :success |
|
297 | 297 | assert_template 'revision' |
|
298 | 298 | |
|
299 | 299 | assert_select 'ul' do |
|
300 | 300 | assert_select 'li' do |
|
301 | 301 | # link to the entry at rev 2 |
|
302 | 302 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo', :text => 'repo' |
|
303 | 303 | # link to partial diff |
|
304 | 304 | assert_select 'a[href=?]', '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' |
|
305 | 305 | end |
|
306 | 306 | end |
|
307 | 307 | end |
|
308 | 308 | |
|
309 | 309 | def test_revision_diff |
|
310 | 310 | assert_equal 0, @repository.changesets.count |
|
311 | 311 | @repository.fetch_changesets |
|
312 | 312 | @project.reload |
|
313 | 313 | assert_equal NUM_REV, @repository.changesets.count |
|
314 | 314 | ['inline', 'sbs'].each do |dt| |
|
315 | 315 | get :diff, :id => PRJ_ID, :rev => 3, :type => dt |
|
316 | 316 | assert_response :success |
|
317 | 317 | assert_template 'diff' |
|
318 | 318 | assert_select 'h2', :text => /Revision 3/ |
|
319 | 319 | assert_select 'th.filename', :text => 'subversion_test/textfile.txt' |
|
320 | 320 | end |
|
321 | 321 | end |
|
322 | 322 | |
|
323 | 323 | def test_revision_diff_raw_format |
|
324 | 324 | assert_equal 0, @repository.changesets.count |
|
325 | 325 | @repository.fetch_changesets |
|
326 | 326 | @project.reload |
|
327 | 327 | assert_equal NUM_REV, @repository.changesets.count |
|
328 | 328 | |
|
329 |
get :diff, :id => PRJ_ID, :rev => |
|
|
329 | get :diff, :id => PRJ_ID, :rev => 5, :format => 'diff' | |
|
330 | 330 | assert_response :success |
|
331 | 331 | assert_equal 'text/x-patch', @response.content_type |
|
332 |
assert_equal 'Index: subversion_test/ |
|
|
332 | assert_equal 'Index: subversion_test/folder/greeter.rb', @response.body.split(/\r?\n/).first | |
|
333 | 333 | end |
|
334 | 334 | |
|
335 | 335 | def test_directory_diff |
|
336 | 336 | assert_equal 0, @repository.changesets.count |
|
337 | 337 | @repository.fetch_changesets |
|
338 | 338 | @project.reload |
|
339 | 339 | assert_equal NUM_REV, @repository.changesets.count |
|
340 | 340 | ['inline', 'sbs'].each do |dt| |
|
341 | 341 | get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2, |
|
342 | 342 | :path => repository_path_hash(['subversion_test', 'folder'])[:param], |
|
343 | 343 | :type => dt |
|
344 | 344 | assert_response :success |
|
345 | 345 | assert_template 'diff' |
|
346 | 346 | |
|
347 | 347 | diff = assigns(:diff) |
|
348 | 348 | assert_not_nil diff |
|
349 | 349 | # 2 files modified |
|
350 | 350 | assert_equal 2, Redmine::UnifiedDiff.new(diff).size |
|
351 | 351 | assert_tag :tag => 'h2', :content => /2:6/ |
|
352 | 352 | end |
|
353 | 353 | end |
|
354 | 354 | |
|
355 | 355 | def test_annotate |
|
356 | 356 | assert_equal 0, @repository.changesets.count |
|
357 | 357 | @repository.fetch_changesets |
|
358 | 358 | @project.reload |
|
359 | 359 | assert_equal NUM_REV, @repository.changesets.count |
|
360 | 360 | get :annotate, :id => PRJ_ID, |
|
361 | 361 | :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] |
|
362 | 362 | assert_response :success |
|
363 | 363 | assert_template 'annotate' |
|
364 | 364 | |
|
365 | 365 | assert_select 'tr' do |
|
366 | 366 | assert_select 'th.line-num', :text => '1' |
|
367 | 367 | assert_select 'td.revision', :text => '4' |
|
368 | 368 | assert_select 'td.author', :text => 'jp' |
|
369 | 369 | assert_select 'td', :text => /stdio.h/ |
|
370 | 370 | end |
|
371 | 371 | # Same revision |
|
372 | 372 | assert_select 'tr' do |
|
373 | 373 | assert_select 'th.line-num', :text => '2' |
|
374 | 374 | assert_select 'td.revision', :text => '' |
|
375 | 375 | assert_select 'td.author', :text => '' |
|
376 | 376 | end |
|
377 | 377 | end |
|
378 | 378 | |
|
379 | 379 | def test_annotate_at_given_revision |
|
380 | 380 | assert_equal 0, @repository.changesets.count |
|
381 | 381 | @repository.fetch_changesets |
|
382 | 382 | @project.reload |
|
383 | 383 | assert_equal NUM_REV, @repository.changesets.count |
|
384 | 384 | get :annotate, :id => PRJ_ID, :rev => 8, |
|
385 | 385 | :path => repository_path_hash(['subversion_test', 'helloworld.c'])[:param] |
|
386 | 386 | assert_response :success |
|
387 | 387 | assert_template 'annotate' |
|
388 | 388 | assert_tag :tag => 'h2', :content => /@ 8/ |
|
389 | 389 | end |
|
390 | 390 | |
|
391 | 391 | def test_destroy_valid_repository |
|
392 | 392 | @request.session[:user_id] = 1 # admin |
|
393 | 393 | assert_equal 0, @repository.changesets.count |
|
394 | 394 | @repository.fetch_changesets |
|
395 | 395 | assert_equal NUM_REV, @repository.changesets.count |
|
396 | 396 | |
|
397 | 397 | assert_difference 'Repository.count', -1 do |
|
398 | 398 | delete :destroy, :id => @repository.id |
|
399 | 399 | end |
|
400 | 400 | assert_response 302 |
|
401 | 401 | @project.reload |
|
402 | 402 | assert_nil @project.repository |
|
403 | 403 | end |
|
404 | 404 | |
|
405 | 405 | def test_destroy_invalid_repository |
|
406 | 406 | @request.session[:user_id] = 1 # admin |
|
407 | 407 | @project.repository.destroy |
|
408 | 408 | @repository = Repository::Subversion.create!( |
|
409 | 409 | :project => @project, |
|
410 | 410 | :url => "file:///invalid") |
|
411 | 411 | @repository.fetch_changesets |
|
412 | 412 | assert_equal 0, @repository.changesets.count |
|
413 | 413 | |
|
414 | 414 | assert_difference 'Repository.count', -1 do |
|
415 | 415 | delete :destroy, :id => @repository.id |
|
416 | 416 | end |
|
417 | 417 | assert_response 302 |
|
418 | 418 | @project.reload |
|
419 | 419 | assert_nil @project.repository |
|
420 | 420 | end |
|
421 | 421 | else |
|
422 | 422 | puts "Subversion test repository NOT FOUND. Skipping functional tests !!!" |
|
423 | 423 | def test_fake; assert true end |
|
424 | 424 | end |
|
425 | 425 | end |
General Comments 0
You need to be logged in to leave comments.
Login now