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