1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
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
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 require File.expand_path('../../test_helper', __FILE__)
19 require 'repositories_controller'
21 # Re-raise errors caught by the controller.
22 class RepositoriesController; def rescue_action(e) raise e end; end
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
29 '/tmp/test/mercurial_repository'
30 CHAR_1_HEX = "\xc3\x9c"
33 ruby19_non_utf8_pass =
34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
37 @controller = RepositoriesController.new
38 @request = ActionController::TestRequest.new
39 @response = ActionController::TestResponse.new
41 @repository = Repository::Mercurial.create(
42 :project => Project.find(PRJ_ID),
43 :url => REPOSITORY_PATH,
44 :path_encoding => 'ISO-8859-1'
47 @diff_c_support = true
48 @char_1 = CHAR_1_HEX.dup
49 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
50 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
51 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
52 if @char_1.respond_to?(:force_encoding)
53 @char_1.force_encoding('UTF-8')
54 @tag_char_1.force_encoding('UTF-8')
55 @branch_char_0.force_encoding('UTF-8')
56 @branch_char_1.force_encoding('UTF-8')
60 if ruby19_non_utf8_pass
61 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
62 "and Encoding.default_external is not UTF-8. " +
63 "Current value is '#{Encoding.default_external.to_s}'"
64 def test_fake; assert true end
65 elsif File.directory?(REPOSITORY_PATH)
67 @repository.fetch_changesets
69 get :show, :id => PRJ_ID
70 assert_response :success
71 assert_template 'show'
72 assert_not_nil assigns(:entries)
73 assert_equal 4, assigns(:entries).size
74 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 assert_not_nil assigns(:changesets)
78 assigns(:changesets).size > 0
81 def test_show_directory
82 @repository.fetch_changesets
84 get :show, :id => PRJ_ID, :path => ['images']
85 assert_response :success
86 assert_template 'show'
87 assert_not_nil assigns(:entries)
88 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
89 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
91 assert_equal 'file', entry.kind
92 assert_equal 'images/edit.png', entry.path
93 assert_not_nil assigns(:changesets)
94 assigns(:changesets).size > 0
97 def test_show_at_given_revision
98 @repository.fetch_changesets
100 [0, '0', '0885933ad4f6'].each do |r1|
101 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
102 assert_response :success
103 assert_template 'show'
104 assert_not_nil assigns(:entries)
105 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 assert_not_nil assigns(:changesets)
107 assigns(:changesets).size > 0
111 def test_show_directory_sql_escape_percent
112 @repository.fetch_changesets
114 [13, '13', '3a330eb32958'].each do |r1|
115 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
117 assert_response :success
118 assert_template 'show'
120 assert_not_nil assigns(:entries)
121 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 assigns(:entries).collect(&:name)
123 changesets = assigns(:changesets)
124 assert_not_nil changesets
125 assigns(:changesets).size > 0
126 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
130 def test_show_directory_latin_1_path
131 @repository.fetch_changesets
133 [21, '21', 'adf805632193'].each do |r1|
134 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
135 assert_response :success
136 assert_template 'show'
138 assert_not_nil assigns(:entries)
139 assert_equal ["make-latin-1-file.rb",
140 "test-#{@char_1}-1.txt",
141 "test-#{@char_1}-2.txt",
142 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
143 changesets = assigns(:changesets)
144 assert_not_nil changesets
145 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
150 @repository.fetch_changesets
155 'branch (1)[2]&,%.-3_4',
157 'test_branch.latin-1',
160 get :show, :id => PRJ_ID, :rev => bra
161 assert_response :success
162 assert_template 'show'
163 assert_not_nil assigns(:entries)
164 assert assigns(:entries).size > 0
165 assert_not_nil assigns(:changesets)
166 assigns(:changesets).size > 0
171 @repository.fetch_changesets
178 get :show, :id => PRJ_ID, :rev => tag
179 assert_response :success
180 assert_template 'show'
181 assert_not_nil assigns(:entries)
182 assert assigns(:entries).size > 0
183 assert_not_nil assigns(:changesets)
184 assigns(:changesets).size > 0
189 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
190 assert_response :success
191 assert_template 'changes'
192 assert_tag :tag => 'h2', :content => 'edit.png'
196 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
197 assert_response :success
198 assert_template 'entry'
200 assert_tag :tag => 'th',
202 :attributes => { :class => 'line-num' },
203 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
206 def test_entry_show_latin_1_path
207 [21, '21', 'adf805632193'].each do |r1|
208 get :entry, :id => PRJ_ID,
209 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
210 assert_response :success
211 assert_template 'entry'
212 assert_tag :tag => 'th',
214 :attributes => { :class => 'line-num' },
215 :sibling => { :tag => 'td',
216 :content => /Mercurial is a distributed version control system/ }
220 def test_entry_show_latin_1_contents
221 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
222 [27, '27', '7bbf4c738e71'].each do |r1|
223 get :entry, :id => PRJ_ID,
224 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
225 assert_response :success
226 assert_template 'entry'
227 assert_tag :tag => 'th',
229 :attributes => { :class => 'line-num' },
230 :sibling => { :tag => 'td',
231 :content => /test-#{@char_1}.txt/ }
236 def test_entry_download
237 get :entry, :id => PRJ_ID,
238 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
239 assert_response :success
241 assert @response.body.include?('WITHOUT ANY WARRANTY')
244 def test_entry_binary_force_download
245 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
246 assert_response :success
247 assert_equal 'image/png', @response.content_type
250 def test_directory_entry
251 get :entry, :id => PRJ_ID, :path => ['sources']
252 assert_response :success
253 assert_template 'show'
254 assert_not_nil assigns(:entry)
255 assert_equal 'sources', assigns(:entry).name
259 @repository.fetch_changesets
261 [4, '4', 'def6d2f1254a'].each do |r1|
262 # Full diff of changeset 4
263 get :diff, :id => PRJ_ID, :rev => r1
264 assert_response :success
265 assert_template 'diff'
268 assert_tag :tag => 'th',
270 :sibling => { :tag => 'td',
271 :attributes => { :class => /diff_out/ },
272 :content => /def remove/ }
273 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
278 def test_diff_two_revs
279 @repository.fetch_changesets
281 [2, '400bb8672109', '400', 400].each do |r1|
282 [4, 'def6d2f1254a'].each do |r2|
283 get :diff, :id => PRJ_ID, :rev => r1,
285 assert_response :success
286 assert_template 'diff'
288 diff = assigns(:diff)
290 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
295 def test_diff_latin_1_path
296 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
297 [21, 'adf805632193'].each do |r1|
298 get :diff, :id => PRJ_ID, :rev => r1
299 assert_response :success
300 assert_template 'diff'
301 assert_tag :tag => 'thead',
304 :attributes => { :class => 'filename' } ,
305 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
311 :attributes => { :class => /diff_in/ },
312 :content => /It is written in Python/
320 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
321 assert_response :success
322 assert_template 'annotate'
323 # Line 23, revision 4:def6d2f1254a
324 assert_tag :tag => 'th',
326 :attributes => { :class => 'line-num' },
330 :attributes => { :class => 'revision' },
331 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
333 assert_tag :tag => 'th',
335 :attributes => { :class => 'line-num' },
339 :content => 'jsmith' ,
340 :attributes => { :class => 'author' },
342 assert_tag :tag => 'th',
344 :attributes => { :class => 'line-num' },
345 :sibling => { :tag => 'td', :content => /watcher =/ }
348 def test_annotate_at_given_revision
349 @repository.fetch_changesets
351 [2, '400bb8672109', '400', 400].each do |r1|
352 get :annotate, :id => PRJ_ID, :rev => r1,
353 :path => ['sources', 'watchers_controller.rb']
354 assert_response :success
355 assert_template 'annotate'
356 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
360 def test_annotate_latin_1_path
361 [21, '21', 'adf805632193'].each do |r1|
362 get :annotate, :id => PRJ_ID,
363 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
364 assert_response :success
365 assert_template 'annotate'
366 assert_tag :tag => 'th',
368 :attributes => { :class => 'line-num' },
372 :attributes => { :class => 'revision' },
373 :child => { :tag => 'a', :content => '20:709858aafd1b' }
375 assert_tag :tag => 'th',
377 :attributes => { :class => 'line-num' },
381 :content => 'jsmith' ,
382 :attributes => { :class => 'author' },
384 assert_tag :tag => 'th',
386 :attributes => { :class => 'line-num' },
387 :sibling => { :tag => 'td',
388 :content => /Mercurial is a distributed version control system/ }
393 def test_annotate_latin_1_contents
394 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
395 [27, '7bbf4c738e71'].each do |r1|
396 get :annotate, :id => PRJ_ID,
397 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
398 assert_tag :tag => 'th',
400 :attributes => { :class => 'line-num' },
401 :sibling => { :tag => 'td',
402 :content => /test-#{@char_1}.txt/ }
407 def test_empty_revision
408 @repository.fetch_changesets
410 ['', ' ', nil].each do |r|
411 get :revision, :id => PRJ_ID, :rev => r
413 assert_error_tag :content => /was not found/
417 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
418 def test_fake; assert true end