##// END OF EJS Templates
Removed duplicated test....
Jean-Philippe Lang -
r8546:141630e771d2
parent child
Show More
@@ -1,392 +1,383
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 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 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
63 assert_not_nil entry
64 assert_equal 'dir', entry.kind
65
62 66 assert_tag 'input', :attributes => {:name => 'rev'}
63 67 assert_tag 'a', :content => 'Statistics'
64 68 assert_tag 'a', :content => 'Atom'
65 69 end
66 70
67 def test_browse_root
68 assert_equal 0, @repository.changesets.count
69 @repository.fetch_changesets
70 @project.reload
71 assert_equal NUM_REV, @repository.changesets.count
72 get :show, :id => PRJ_ID
73 assert_response :success
74 assert_template 'show'
75 assert_not_nil assigns(:entries)
76 entry = assigns(:entries).detect {|e| e.name == 'subversion_test'}
77 assert_equal 'dir', entry.kind
78 end
79
80 71 def test_browse_directory
81 72 assert_equal 0, @repository.changesets.count
82 73 @repository.fetch_changesets
83 74 @project.reload
84 75 assert_equal NUM_REV, @repository.changesets.count
85 76 get :show, :id => PRJ_ID, :path => ['subversion_test']
86 77 assert_response :success
87 78 assert_template 'show'
88 79 assert_not_nil assigns(:entries)
89 80 assert_equal [
90 81 '[folder_with_brackets]', 'folder', '.project',
91 82 'helloworld.c', 'textfile.txt'
92 83 ],
93 84 assigns(:entries).collect(&:name)
94 85 entry = assigns(:entries).detect {|e| e.name == 'helloworld.c'}
95 86 assert_equal 'file', entry.kind
96 87 assert_equal 'subversion_test/helloworld.c', entry.path
97 88 assert_tag :a, :content => 'helloworld.c', :attributes => { :class => /text\-x\-c/ }
98 89 end
99 90
100 91 def test_browse_at_given_revision
101 92 assert_equal 0, @repository.changesets.count
102 93 @repository.fetch_changesets
103 94 @project.reload
104 95 assert_equal NUM_REV, @repository.changesets.count
105 96 get :show, :id => PRJ_ID, :path => ['subversion_test'], :rev => 4
106 97 assert_response :success
107 98 assert_template 'show'
108 99 assert_not_nil assigns(:entries)
109 100 assert_equal ['folder', '.project', 'helloworld.c', 'helloworld.rb', 'textfile.txt'],
110 101 assigns(:entries).collect(&:name)
111 102 end
112 103
113 104 def test_file_changes
114 105 assert_equal 0, @repository.changesets.count
115 106 @repository.fetch_changesets
116 107 @project.reload
117 108 assert_equal NUM_REV, @repository.changesets.count
118 109 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder', 'helloworld.rb' ]
119 110 assert_response :success
120 111 assert_template 'changes'
121 112
122 113 changesets = assigns(:changesets)
123 114 assert_not_nil changesets
124 115 assert_equal %w(6 3 2), changesets.collect(&:revision)
125 116
126 117 # svn properties displayed with svn >= 1.5 only
127 118 if Redmine::Scm::Adapters::SubversionAdapter.client_version_above?([1, 5, 0])
128 119 assert_not_nil assigns(:properties)
129 120 assert_equal 'native', assigns(:properties)['svn:eol-style']
130 121 assert_tag :ul,
131 122 :child => { :tag => 'li',
132 123 :child => { :tag => 'b', :content => 'svn:eol-style' },
133 124 :child => { :tag => 'span', :content => 'native' } }
134 125 end
135 126 end
136 127
137 128 def test_directory_changes
138 129 assert_equal 0, @repository.changesets.count
139 130 @repository.fetch_changesets
140 131 @project.reload
141 132 assert_equal NUM_REV, @repository.changesets.count
142 133 get :changes, :id => PRJ_ID, :path => ['subversion_test', 'folder' ]
143 134 assert_response :success
144 135 assert_template 'changes'
145 136
146 137 changesets = assigns(:changesets)
147 138 assert_not_nil changesets
148 139 assert_equal %w(10 9 7 6 5 2), changesets.collect(&:revision)
149 140 end
150 141
151 142 def test_entry
152 143 assert_equal 0, @repository.changesets.count
153 144 @repository.fetch_changesets
154 145 @project.reload
155 146 assert_equal NUM_REV, @repository.changesets.count
156 147 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
157 148 assert_response :success
158 149 assert_template 'entry'
159 150 end
160 151
161 152 def test_entry_should_send_if_too_big
162 153 assert_equal 0, @repository.changesets.count
163 154 @repository.fetch_changesets
164 155 @project.reload
165 156 assert_equal NUM_REV, @repository.changesets.count
166 157 # no files in the test repo is larger than 1KB...
167 158 with_settings :file_max_size_displayed => 0 do
168 159 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
169 160 assert_response :success
170 161 assert_template ''
171 162 assert_equal 'attachment; filename="helloworld.c"',
172 163 @response.headers['Content-Disposition']
173 164 end
174 165 end
175 166
176 167 def test_entry_at_given_revision
177 168 assert_equal 0, @repository.changesets.count
178 169 @repository.fetch_changesets
179 170 @project.reload
180 171 assert_equal NUM_REV, @repository.changesets.count
181 172 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.rb'], :rev => 2
182 173 assert_response :success
183 174 assert_template 'entry'
184 175 # this line was removed in r3 and file was moved in r6
185 176 assert_tag :tag => 'td', :attributes => { :class => /line-code/},
186 177 :content => /Here's the code/
187 178 end
188 179
189 180 def test_entry_not_found
190 181 assert_equal 0, @repository.changesets.count
191 182 @repository.fetch_changesets
192 183 @project.reload
193 184 assert_equal NUM_REV, @repository.changesets.count
194 185 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'zzz.c']
195 186 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
196 187 :content => /The entry or revision was not found in the repository/
197 188 end
198 189
199 190 def test_entry_download
200 191 assert_equal 0, @repository.changesets.count
201 192 @repository.fetch_changesets
202 193 @project.reload
203 194 assert_equal NUM_REV, @repository.changesets.count
204 195 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c'], :format => 'raw'
205 196 assert_response :success
206 197 assert_template ''
207 198 assert_equal 'attachment; filename="helloworld.c"', @response.headers['Content-Disposition']
208 199 end
209 200
210 201 def test_directory_entry
211 202 assert_equal 0, @repository.changesets.count
212 203 @repository.fetch_changesets
213 204 @project.reload
214 205 assert_equal NUM_REV, @repository.changesets.count
215 206 get :entry, :id => PRJ_ID, :path => ['subversion_test', 'folder']
216 207 assert_response :success
217 208 assert_template 'show'
218 209 assert_not_nil assigns(:entry)
219 210 assert_equal 'folder', assigns(:entry).name
220 211 end
221 212
222 213 # TODO: this test needs fixtures.
223 214 def test_revision
224 215 get :revision, :id => 1, :rev => 2
225 216 assert_response :success
226 217 assert_template 'revision'
227 218 assert_tag :tag => 'ul',
228 219 :child => { :tag => 'li',
229 220 # link to the entry at rev 2
230 221 :child => { :tag => 'a',
231 222 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/test/some/path/in/the/repo'},
232 223 :content => 'repo',
233 224 # link to partial diff
234 225 :sibling => { :tag => 'a',
235 226 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/test/some/path/in/the/repo' }
236 227 }
237 228 }
238 229 }
239 230 end
240 231
241 232 def test_invalid_revision
242 233 assert_equal 0, @repository.changesets.count
243 234 @repository.fetch_changesets
244 235 @project.reload
245 236 assert_equal NUM_REV, @repository.changesets.count
246 237 get :revision, :id => PRJ_ID, :rev => 'something_weird'
247 238 assert_response 404
248 239 assert_error_tag :content => /was not found/
249 240 end
250 241
251 242 def test_invalid_revision_diff
252 243 get :diff, :id => PRJ_ID, :rev => '1', :rev_to => 'something_weird'
253 244 assert_response 404
254 245 assert_error_tag :content => /was not found/
255 246 end
256 247
257 248 def test_empty_revision
258 249 assert_equal 0, @repository.changesets.count
259 250 @repository.fetch_changesets
260 251 @project.reload
261 252 assert_equal NUM_REV, @repository.changesets.count
262 253 ['', ' ', nil].each do |r|
263 254 get :revision, :id => PRJ_ID, :rev => r
264 255 assert_response 404
265 256 assert_error_tag :content => /was not found/
266 257 end
267 258 end
268 259
269 260 # TODO: this test needs fixtures.
270 261 def test_revision_with_repository_pointing_to_a_subdirectory
271 262 r = Project.find(1).repository
272 263 # Changes repository url to a subdirectory
273 264 r.update_attribute :url, (r.url + '/test/some')
274 265
275 266 get :revision, :id => 1, :rev => 2
276 267 assert_response :success
277 268 assert_template 'revision'
278 269 assert_tag :tag => 'ul',
279 270 :child => { :tag => 'li',
280 271 # link to the entry at rev 2
281 272 :child => { :tag => 'a',
282 273 :attributes => {:href => '/projects/ecookbook/repository/revisions/2/entry/path/in/the/repo'},
283 274 :content => 'repo',
284 275 # link to partial diff
285 276 :sibling => { :tag => 'a',
286 277 :attributes => { :href => '/projects/ecookbook/repository/revisions/2/diff/path/in/the/repo' }
287 278 }
288 279 }
289 280 }
290 281 end
291 282
292 283 def test_revision_diff
293 284 assert_equal 0, @repository.changesets.count
294 285 @repository.fetch_changesets
295 286 @project.reload
296 287 assert_equal NUM_REV, @repository.changesets.count
297 288 ['inline', 'sbs'].each do |dt|
298 289 get :diff, :id => PRJ_ID, :rev => 3, :type => dt
299 290 assert_response :success
300 291 assert_template 'diff'
301 292 assert_tag :tag => 'h2',
302 293 :content => / 3/
303 294 end
304 295 end
305 296
306 297 def test_revision_diff_raw_format
307 298 assert_equal 0, @repository.changesets.count
308 299 @repository.fetch_changesets
309 300 @project.reload
310 301 assert_equal NUM_REV, @repository.changesets.count
311 302
312 303 get :diff, :id => PRJ_ID, :rev => 3, :format => 'diff'
313 304 assert_response :success
314 305 assert_equal 'text/x-patch', @response.content_type
315 306 assert_equal 'Index: subversion_test/textfile.txt', @response.body.split(/\r?\n/).first
316 307 end
317 308
318 309 def test_directory_diff
319 310 assert_equal 0, @repository.changesets.count
320 311 @repository.fetch_changesets
321 312 @project.reload
322 313 assert_equal NUM_REV, @repository.changesets.count
323 314 ['inline', 'sbs'].each do |dt|
324 315 get :diff, :id => PRJ_ID, :rev => 6, :rev_to => 2,
325 316 :path => ['subversion_test', 'folder'], :type => dt
326 317 assert_response :success
327 318 assert_template 'diff'
328 319
329 320 diff = assigns(:diff)
330 321 assert_not_nil diff
331 322 # 2 files modified
332 323 assert_equal 2, Redmine::UnifiedDiff.new(diff).size
333 324 assert_tag :tag => 'h2', :content => /2:6/
334 325 end
335 326 end
336 327
337 328 def test_annotate
338 329 assert_equal 0, @repository.changesets.count
339 330 @repository.fetch_changesets
340 331 @project.reload
341 332 assert_equal NUM_REV, @repository.changesets.count
342 333 get :annotate, :id => PRJ_ID, :path => ['subversion_test', 'helloworld.c']
343 334 assert_response :success
344 335 assert_template 'annotate'
345 336 end
346 337
347 338 def test_annotate_at_given_revision
348 339 assert_equal 0, @repository.changesets.count
349 340 @repository.fetch_changesets
350 341 @project.reload
351 342 assert_equal NUM_REV, @repository.changesets.count
352 343 get :annotate, :id => PRJ_ID, :rev => 8, :path => ['subversion_test', 'helloworld.c']
353 344 assert_response :success
354 345 assert_template 'annotate'
355 346 assert_tag :tag => 'h2', :content => /@ 8/
356 347 end
357 348
358 349 def test_destroy_valid_repository
359 350 @request.session[:user_id] = 1 # admin
360 351 assert_equal 0, @repository.changesets.count
361 352 @repository.fetch_changesets
362 353 assert_equal NUM_REV, @repository.changesets.count
363 354
364 355 assert_difference 'Repository.count', -1 do
365 356 delete :destroy, :id => @repository.id
366 357 end
367 358 assert_response 302
368 359 @project.reload
369 360 assert_nil @project.repository
370 361 end
371 362
372 363 def test_destroy_invalid_repository
373 364 @request.session[:user_id] = 1 # admin
374 365 @project.repository.destroy
375 366 @repository = Repository::Subversion.create!(
376 367 :project => @project,
377 368 :url => "file:///invalid")
378 369 @repository.fetch_changesets
379 370 assert_equal 0, @repository.changesets.count
380 371
381 372 assert_difference 'Repository.count', -1 do
382 373 delete :destroy, :id => @repository.id
383 374 end
384 375 assert_response 302
385 376 @project.reload
386 377 assert_nil @project.repository
387 378 end
388 379 else
389 380 puts "Subversion test repository NOT FOUND. Skipping functional tests !!!"
390 381 def test_fake; assert true end
391 382 end
392 383 end
General Comments 0
You need to be logged in to leave comments. Login now