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