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