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