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