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