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