comparison test/functional/.svn/text-base/repositories_mercurial_controller_test.rb.svn-base @ 442:753f1380d6bc cannam

Merge from branch "redmine-1.2"
author Chris Cannam
date Mon, 06 Jun 2011 14:41:04 +0100
parents eeebe205a056 cbce1fd3b1b7
children 851510f1b535
comparison
equal deleted inserted replaced
252:adc8466df404 442:753f1380d6bc
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.expand_path('../../test_helper', __FILE__) 18 require File.expand_path('../../test_helper', __FILE__)
23 23
24 class RepositoriesMercurialControllerTest < ActionController::TestCase 24 class RepositoriesMercurialControllerTest < ActionController::TestCase
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/mercurial_repository' 28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') +
29 '/tmp/test/mercurial_repository'
30 CHAR_1_HEX = "\xc3\x9c"
31 PRJ_ID = 3
32
33 ruby19_non_utf8_pass =
34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
29 35
30 def setup 36 def setup
31 @controller = RepositoriesController.new 37 @controller = RepositoriesController.new
32 @request = ActionController::TestRequest.new 38 @request = ActionController::TestRequest.new
33 @response = ActionController::TestResponse.new 39 @response = ActionController::TestResponse.new
34 User.current = nil 40 User.current = nil
35 @repository = Repository::Mercurial.create(:project => Project.find(3), :url => REPOSITORY_PATH) 41 @repository = Repository::Mercurial.create(
42 :project => Project.find(PRJ_ID),
43 :url => REPOSITORY_PATH,
44 :path_encoding => 'ISO-8859-1'
45 )
36 assert @repository 46 assert @repository
37 @diff_c_support = true 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')
57 end
38 end 58 end
39 59
40 if File.directory?(REPOSITORY_PATH) 60 if ruby19_non_utf8_pass
41 def test_show 61 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
42 get :show, :id => 3 62 "and Encoding.default_external is not UTF-8. " +
43 assert_response :success 63 "Current value is '#{Encoding.default_external.to_s}'"
44 assert_template 'show' 64 def test_fake; assert true end
45 assert_not_nil assigns(:entries) 65 elsif File.directory?(REPOSITORY_PATH)
46 assert_not_nil assigns(:changesets)
47 end
48
49 def test_show_root 66 def test_show_root
50 get :show, :id => 3 67 @repository.fetch_changesets
68 @repository.reload
69 get :show, :id => PRJ_ID
51 assert_response :success 70 assert_response :success
52 assert_template 'show' 71 assert_template 'show'
53 assert_not_nil assigns(:entries) 72 assert_not_nil assigns(:entries)
54 assert_equal 4, assigns(:entries).size 73 assert_equal 4, assigns(:entries).size
55 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} 74 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
56 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} 75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
57 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} 76 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 assert_not_nil assigns(:changesets)
78 assigns(:changesets).size > 0
58 end 79 end
59 80
60 def test_show_directory 81 def test_show_directory
61 get :show, :id => 3, :path => ['images'] 82 @repository.fetch_changesets
83 @repository.reload
84 get :show, :id => PRJ_ID, :path => ['images']
62 assert_response :success 85 assert_response :success
63 assert_template 'show' 86 assert_template 'show'
64 assert_not_nil assigns(:entries) 87 assert_not_nil assigns(:entries)
65 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) 88 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
66 entry = assigns(:entries).detect {|e| e.name == 'edit.png'} 89 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
67 assert_not_nil entry 90 assert_not_nil entry
68 assert_equal 'file', entry.kind 91 assert_equal 'file', entry.kind
69 assert_equal 'images/edit.png', entry.path 92 assert_equal 'images/edit.png', entry.path
93 assert_not_nil assigns(:changesets)
94 assigns(:changesets).size > 0
70 end 95 end
71 96
72 def test_show_at_given_revision 97 def test_show_at_given_revision
98 @repository.fetch_changesets
99 @repository.reload
73 [0, '0', '0885933ad4f6'].each do |r1| 100 [0, '0', '0885933ad4f6'].each do |r1|
74 get :show, :id => 3, :path => ['images'], :rev => r1 101 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
75 assert_response :success 102 assert_response :success
76 assert_template 'show' 103 assert_template 'show'
77 assert_not_nil assigns(:entries) 104 assert_not_nil assigns(:entries)
78 assert_equal ['delete.png'], assigns(:entries).collect(&:name) 105 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 assert_not_nil assigns(:changesets)
107 assigns(:changesets).size > 0
79 end 108 end
80 end 109 end
81 110
82 def test_show_directory_sql_escape_percent 111 def test_show_directory_sql_escape_percent
112 @repository.fetch_changesets
113 @repository.reload
83 [13, '13', '3a330eb32958'].each do |r1| 114 [13, '13', '3a330eb32958'].each do |r1|
84 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1 115 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
116 :rev => r1
85 assert_response :success 117 assert_response :success
86 assert_template 'show' 118 assert_template 'show'
87 119
88 assert_not_nil assigns(:entries) 120 assert_not_nil assigns(:entries)
89 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name) 121 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 assigns(:entries).collect(&:name)
90 changesets = assigns(:changesets) 123 changesets = assigns(:changesets)
91 124 assert_not_nil changesets
92 ## This is not yet implemented. 125 assigns(:changesets).size > 0
93 # assert_not_nil changesets 126 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
94 # assert_equal %w(13 11 10 9), changesets.collect(&:revision) 127 end
128 end
129
130 def test_show_directory_latin_1_path
131 @repository.fetch_changesets
132 @repository.reload
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'
137
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)
146 end
147 end
148
149 def test_show_branch
150 @repository.fetch_changesets
151 @repository.reload
152 [
153 'default',
154 @branch_char_1,
155 'branch (1)[2]&,%.-3_4',
156 @branch_char_0,
157 'test_branch.latin-1',
158 'test-branch-00',
159 ].each do |bra|
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
167 end
168 end
169
170 def test_show_tag
171 @repository.fetch_changesets
172 @repository.reload
173 [
174 @tag_char_1,
175 'tag_test.00',
176 'tag-init-revision'
177 ].each do |tag|
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
95 end 185 end
96 end 186 end
97 187
98 def test_changes 188 def test_changes
99 get :changes, :id => 3, :path => ['images', 'edit.png'] 189 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
100 assert_response :success 190 assert_response :success
101 assert_template 'changes' 191 assert_template 'changes'
102 assert_tag :tag => 'h2', :content => 'edit.png' 192 assert_tag :tag => 'h2', :content => 'edit.png'
103 end 193 end
104 194
105 def test_entry_show 195 def test_entry_show
106 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'] 196 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
107 assert_response :success 197 assert_response :success
108 assert_template 'entry' 198 assert_template 'entry'
109 # Line 10 199 # Line 10
110 assert_tag :tag => 'th', 200 assert_tag :tag => 'th',
111 :content => '10', 201 :content => '10',
112 :attributes => { :class => 'line-num' }, 202 :attributes => { :class => 'line-num' },
113 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } 203 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
114 end 204 end
115 205
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',
213 :content => '1',
214 :attributes => { :class => 'line-num' },
215 :sibling => { :tag => 'td',
216 :content => /Mercurial is a distributed version control system/ }
217 end
218 end
219
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',
228 :content => '1',
229 :attributes => { :class => 'line-num' },
230 :sibling => { :tag => 'td',
231 :content => /test-#{@char_1}.txt/ }
232 end
233 end
234 end
235
116 def test_entry_download 236 def test_entry_download
117 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw' 237 get :entry, :id => PRJ_ID,
238 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
118 assert_response :success 239 assert_response :success
119 # File content 240 # File content
120 assert @response.body.include?('WITHOUT ANY WARRANTY') 241 assert @response.body.include?('WITHOUT ANY WARRANTY')
121 end 242 end
122 243
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
248 end
249
123 def test_directory_entry 250 def test_directory_entry
124 get :entry, :id => 3, :path => ['sources'] 251 get :entry, :id => PRJ_ID, :path => ['sources']
125 assert_response :success 252 assert_response :success
126 assert_template 'show' 253 assert_template 'show'
127 assert_not_nil assigns(:entry) 254 assert_not_nil assigns(:entry)
128 assert_equal 'sources', assigns(:entry).name 255 assert_equal 'sources', assigns(:entry).name
129 end 256 end
130 257
131 def test_diff 258 def test_diff
132 @repository.fetch_changesets 259 @repository.fetch_changesets
133 @repository.reload 260 @repository.reload
134
135 [4, '4', 'def6d2f1254a'].each do |r1| 261 [4, '4', 'def6d2f1254a'].each do |r1|
136 # Full diff of changeset 4 262 # Full diff of changeset 4
137 get :diff, :id => 3, :rev => r1 263 get :diff, :id => PRJ_ID, :rev => r1
138 assert_response :success 264 assert_response :success
139 assert_template 'diff' 265 assert_template 'diff'
140
141 if @diff_c_support 266 if @diff_c_support
142 # Line 22 removed 267 # Line 22 removed
143 assert_tag :tag => 'th', 268 assert_tag :tag => 'th',
144 :content => '22', 269 :content => '22',
145 :sibling => { :tag => 'td', 270 :sibling => { :tag => 'td',
146 :attributes => { :class => /diff_out/ }, 271 :attributes => { :class => /diff_out/ },
147 :content => /def remove/ } 272 :content => /def remove/ }
148 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ 273 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
149 end 274 end
150 end 275 end
151 end 276 end
152 277
153 def test_diff_two_revs 278 def test_diff_two_revs
154 @repository.fetch_changesets 279 @repository.fetch_changesets
155 @repository.reload 280 @repository.reload
156
157 [2, '400bb8672109', '400', 400].each do |r1| 281 [2, '400bb8672109', '400', 400].each do |r1|
158 [4, 'def6d2f1254a'].each do |r2| 282 [4, 'def6d2f1254a'].each do |r2|
159 get :diff, :id => 3, :rev => r1, 283 get :diff, :id => PRJ_ID, :rev => r1,
160 :rev_to => r2 284 :rev_to => r2
161 assert_response :success 285 assert_response :success
162 assert_template 'diff' 286 assert_template 'diff'
163 287
164 diff = assigns(:diff) 288 diff = assigns(:diff)
165 assert_not_nil diff 289 assert_not_nil diff
166 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/ 290 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
167 end 291 end
168 end 292 end
169 end 293 end
170 294
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',
302 :descendant => {
303 :tag => 'th',
304 :attributes => { :class => 'filename' } ,
305 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
306 },
307 :sibling => {
308 :tag => 'tbody',
309 :descendant => {
310 :tag => 'td',
311 :attributes => { :class => /diff_in/ },
312 :content => /It is written in Python/
313 }
314 }
315 end
316 end
317 end
318
171 def test_annotate 319 def test_annotate
172 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb'] 320 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
173 assert_response :success 321 assert_response :success
174 assert_template 'annotate' 322 assert_template 'annotate'
175 # Line 23, revision 4:def6d2f1254a 323 # Line 23, revision 4:def6d2f1254a
176 assert_tag :tag => 'th', 324 assert_tag :tag => 'th',
177 :content => '23', 325 :content => '23',
199 347
200 def test_annotate_at_given_revision 348 def test_annotate_at_given_revision
201 @repository.fetch_changesets 349 @repository.fetch_changesets
202 @repository.reload 350 @repository.reload
203 [2, '400bb8672109', '400', 400].each do |r1| 351 [2, '400bb8672109', '400', 400].each do |r1|
204 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb'] 352 get :annotate, :id => PRJ_ID, :rev => r1,
353 :path => ['sources', 'watchers_controller.rb']
205 assert_response :success 354 assert_response :success
206 assert_template 'annotate' 355 assert_template 'annotate'
207 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ 356 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
208 end 357 end
209 end 358 end
210 359
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',
367 :content => '1',
368 :attributes => { :class => 'line-num' },
369 :sibling =>
370 {
371 :tag => 'td',
372 :attributes => { :class => 'revision' },
373 :child => { :tag => 'a', :content => '20:709858aafd1b' }
374 }
375 assert_tag :tag => 'th',
376 :content => '1',
377 :attributes => { :class => 'line-num' },
378 :sibling =>
379 {
380 :tag => 'td' ,
381 :content => 'jsmith' ,
382 :attributes => { :class => 'author' },
383 }
384 assert_tag :tag => 'th',
385 :content => '1',
386 :attributes => { :class => 'line-num' },
387 :sibling => { :tag => 'td',
388 :content => /Mercurial is a distributed version control system/ }
389
390 end
391 end
392
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',
399 :content => '1',
400 :attributes => { :class => 'line-num' },
401 :sibling => { :tag => 'td',
402 :content => /test-#{@char_1}.txt/ }
403 end
404 end
405 end
406
211 def test_empty_revision 407 def test_empty_revision
212 @repository.fetch_changesets 408 @repository.fetch_changesets
213 @repository.reload 409 @repository.reload
214 ['', ' ', nil].each do |r| 410 ['', ' ', nil].each do |r|
215 get :revision, :id => 3, :rev => r 411 get :revision, :id => PRJ_ID, :rev => r
216 assert_response 404 412 assert_response 404
217 assert_error_tag :content => /was not found/ 413 assert_error_tag :content => /was not found/
218 end 414 end
219 end 415 end
220 else 416 else