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