##// END OF EJS Templates
scm: git: add functional test of destroying valid repository (#6713, #4725)....
Toshi MARUYAMA -
r6129:c077f0cde1d4
parent child
Show More
@@ -1,396 +1,408
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 RepositoriesGitControllerTest < ActionController::TestCase
25 25 fixtures :projects, :users, :roles, :members, :member_roles,
26 26 :repositories, :enabled_modules
27 27
28 28 REPOSITORY_PATH = Rails.root.join('tmp/test/git_repository').to_s
29 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 30 PRJ_ID = 3
31 31 CHAR_1_HEX = "\xc3\x9c"
32 32
33 33 ## Git, Mercurial and CVS path encodings are binary.
34 34 ## Subversion supports URL encoding for path.
35 35 ## Redmine Mercurial adapter and extension use URL encoding.
36 36 ## Git accepts only binary path in command line parameter.
37 37 ## So, there is no way to use binary command line parameter in JRuby.
38 38 JRUBY_SKIP = (RUBY_PLATFORM == 'java')
39 39 JRUBY_SKIP_STR = "TODO: This test fails in JRuby"
40 40
41 41 def setup
42 42 @ruby19_non_utf8_pass =
43 43 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
44 44
45 45 @controller = RepositoriesController.new
46 46 @request = ActionController::TestRequest.new
47 47 @response = ActionController::TestResponse.new
48 48 User.current = nil
49 49 @project = Project.find(PRJ_ID)
50 50 @repository = Repository::Git.create(
51 51 :project => @project,
52 52 :url => REPOSITORY_PATH,
53 53 :path_encoding => 'ISO-8859-1'
54 54 )
55 55 assert @repository
56 56 @char_1 = CHAR_1_HEX.dup
57 57 if @char_1.respond_to?(:force_encoding)
58 58 @char_1.force_encoding('UTF-8')
59 59 end
60 60
61 61 Setting.default_language = 'en'
62 62 end
63 63
64 64 if File.directory?(REPOSITORY_PATH)
65 65 def test_browse_root
66 66 @repository.fetch_changesets
67 67 @repository.reload
68 68 get :show, :id => PRJ_ID
69 69 assert_response :success
70 70 assert_template 'show'
71 71 assert_not_nil assigns(:entries)
72 72 assert_equal 9, assigns(:entries).size
73 73 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
74 74 assert assigns(:entries).detect {|e| e.name == 'this_is_a_really_long_and_verbose_directory_name' && e.kind == 'dir'}
75 75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 76 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 77 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
78 78 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
79 79 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
80 80 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
81 81 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
82 82 assert_not_nil assigns(:changesets)
83 83 assert assigns(:changesets).size > 0
84 84 end
85 85
86 86 def test_browse_branch
87 87 @repository.fetch_changesets
88 88 @repository.reload
89 89 get :show, :id => PRJ_ID, :rev => 'test_branch'
90 90 assert_response :success
91 91 assert_template 'show'
92 92 assert_not_nil assigns(:entries)
93 93 assert_equal 4, assigns(:entries).size
94 94 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
95 95 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
96 96 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
97 97 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
98 98 assert_not_nil assigns(:changesets)
99 99 assert assigns(:changesets).size > 0
100 100 end
101 101
102 102 def test_browse_tag
103 103 @repository.fetch_changesets
104 104 @repository.reload
105 105 [
106 106 "tag00.lightweight",
107 107 "tag01.annotated",
108 108 ].each do |t1|
109 109 get :show, :id => PRJ_ID, :rev => t1
110 110 assert_response :success
111 111 assert_template 'show'
112 112 assert_not_nil assigns(:entries)
113 113 assert assigns(:entries).size > 0
114 114 assert_not_nil assigns(:changesets)
115 115 assert assigns(:changesets).size > 0
116 116 end
117 117 end
118 118
119 119 def test_browse_directory
120 120 @repository.fetch_changesets
121 121 @repository.reload
122 122 get :show, :id => PRJ_ID, :path => ['images']
123 123 assert_response :success
124 124 assert_template 'show'
125 125 assert_not_nil assigns(:entries)
126 126 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
127 127 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
128 128 assert_not_nil entry
129 129 assert_equal 'file', entry.kind
130 130 assert_equal 'images/edit.png', entry.path
131 131 assert_not_nil assigns(:changesets)
132 132 assert assigns(:changesets).size > 0
133 133 end
134 134
135 135 def test_browse_at_given_revision
136 136 @repository.fetch_changesets
137 137 @repository.reload
138 138 get :show, :id => PRJ_ID, :path => ['images'],
139 139 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
140 140 assert_response :success
141 141 assert_template 'show'
142 142 assert_not_nil assigns(:entries)
143 143 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
144 144 assert_not_nil assigns(:changesets)
145 145 assert assigns(:changesets).size > 0
146 146 end
147 147
148 148 def test_changes
149 149 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
150 150 assert_response :success
151 151 assert_template 'changes'
152 152 assert_tag :tag => 'h2', :content => 'edit.png'
153 153 end
154 154
155 155 def test_entry_show
156 156 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
157 157 assert_response :success
158 158 assert_template 'entry'
159 159 # Line 19
160 160 assert_tag :tag => 'th',
161 161 :content => '11',
162 162 :attributes => { :class => 'line-num' },
163 163 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
164 164 end
165 165
166 166 def test_entry_show_latin_1
167 167 if @ruby19_non_utf8_pass
168 168 puts_ruby19_non_utf8_pass()
169 169 elsif JRUBY_SKIP
170 170 puts JRUBY_SKIP_STR
171 171 else
172 172 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
173 173 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
174 174 get :entry, :id => PRJ_ID,
175 175 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
176 176 assert_response :success
177 177 assert_template 'entry'
178 178 assert_tag :tag => 'th',
179 179 :content => '1',
180 180 :attributes => { :class => 'line-num' },
181 181 :sibling => { :tag => 'td',
182 182 :content => /test-#{@char_1}.txt/ }
183 183 end
184 184 end
185 185 end
186 186 end
187 187
188 188 def test_entry_download
189 189 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
190 190 :format => 'raw'
191 191 assert_response :success
192 192 # File content
193 193 assert @response.body.include?('WITHOUT ANY WARRANTY')
194 194 end
195 195
196 196 def test_directory_entry
197 197 get :entry, :id => PRJ_ID, :path => ['sources']
198 198 assert_response :success
199 199 assert_template 'show'
200 200 assert_not_nil assigns(:entry)
201 201 assert_equal 'sources', assigns(:entry).name
202 202 end
203 203
204 204 def test_diff
205 205 @repository.fetch_changesets
206 206 @repository.reload
207 207 # Full diff of changeset 2f9c0091
208 208 ['inline', 'sbs'].each do |dt|
209 209 get :diff,
210 210 :id => PRJ_ID,
211 211 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
212 212 :type => dt
213 213 assert_response :success
214 214 assert_template 'diff'
215 215 # Line 22 removed
216 216 assert_tag :tag => 'th',
217 217 :content => /22/,
218 218 :sibling => { :tag => 'td',
219 219 :attributes => { :class => /diff_out/ },
220 220 :content => /def remove/ }
221 221 assert_tag :tag => 'h2', :content => /2f9c0091/
222 222 end
223 223 end
224 224
225 225 def test_diff_truncated
226 226 @repository.fetch_changesets
227 227 @repository.reload
228 228 Setting.diff_max_lines_displayed = 5
229 229
230 230 # Truncated diff of changeset 2f9c0091
231 231 with_cache do
232 232 get :diff, :id => PRJ_ID, :type => 'inline',
233 233 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
234 234 assert_response :success
235 235 assert @response.body.include?("... This diff was truncated")
236 236
237 237 Setting.default_language = 'fr'
238 238 get :diff, :id => PRJ_ID, :type => 'inline',
239 239 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
240 240 assert_response :success
241 241 assert ! @response.body.include?("... This diff was truncated")
242 242 assert @response.body.include?("... Ce diff")
243 243 end
244 244 end
245 245
246 246 def test_diff_two_revs
247 247 @repository.fetch_changesets
248 248 @repository.reload
249 249 ['inline', 'sbs'].each do |dt|
250 250 get :diff,
251 251 :id => PRJ_ID,
252 252 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
253 253 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7',
254 254 :type => dt
255 255 assert_response :success
256 256 assert_template 'diff'
257 257 diff = assigns(:diff)
258 258 assert_not_nil diff
259 259 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
260 260 end
261 261 end
262 262
263 263 def test_diff_latin_1
264 264 if @ruby19_non_utf8_pass
265 265 puts_ruby19_non_utf8_pass()
266 266 else
267 267 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
268 268 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
269 269 ['inline', 'sbs'].each do |dt|
270 270 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
271 271 assert_response :success
272 272 assert_template 'diff'
273 273 assert_tag :tag => 'thead',
274 274 :descendant => {
275 275 :tag => 'th',
276 276 :attributes => { :class => 'filename' } ,
277 277 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
278 278 },
279 279 :sibling => {
280 280 :tag => 'tbody',
281 281 :descendant => {
282 282 :tag => 'td',
283 283 :attributes => { :class => /diff_in/ },
284 284 :content => /test-#{@char_1}.txt/
285 285 }
286 286 }
287 287 end
288 288 end
289 289 end
290 290 end
291 291 end
292 292
293 293 def test_annotate
294 294 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
295 295 assert_response :success
296 296 assert_template 'annotate'
297 297 # Line 24, changeset 2f9c0091
298 298 assert_tag :tag => 'th', :content => '24',
299 299 :sibling => {
300 300 :tag => 'td',
301 301 :child => {
302 302 :tag => 'a',
303 303 :content => /2f9c0091/
304 304 }
305 305 }
306 306 assert_tag :tag => 'th', :content => '24',
307 307 :sibling => { :tag => 'td', :content => /jsmith/ }
308 308 assert_tag :tag => 'th', :content => '24',
309 309 :sibling => {
310 310 :tag => 'td',
311 311 :child => {
312 312 :tag => 'a',
313 313 :content => /2f9c0091/
314 314 }
315 315 }
316 316 assert_tag :tag => 'th', :content => '24',
317 317 :sibling => { :tag => 'td', :content => /watcher =/ }
318 318 end
319 319
320 320 def test_annotate_at_given_revision
321 321 @repository.fetch_changesets
322 322 @repository.reload
323 323 get :annotate, :id => PRJ_ID, :rev => 'deff7',
324 324 :path => ['sources', 'watchers_controller.rb']
325 325 assert_response :success
326 326 assert_template 'annotate'
327 327 assert_tag :tag => 'h2', :content => /@ deff712f/
328 328 end
329 329
330 330 def test_annotate_binary_file
331 331 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
332 332 assert_response 500
333 333 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
334 334 :content => /cannot be annotated/
335 335 end
336 336
337 337 def test_annotate_latin_1
338 338 if @ruby19_non_utf8_pass
339 339 puts_ruby19_non_utf8_pass()
340 340 elsif JRUBY_SKIP
341 341 puts JRUBY_SKIP_STR
342 342 else
343 343 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
344 344 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
345 345 get :annotate, :id => PRJ_ID,
346 346 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
347 347 assert_tag :tag => 'th',
348 348 :content => '1',
349 349 :attributes => { :class => 'line-num' },
350 350 :sibling => { :tag => 'td',
351 351 :content => /test-#{@char_1}.txt/ }
352 352 end
353 353 end
354 354 end
355 355 end
356 356
357 357 def test_revision
358 358 @repository.fetch_changesets
359 359 @repository.reload
360 360 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
361 361 get :revision, :id => PRJ_ID, :rev => r
362 362 assert_response :success
363 363 assert_template 'revision'
364 364 end
365 365 end
366 366
367 367 def test_empty_revision
368 368 @repository.fetch_changesets
369 369 @repository.reload
370 370 ['', ' ', nil].each do |r|
371 371 get :revision, :id => PRJ_ID, :rev => r
372 372 assert_response 404
373 373 assert_error_tag :content => /was not found/
374 374 end
375 375 end
376 376
377 def test_destroy_valid_repository
378 @request.session[:user_id] = 1 # admin
379 @repository.fetch_changesets
380 @repository.reload
381 assert @repository.changesets.count > 0
382
383 get :destroy, :id => PRJ_ID
384 assert_response 302
385 @project.reload
386 assert_nil @project.repository
387 end
388
377 389 private
378 390
379 391 def puts_ruby19_non_utf8_pass
380 392 puts "TODO: This test fails in Ruby 1.9 " +
381 393 "and Encoding.default_external is not UTF-8. " +
382 394 "Current value is '#{Encoding.default_external.to_s}'"
383 395 end
384 396 else
385 397 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
386 398 def test_fake; assert true end
387 399 end
388 400
389 401 private
390 402 def with_cache(&block)
391 403 before = ActionController::Base.perform_caching
392 404 ActionController::Base.perform_caching = true
393 405 block.call
394 406 ActionController::Base.perform_caching = before
395 407 end
396 408 end
General Comments 0
You need to be logged in to leave comments. Login now