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