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