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