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