comparison test/functional/repositories_git_controller_test.rb @ 524:1248a47e81b3 feature_36

Merge from branch "luisf"
author luisf <luis.figueira@eecs.qmul.ac.uk>
date Mon, 25 Jul 2011 14:39:38 +0100
parents 0c939c159af4
children cbb26bc654de
comparison
equal deleted inserted replaced
519:3be6bc3c2a17 524:1248a47e81b3
1 # redMine - project management software 1 # Redmine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang 2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 # 3 #
4 # This program is free software; you can redistribute it and/or 4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License 5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2 6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version. 7 # of the License, or (at your option) any later version.
8 # 8 #
9 # This program is distributed in the hope that it will be useful, 9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of 10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details. 12 # GNU General Public License for more details.
13 # 13 #
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software 15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 17
18 require File.dirname(__FILE__) + '/../test_helper' 18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller' 19 require 'repositories_controller'
20 20
21 # Re-raise errors caught by the controller. 21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end 22 class RepositoriesController; def rescue_action(e) raise e end; end
23 23
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules 25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26 26
27 # No '..' in the repository path 27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? 29 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
30 PRJ_ID = 3
31 CHAR_1_HEX = "\xc3\x9c"
30 32
31 def setup 33 def setup
34 @ruby19_non_utf8_pass =
35 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
36
32 @controller = RepositoriesController.new 37 @controller = RepositoriesController.new
33 @request = ActionController::TestRequest.new 38 @request = ActionController::TestRequest.new
34 @response = ActionController::TestResponse.new 39 @response = ActionController::TestResponse.new
35 User.current = nil 40 User.current = nil
36 Repository::Git.create(:project => Project.find(3), :url => REPOSITORY_PATH) 41 @repository = Repository::Git.create(
42 :project => Project.find(3),
43 :url => REPOSITORY_PATH,
44 :path_encoding => 'ISO-8859-1'
45 )
46 assert @repository
47 @char_1 = CHAR_1_HEX.dup
48 if @char_1.respond_to?(:force_encoding)
49 @char_1.force_encoding('UTF-8')
50 end
51
52 Setting.default_language = 'en'
37 end 53 end
38 54
39 if File.directory?(REPOSITORY_PATH) 55 if File.directory?(REPOSITORY_PATH)
40 def test_show
41 get :show, :id => 3
42 assert_response :success
43 assert_template 'show'
44 assert_not_nil assigns(:entries)
45 assert_not_nil assigns(:changesets)
46 end
47
48 def test_browse_root 56 def test_browse_root
49 get :show, :id => 3 57 @repository.fetch_changesets
58 @repository.reload
59 get :show, :id => PRJ_ID
50 assert_response :success 60 assert_response :success
51 assert_template 'show' 61 assert_template 'show'
52 assert_not_nil assigns(:entries) 62 assert_not_nil assigns(:entries)
53 assert_equal 9, assigns(:entries).size 63 assert_equal 9, assigns(:entries).size
54 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 64 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
58 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'} 68 assert assigns(:entries).detect {|e| e.name == 'copied_README' && e.kind == 'file'}
59 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'} 69 assert assigns(:entries).detect {|e| e.name == 'new_file.txt' && e.kind == 'file'}
60 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'} 70 assert assigns(:entries).detect {|e| e.name == 'renamed_test.txt' && e.kind == 'file'}
61 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'} 71 assert assigns(:entries).detect {|e| e.name == 'filemane with spaces.txt' && e.kind == 'file'}
62 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'} 72 assert assigns(:entries).detect {|e| e.name == ' filename with a leading space.txt ' && e.kind == 'file'}
73 assert_not_nil assigns(:changesets)
74 assigns(:changesets).size > 0
63 end 75 end
64 76
65 def test_browse_branch 77 def test_browse_branch
66 get :show, :id => 3, :rev => 'test_branch' 78 @repository.fetch_changesets
79 @repository.reload
80 get :show, :id => PRJ_ID, :rev => 'test_branch'
67 assert_response :success 81 assert_response :success
68 assert_template 'show' 82 assert_template 'show'
69 assert_not_nil assigns(:entries) 83 assert_not_nil assigns(:entries)
70 assert_equal 4, assigns(:entries).size 84 assert_equal 4, assigns(:entries).size
71 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 85 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
72 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} 86 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
73 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} 87 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
74 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'} 88 assert assigns(:entries).detect {|e| e.name == 'test.txt' && e.kind == 'file'}
89 assert_not_nil assigns(:changesets)
90 assigns(:changesets).size > 0
91 end
92
93 def test_browse_tag
94 @repository.fetch_changesets
95 @repository.reload
96 [
97 "tag00.lightweight",
98 "tag01.annotated",
99 ].each do |t1|
100 get :show, :id => PRJ_ID, :rev => t1
101 assert_response :success
102 assert_template 'show'
103 assert_not_nil assigns(:entries)
104 assigns(:entries).size > 0
105 assert_not_nil assigns(:changesets)
106 assigns(:changesets).size > 0
107 end
75 end 108 end
76 109
77 def test_browse_directory 110 def test_browse_directory
78 get :show, :id => 3, :path => ['images'] 111 @repository.fetch_changesets
112 @repository.reload
113 get :show, :id => PRJ_ID, :path => ['images']
79 assert_response :success 114 assert_response :success
80 assert_template 'show' 115 assert_template 'show'
81 assert_not_nil assigns(:entries) 116 assert_not_nil assigns(:entries)
82 assert_equal ['edit.png'], assigns(:entries).collect(&:name) 117 assert_equal ['edit.png'], assigns(:entries).collect(&:name)
83 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} 118 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
84 assert_not_nil entry 119 assert_not_nil entry
85 assert_equal 'file', entry.kind 120 assert_equal 'file', entry.kind
86 assert_equal 'images/edit.png', entry.path 121 assert_equal 'images/edit.png', entry.path
87 end 122 assert_not_nil assigns(:changesets)
88 123 assigns(:changesets).size > 0
124 end
125
89 def test_browse_at_given_revision 126 def test_browse_at_given_revision
90 get :show, :id => 3, :path => ['images'], :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518' 127 @repository.fetch_changesets
128 @repository.reload
129 get :show, :id => PRJ_ID, :path => ['images'],
130 :rev => '7234cb2750b63f47bff735edc50a1c0a433c2518'
91 assert_response :success 131 assert_response :success
92 assert_template 'show' 132 assert_template 'show'
93 assert_not_nil assigns(:entries) 133 assert_not_nil assigns(:entries)
94 assert_equal ['delete.png'], assigns(:entries).collect(&:name) 134 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
135 assert_not_nil assigns(:changesets)
136 assigns(:changesets).size > 0
95 end 137 end
96 138
97 def test_changes 139 def test_changes
98 get :changes, :id => 3, :path => ['images', 'edit.png'] 140 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
99 assert_response :success 141 assert_response :success
100 assert_template 'changes' 142 assert_template 'changes'
101 assert_tag :tag => 'h2', :content => 'edit.png' 143 assert_tag :tag => 'h2', :content => 'edit.png'
102 end 144 end
103 145
104 def test_entry_show 146 def test_entry_show
105 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] 147 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
106 assert_response :success 148 assert_response :success
107 assert_template 'entry' 149 assert_template 'entry'
108 # Line 19 150 # Line 19
109 assert_tag :tag => 'th', 151 assert_tag :tag => 'th',
110 :content => /11/, 152 :content => '11',
111 :attributes => { :class => /line-num/ }, 153 :attributes => { :class => 'line-num' },
112 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } 154 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
113 end 155 end
114 156
157 def test_entry_show_latin_1
158 if @ruby19_non_utf8_pass
159 puts_ruby19_non_utf8_pass()
160 else
161 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
162 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
163 get :entry, :id => PRJ_ID,
164 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
165 assert_response :success
166 assert_template 'entry'
167 assert_tag :tag => 'th',
168 :content => '1',
169 :attributes => { :class => 'line-num' },
170 :sibling => { :tag => 'td',
171 :content => /test-#{@char_1}.txt/ }
172 end
173 end
174 end
175 end
176
115 def test_entry_download 177 def test_entry_download
116 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' 178 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb'],
179 :format => 'raw'
117 assert_response :success 180 assert_response :success
118 # File content 181 # File content
119 assert @response.body.include?('WITHOUT ANY WARRANTY') 182 assert @response.body.include?('WITHOUT ANY WARRANTY')
120 end 183 end
121 184
122 def test_directory_entry 185 def test_directory_entry
123 get :entry, :id => 3, :path => ['sources'] 186 get :entry, :id => PRJ_ID, :path => ['sources']
124 assert_response :success 187 assert_response :success
125 assert_template 'show' 188 assert_template 'show'
126 assert_not_nil assigns(:entry) 189 assert_not_nil assigns(:entry)
127 assert_equal 'sources', assigns(:entry).name 190 assert_equal 'sources', assigns(:entry).name
128 end 191 end
129 192
130 def test_diff 193 def test_diff
194 @repository.fetch_changesets
195 @repository.reload
131 # Full diff of changeset 2f9c0091 196 # Full diff of changeset 2f9c0091
132 get :diff, :id => 3, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7' 197 get :diff, :id => PRJ_ID, :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
133 assert_response :success 198 assert_response :success
134 assert_template 'diff' 199 assert_template 'diff'
135 # Line 22 removed 200 # Line 22 removed
136 assert_tag :tag => 'th', 201 assert_tag :tag => 'th',
137 :content => /22/, 202 :content => /22/,
138 :sibling => { :tag => 'td', 203 :sibling => { :tag => 'td',
139 :attributes => { :class => /diff_out/ }, 204 :attributes => { :class => /diff_out/ },
140 :content => /def remove/ } 205 :content => /def remove/ }
206 assert_tag :tag => 'h2', :content => /2f9c0091/
207 end
208
209 def test_diff_truncated
210 @repository.fetch_changesets
211 @repository.reload
212 Setting.diff_max_lines_displayed = 5
213
214 # Truncated diff of changeset 2f9c0091
215 with_cache do
216 get :diff, :id => PRJ_ID, :type => 'inline',
217 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
218 assert_response :success
219 assert @response.body.include?("... This diff was truncated")
220
221 Setting.default_language = 'fr'
222 get :diff, :id => PRJ_ID, :type => 'inline',
223 :rev => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
224 assert_response :success
225 assert ! @response.body.include?("... This diff was truncated")
226 assert @response.body.include?("... Ce diff")
227 end
228 end
229
230 def test_diff_two_revs
231 @repository.fetch_changesets
232 @repository.reload
233 get :diff, :id => PRJ_ID,
234 :rev => '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
235 :rev_to => '2f9c0091c754a91af7a9c478e36556b4bde8dcf7'
236 assert_response :success
237 assert_template 'diff'
238 diff = assigns(:diff)
239 assert_not_nil diff
240 assert_tag :tag => 'h2', :content => /2f9c0091:61b685fb/
241 end
242
243 def test_diff_latin_1
244 if @ruby19_non_utf8_pass
245 puts_ruby19_non_utf8_pass()
246 else
247 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
248 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
249 get :diff, :id => PRJ_ID, :rev => r1
250 assert_response :success
251 assert_template 'diff'
252 assert_tag :tag => 'thead',
253 :descendant => {
254 :tag => 'th',
255 :attributes => { :class => 'filename' } ,
256 :content => /latin-1-dir\/test-#{@char_1}.txt/ ,
257 },
258 :sibling => {
259 :tag => 'tbody',
260 :descendant => {
261 :tag => 'td',
262 :attributes => { :class => /diff_in/ },
263 :content => /test-#{@char_1}.txt/
264 }
265 }
266 end
267 end
268 end
141 end 269 end
142 270
143 def test_annotate 271 def test_annotate
144 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] 272 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
145 assert_response :success 273 assert_response :success
146 assert_template 'annotate' 274 assert_template 'annotate'
147 # Line 23, changeset 2f9c0091 275 # Line 23, changeset 2f9c0091
148 assert_tag :tag => 'th', :content => /24/, 276 assert_tag :tag => 'th', :content => '24',
149 :sibling => { :tag => 'td', :child => { :tag => 'a', :content => /2f9c0091/ } }, 277 :sibling => {
150 :sibling => { :tag => 'td', :content => /jsmith/ }, 278 :tag => 'td',
279 :child => {
280 :tag => 'a',
281 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
282 }
283 },
284 :sibling => { :tag => 'td', :content => /jsmith/ }
285 assert_tag :tag => 'th', :content => '24',
286 :sibling => {
287 :tag => 'td',
288 :child => {
289 :tag => 'a',
290 :content => /2f9c0091c754a91af7a9c478e36556b4bde8dcf7/
291 }
292 },
151 :sibling => { :tag => 'td', :content => /watcher =/ } 293 :sibling => { :tag => 'td', :content => /watcher =/ }
152 end 294 end
153 295
296 def test_annotate_at_given_revision
297 @repository.fetch_changesets
298 @repository.reload
299 get :annotate, :id => PRJ_ID, :rev => 'deff7',
300 :path => ['sources', 'watchers_controller.rb']
301 assert_response :success
302 assert_template 'annotate'
303 assert_tag :tag => 'h2', :content => /@ deff712f/
304 end
305
154 def test_annotate_binary_file 306 def test_annotate_binary_file
155 get :annotate, :id => 3, :path => ['images', 'edit.png'] 307 get :annotate, :id => PRJ_ID, :path => ['images', 'edit.png']
156 assert_response 500 308 assert_response 500
157 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ }, 309 assert_tag :tag => 'p', :attributes => { :id => /errorExplanation/ },
158 :content => /can not be annotated/ 310 :content => /cannot be annotated/
311 end
312
313 def test_annotate_latin_1
314 if @ruby19_non_utf8_pass
315 puts_ruby19_non_utf8_pass()
316 else
317 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
318 ['57ca437c', '57ca437c0acbbcb749821fdf3726a1367056d364'].each do |r1|
319 get :annotate, :id => PRJ_ID,
320 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
321 assert_tag :tag => 'th',
322 :content => '1',
323 :attributes => { :class => 'line-num' },
324 :sibling => { :tag => 'td',
325 :content => /test-#{@char_1}.txt/ }
326 end
327 end
328 end
329 end
330
331 def test_revision
332 @repository.fetch_changesets
333 @repository.reload
334 ['61b685fbe55ab05b5ac68402d5720c1a6ac973d1', '61b685f'].each do |r|
335 get :revision, :id => PRJ_ID, :rev => r
336 assert_response :success
337 assert_template 'revision'
338 end
339 end
340
341 def test_empty_revision
342 @repository.fetch_changesets
343 @repository.reload
344 ['', ' ', nil].each do |r|
345 get :revision, :id => PRJ_ID, :rev => r
346 assert_response 404
347 assert_error_tag :content => /was not found/
348 end
349 end
350
351 private
352
353 def puts_ruby19_non_utf8_pass
354 puts "TODO: This test fails in Ruby 1.9 " +
355 "and Encoding.default_external is not UTF-8. " +
356 "Current value is '#{Encoding.default_external.to_s}'"
159 end 357 end
160 else 358 else
161 puts "Git test repository NOT FOUND. Skipping functional tests !!!" 359 puts "Git test repository NOT FOUND. Skipping functional tests !!!"
162 def test_fake; assert true end 360 def test_fake; assert true end
163 end 361 end
362
363 private
364 def with_cache(&block)
365 before = ActionController::Base.perform_caching
366 ActionController::Base.perform_caching = true
367 block.call
368 ActionController::Base.perform_caching = before
369 end
164 end 370 end