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