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