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