##// END OF EJS Templates
scm: mercurial: define NUM_REV as the number of test repository revisions at functional test...
Toshi MARUYAMA -
r7006:467d72bbb8c4
parent child
Show More
@@ -1,479 +1,480
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 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__)
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
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
24 class RepositoriesMercurialControllerTest < ActionController::TestCase
25 fixtures :projects, :users, :roles, :members, :member_roles,
25 fixtures :projects, :users, :roles, :members, :member_roles,
26 :repositories, :enabled_modules
26 :repositories, :enabled_modules
27
27
28 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
28 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30 PRJ_ID = 3
30 PRJ_ID = 3
31 NUM_REV = 29
31
32
32 ruby19_non_utf8_pass =
33 ruby19_non_utf8_pass =
33 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
34 (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
34
35
35 def setup
36 def setup
36 @controller = RepositoriesController.new
37 @controller = RepositoriesController.new
37 @request = ActionController::TestRequest.new
38 @request = ActionController::TestRequest.new
38 @response = ActionController::TestResponse.new
39 @response = ActionController::TestResponse.new
39 User.current = nil
40 User.current = nil
40 @project = Project.find(PRJ_ID)
41 @project = Project.find(PRJ_ID)
41 @repository = Repository::Mercurial.create(
42 @repository = Repository::Mercurial.create(
42 :project => @project,
43 :project => @project,
43 :url => REPOSITORY_PATH,
44 :url => REPOSITORY_PATH,
44 :path_encoding => 'ISO-8859-1'
45 :path_encoding => 'ISO-8859-1'
45 )
46 )
46 assert @repository
47 assert @repository
47 @diff_c_support = true
48 @diff_c_support = true
48 @char_1 = CHAR_1_HEX.dup
49 @char_1 = CHAR_1_HEX.dup
49 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
50 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
50 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
51 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
51 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
52 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
52 if @char_1.respond_to?(:force_encoding)
53 if @char_1.respond_to?(:force_encoding)
53 @char_1.force_encoding('UTF-8')
54 @char_1.force_encoding('UTF-8')
54 @tag_char_1.force_encoding('UTF-8')
55 @tag_char_1.force_encoding('UTF-8')
55 @branch_char_0.force_encoding('UTF-8')
56 @branch_char_0.force_encoding('UTF-8')
56 @branch_char_1.force_encoding('UTF-8')
57 @branch_char_1.force_encoding('UTF-8')
57 end
58 end
58 end
59 end
59
60
60 if ruby19_non_utf8_pass
61 if ruby19_non_utf8_pass
61 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
62 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
62 "and Encoding.default_external is not UTF-8. " +
63 "and Encoding.default_external is not UTF-8. " +
63 "Current value is '#{Encoding.default_external.to_s}'"
64 "Current value is '#{Encoding.default_external.to_s}'"
64 def test_fake; assert true end
65 def test_fake; assert true end
65 elsif File.directory?(REPOSITORY_PATH)
66 elsif File.directory?(REPOSITORY_PATH)
66 def test_show_root
67 def test_show_root
67 @repository.fetch_changesets
68 @repository.fetch_changesets
68 @repository.reload
69 @repository.reload
69 get :show, :id => PRJ_ID
70 get :show, :id => PRJ_ID
70 assert_response :success
71 assert_response :success
71 assert_template 'show'
72 assert_template 'show'
72 assert_not_nil assigns(:entries)
73 assert_not_nil assigns(:entries)
73 assert_equal 4, assigns(:entries).size
74 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 == 'images' && e.kind == 'dir'}
75 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
76 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 assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
77 assert_not_nil assigns(:changesets)
78 assert_not_nil assigns(:changesets)
78 assert assigns(:changesets).size > 0
79 assert assigns(:changesets).size > 0
79 end
80 end
80
81
81 def test_show_directory
82 def test_show_directory
82 @repository.fetch_changesets
83 @repository.fetch_changesets
83 @repository.reload
84 @repository.reload
84 get :show, :id => PRJ_ID, :path => ['images']
85 get :show, :id => PRJ_ID, :path => ['images']
85 assert_response :success
86 assert_response :success
86 assert_template 'show'
87 assert_template 'show'
87 assert_not_nil assigns(:entries)
88 assert_not_nil assigns(:entries)
88 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
89 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
89 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
90 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
90 assert_not_nil entry
91 assert_not_nil entry
91 assert_equal 'file', entry.kind
92 assert_equal 'file', entry.kind
92 assert_equal 'images/edit.png', entry.path
93 assert_equal 'images/edit.png', entry.path
93 assert_not_nil assigns(:changesets)
94 assert_not_nil assigns(:changesets)
94 assert assigns(:changesets).size > 0
95 assert assigns(:changesets).size > 0
95 end
96 end
96
97
97 def test_show_at_given_revision
98 def test_show_at_given_revision
98 @repository.fetch_changesets
99 @repository.fetch_changesets
99 @repository.reload
100 @repository.reload
100 [0, '0', '0885933ad4f6'].each do |r1|
101 [0, '0', '0885933ad4f6'].each do |r1|
101 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
102 get :show, :id => PRJ_ID, :path => ['images'], :rev => r1
102 assert_response :success
103 assert_response :success
103 assert_template 'show'
104 assert_template 'show'
104 assert_not_nil assigns(:entries)
105 assert_not_nil assigns(:entries)
105 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
106 assert_not_nil assigns(:changesets)
107 assert_not_nil assigns(:changesets)
107 assert assigns(:changesets).size > 0
108 assert assigns(:changesets).size > 0
108 end
109 end
109 end
110 end
110
111
111 def test_show_directory_sql_escape_percent
112 def test_show_directory_sql_escape_percent
112 @repository.fetch_changesets
113 @repository.fetch_changesets
113 @repository.reload
114 @repository.reload
114 [13, '13', '3a330eb32958'].each do |r1|
115 [13, '13', '3a330eb32958'].each do |r1|
115 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
116 get :show, :id => PRJ_ID, :path => ['sql_escape', 'percent%dir'],
116 :rev => r1
117 :rev => r1
117 assert_response :success
118 assert_response :success
118 assert_template 'show'
119 assert_template 'show'
119
120
120 assert_not_nil assigns(:entries)
121 assert_not_nil assigns(:entries)
121 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 assert_equal ['percent%file1.txt', 'percentfile1.txt'],
122 assigns(:entries).collect(&:name)
123 assigns(:entries).collect(&:name)
123 changesets = assigns(:changesets)
124 changesets = assigns(:changesets)
124 assert_not_nil changesets
125 assert_not_nil changesets
125 assert assigns(:changesets).size > 0
126 assert assigns(:changesets).size > 0
126 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
127 assert_equal %w(13 11 10 9), changesets.collect(&:revision)
127 end
128 end
128 end
129 end
129
130
130 def test_show_directory_latin_1_path
131 def test_show_directory_latin_1_path
131 @repository.fetch_changesets
132 @repository.fetch_changesets
132 @repository.reload
133 @repository.reload
133 [21, '21', 'adf805632193'].each do |r1|
134 [21, '21', 'adf805632193'].each do |r1|
134 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
135 get :show, :id => PRJ_ID, :path => ['latin-1-dir'], :rev => r1
135 assert_response :success
136 assert_response :success
136 assert_template 'show'
137 assert_template 'show'
137
138
138 assert_not_nil assigns(:entries)
139 assert_not_nil assigns(:entries)
139 assert_equal ["make-latin-1-file.rb",
140 assert_equal ["make-latin-1-file.rb",
140 "test-#{@char_1}-1.txt",
141 "test-#{@char_1}-1.txt",
141 "test-#{@char_1}-2.txt",
142 "test-#{@char_1}-2.txt",
142 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
143 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
143 changesets = assigns(:changesets)
144 changesets = assigns(:changesets)
144 assert_not_nil changesets
145 assert_not_nil changesets
145 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
146 assert_equal %w(21 20 19 18 17), changesets.collect(&:revision)
146 end
147 end
147 end
148 end
148
149
149 def test_show_branch
150 def test_show_branch
150 @repository.fetch_changesets
151 @repository.fetch_changesets
151 @repository.reload
152 @repository.reload
152 [
153 [
153 'default',
154 'default',
154 @branch_char_1,
155 @branch_char_1,
155 'branch (1)[2]&,%.-3_4',
156 'branch (1)[2]&,%.-3_4',
156 @branch_char_0,
157 @branch_char_0,
157 'test_branch.latin-1',
158 'test_branch.latin-1',
158 'test-branch-00',
159 'test-branch-00',
159 ].each do |bra|
160 ].each do |bra|
160 get :show, :id => PRJ_ID, :rev => bra
161 get :show, :id => PRJ_ID, :rev => bra
161 assert_response :success
162 assert_response :success
162 assert_template 'show'
163 assert_template 'show'
163 assert_not_nil assigns(:entries)
164 assert_not_nil assigns(:entries)
164 assert assigns(:entries).size > 0
165 assert assigns(:entries).size > 0
165 assert_not_nil assigns(:changesets)
166 assert_not_nil assigns(:changesets)
166 assert assigns(:changesets).size > 0
167 assert assigns(:changesets).size > 0
167 end
168 end
168 end
169 end
169
170
170 def test_show_tag
171 def test_show_tag
171 @repository.fetch_changesets
172 @repository.fetch_changesets
172 @repository.reload
173 @repository.reload
173 [
174 [
174 @tag_char_1,
175 @tag_char_1,
175 'tag_test.00',
176 'tag_test.00',
176 'tag-init-revision'
177 'tag-init-revision'
177 ].each do |tag|
178 ].each do |tag|
178 get :show, :id => PRJ_ID, :rev => tag
179 get :show, :id => PRJ_ID, :rev => tag
179 assert_response :success
180 assert_response :success
180 assert_template 'show'
181 assert_template 'show'
181 assert_not_nil assigns(:entries)
182 assert_not_nil assigns(:entries)
182 assert assigns(:entries).size > 0
183 assert assigns(:entries).size > 0
183 assert_not_nil assigns(:changesets)
184 assert_not_nil assigns(:changesets)
184 assert assigns(:changesets).size > 0
185 assert assigns(:changesets).size > 0
185 end
186 end
186 end
187 end
187
188
188 def test_changes
189 def test_changes
189 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
190 get :changes, :id => PRJ_ID, :path => ['images', 'edit.png']
190 assert_response :success
191 assert_response :success
191 assert_template 'changes'
192 assert_template 'changes'
192 assert_tag :tag => 'h2', :content => 'edit.png'
193 assert_tag :tag => 'h2', :content => 'edit.png'
193 end
194 end
194
195
195 def test_entry_show
196 def test_entry_show
196 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
197 get :entry, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
197 assert_response :success
198 assert_response :success
198 assert_template 'entry'
199 assert_template 'entry'
199 # Line 10
200 # Line 10
200 assert_tag :tag => 'th',
201 assert_tag :tag => 'th',
201 :content => '10',
202 :content => '10',
202 :attributes => { :class => 'line-num' },
203 :attributes => { :class => 'line-num' },
203 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
204 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
204 end
205 end
205
206
206 def test_entry_show_latin_1_path
207 def test_entry_show_latin_1_path
207 [21, '21', 'adf805632193'].each do |r1|
208 [21, '21', 'adf805632193'].each do |r1|
208 get :entry, :id => PRJ_ID,
209 get :entry, :id => PRJ_ID,
209 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
210 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
210 assert_response :success
211 assert_response :success
211 assert_template 'entry'
212 assert_template 'entry'
212 assert_tag :tag => 'th',
213 assert_tag :tag => 'th',
213 :content => '1',
214 :content => '1',
214 :attributes => { :class => 'line-num' },
215 :attributes => { :class => 'line-num' },
215 :sibling => { :tag => 'td',
216 :sibling => { :tag => 'td',
216 :content => /Mercurial is a distributed version control system/ }
217 :content => /Mercurial is a distributed version control system/ }
217 end
218 end
218 end
219 end
219
220
220 def test_entry_show_latin_1_contents
221 def test_entry_show_latin_1_contents
221 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
222 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
222 [27, '27', '7bbf4c738e71'].each do |r1|
223 [27, '27', '7bbf4c738e71'].each do |r1|
223 get :entry, :id => PRJ_ID,
224 get :entry, :id => PRJ_ID,
224 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
225 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
225 assert_response :success
226 assert_response :success
226 assert_template 'entry'
227 assert_template 'entry'
227 assert_tag :tag => 'th',
228 assert_tag :tag => 'th',
228 :content => '1',
229 :content => '1',
229 :attributes => { :class => 'line-num' },
230 :attributes => { :class => 'line-num' },
230 :sibling => { :tag => 'td',
231 :sibling => { :tag => 'td',
231 :content => /test-#{@char_1}.txt/ }
232 :content => /test-#{@char_1}.txt/ }
232 end
233 end
233 end
234 end
234 end
235 end
235
236
236 def test_entry_download
237 def test_entry_download
237 get :entry, :id => PRJ_ID,
238 get :entry, :id => PRJ_ID,
238 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
239 :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
239 assert_response :success
240 assert_response :success
240 # File content
241 # File content
241 assert @response.body.include?('WITHOUT ANY WARRANTY')
242 assert @response.body.include?('WITHOUT ANY WARRANTY')
242 end
243 end
243
244
244 def test_entry_binary_force_download
245 def test_entry_binary_force_download
245 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
246 get :entry, :id => PRJ_ID, :rev => 1, :path => ['images', 'edit.png']
246 assert_response :success
247 assert_response :success
247 assert_equal 'image/png', @response.content_type
248 assert_equal 'image/png', @response.content_type
248 end
249 end
249
250
250 def test_directory_entry
251 def test_directory_entry
251 get :entry, :id => PRJ_ID, :path => ['sources']
252 get :entry, :id => PRJ_ID, :path => ['sources']
252 assert_response :success
253 assert_response :success
253 assert_template 'show'
254 assert_template 'show'
254 assert_not_nil assigns(:entry)
255 assert_not_nil assigns(:entry)
255 assert_equal 'sources', assigns(:entry).name
256 assert_equal 'sources', assigns(:entry).name
256 end
257 end
257
258
258 def test_diff
259 def test_diff
259 @repository.fetch_changesets
260 @repository.fetch_changesets
260 @repository.reload
261 @repository.reload
261 [4, '4', 'def6d2f1254a'].each do |r1|
262 [4, '4', 'def6d2f1254a'].each do |r1|
262 # Full diff of changeset 4
263 # Full diff of changeset 4
263 ['inline', 'sbs'].each do |dt|
264 ['inline', 'sbs'].each do |dt|
264 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
265 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
265 assert_response :success
266 assert_response :success
266 assert_template 'diff'
267 assert_template 'diff'
267 if @diff_c_support
268 if @diff_c_support
268 # Line 22 removed
269 # Line 22 removed
269 assert_tag :tag => 'th',
270 assert_tag :tag => 'th',
270 :content => '22',
271 :content => '22',
271 :sibling => { :tag => 'td',
272 :sibling => { :tag => 'td',
272 :attributes => { :class => /diff_out/ },
273 :attributes => { :class => /diff_out/ },
273 :content => /def remove/ }
274 :content => /def remove/ }
274 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
275 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
275 end
276 end
276 end
277 end
277 end
278 end
278 end
279 end
279
280
280 def test_diff_two_revs
281 def test_diff_two_revs
281 @repository.fetch_changesets
282 @repository.fetch_changesets
282 @repository.reload
283 @repository.reload
283 [2, '400bb8672109', '400', 400].each do |r1|
284 [2, '400bb8672109', '400', 400].each do |r1|
284 [4, 'def6d2f1254a'].each do |r2|
285 [4, 'def6d2f1254a'].each do |r2|
285 ['inline', 'sbs'].each do |dt|
286 ['inline', 'sbs'].each do |dt|
286 get :diff,
287 get :diff,
287 :id => PRJ_ID,
288 :id => PRJ_ID,
288 :rev => r1,
289 :rev => r1,
289 :rev_to => r2,
290 :rev_to => r2,
290 :type => dt
291 :type => dt
291 assert_response :success
292 assert_response :success
292 assert_template 'diff'
293 assert_template 'diff'
293 diff = assigns(:diff)
294 diff = assigns(:diff)
294 assert_not_nil diff
295 assert_not_nil diff
295 assert_tag :tag => 'h2',
296 assert_tag :tag => 'h2',
296 :content => /4:def6d2f1254a 2:400bb8672109/
297 :content => /4:def6d2f1254a 2:400bb8672109/
297 end
298 end
298 end
299 end
299 end
300 end
300 end
301 end
301
302
302 def test_diff_latin_1_path
303 def test_diff_latin_1_path
303 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
304 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
304 [21, 'adf805632193'].each do |r1|
305 [21, 'adf805632193'].each do |r1|
305 ['inline', 'sbs'].each do |dt|
306 ['inline', 'sbs'].each do |dt|
306 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
307 get :diff, :id => PRJ_ID, :rev => r1, :type => dt
307 assert_response :success
308 assert_response :success
308 assert_template 'diff'
309 assert_template 'diff'
309 assert_tag :tag => 'thead',
310 assert_tag :tag => 'thead',
310 :descendant => {
311 :descendant => {
311 :tag => 'th',
312 :tag => 'th',
312 :attributes => { :class => 'filename' } ,
313 :attributes => { :class => 'filename' } ,
313 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
314 :content => /latin-1-dir\/test-#{@char_1}-2.txt/ ,
314 },
315 },
315 :sibling => {
316 :sibling => {
316 :tag => 'tbody',
317 :tag => 'tbody',
317 :descendant => {
318 :descendant => {
318 :tag => 'td',
319 :tag => 'td',
319 :attributes => { :class => /diff_in/ },
320 :attributes => { :class => /diff_in/ },
320 :content => /It is written in Python/
321 :content => /It is written in Python/
321 }
322 }
322 }
323 }
323 end
324 end
324 end
325 end
325 end
326 end
326 end
327 end
327
328
328 def test_annotate
329 def test_annotate
329 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
330 get :annotate, :id => PRJ_ID, :path => ['sources', 'watchers_controller.rb']
330 assert_response :success
331 assert_response :success
331 assert_template 'annotate'
332 assert_template 'annotate'
332 # Line 23, revision 4:def6d2f1254a
333 # Line 23, revision 4:def6d2f1254a
333 assert_tag :tag => 'th',
334 assert_tag :tag => 'th',
334 :content => '23',
335 :content => '23',
335 :attributes => { :class => 'line-num' },
336 :attributes => { :class => 'line-num' },
336 :sibling =>
337 :sibling =>
337 {
338 {
338 :tag => 'td',
339 :tag => 'td',
339 :attributes => { :class => 'revision' },
340 :attributes => { :class => 'revision' },
340 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
341 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
341 }
342 }
342 assert_tag :tag => 'th',
343 assert_tag :tag => 'th',
343 :content => '23',
344 :content => '23',
344 :attributes => { :class => 'line-num' },
345 :attributes => { :class => 'line-num' },
345 :sibling =>
346 :sibling =>
346 {
347 {
347 :tag => 'td' ,
348 :tag => 'td' ,
348 :content => 'jsmith' ,
349 :content => 'jsmith' ,
349 :attributes => { :class => 'author' },
350 :attributes => { :class => 'author' },
350 }
351 }
351 assert_tag :tag => 'th',
352 assert_tag :tag => 'th',
352 :content => '23',
353 :content => '23',
353 :attributes => { :class => 'line-num' },
354 :attributes => { :class => 'line-num' },
354 :sibling => { :tag => 'td', :content => /watcher =/ }
355 :sibling => { :tag => 'td', :content => /watcher =/ }
355 end
356 end
356
357
357 def test_annotate_not_in_tip
358 def test_annotate_not_in_tip
358 @repository.fetch_changesets
359 @repository.fetch_changesets
359 @repository.reload
360 @repository.reload
360 assert @repository.changesets.size > 0
361 assert @repository.changesets.size > 0
361
362
362 get :annotate, :id => PRJ_ID,
363 get :annotate, :id => PRJ_ID,
363 :path => ['sources', 'welcome_controller.rb']
364 :path => ['sources', 'welcome_controller.rb']
364 assert_response 404
365 assert_response 404
365 assert_error_tag :content => /was not found/
366 assert_error_tag :content => /was not found/
366 end
367 end
367
368
368 def test_annotate_at_given_revision
369 def test_annotate_at_given_revision
369 @repository.fetch_changesets
370 @repository.fetch_changesets
370 @repository.reload
371 @repository.reload
371 [2, '400bb8672109', '400', 400].each do |r1|
372 [2, '400bb8672109', '400', 400].each do |r1|
372 get :annotate, :id => PRJ_ID, :rev => r1,
373 get :annotate, :id => PRJ_ID, :rev => r1,
373 :path => ['sources', 'watchers_controller.rb']
374 :path => ['sources', 'watchers_controller.rb']
374 assert_response :success
375 assert_response :success
375 assert_template 'annotate'
376 assert_template 'annotate'
376 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
377 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
377 end
378 end
378 end
379 end
379
380
380 def test_annotate_latin_1_path
381 def test_annotate_latin_1_path
381 [21, '21', 'adf805632193'].each do |r1|
382 [21, '21', 'adf805632193'].each do |r1|
382 get :annotate, :id => PRJ_ID,
383 get :annotate, :id => PRJ_ID,
383 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
384 :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
384 assert_response :success
385 assert_response :success
385 assert_template 'annotate'
386 assert_template 'annotate'
386 assert_tag :tag => 'th',
387 assert_tag :tag => 'th',
387 :content => '1',
388 :content => '1',
388 :attributes => { :class => 'line-num' },
389 :attributes => { :class => 'line-num' },
389 :sibling =>
390 :sibling =>
390 {
391 {
391 :tag => 'td',
392 :tag => 'td',
392 :attributes => { :class => 'revision' },
393 :attributes => { :class => 'revision' },
393 :child => { :tag => 'a', :content => '20:709858aafd1b' }
394 :child => { :tag => 'a', :content => '20:709858aafd1b' }
394 }
395 }
395 assert_tag :tag => 'th',
396 assert_tag :tag => 'th',
396 :content => '1',
397 :content => '1',
397 :attributes => { :class => 'line-num' },
398 :attributes => { :class => 'line-num' },
398 :sibling =>
399 :sibling =>
399 {
400 {
400 :tag => 'td' ,
401 :tag => 'td' ,
401 :content => 'jsmith' ,
402 :content => 'jsmith' ,
402 :attributes => { :class => 'author' },
403 :attributes => { :class => 'author' },
403 }
404 }
404 assert_tag :tag => 'th',
405 assert_tag :tag => 'th',
405 :content => '1',
406 :content => '1',
406 :attributes => { :class => 'line-num' },
407 :attributes => { :class => 'line-num' },
407 :sibling => { :tag => 'td',
408 :sibling => { :tag => 'td',
408 :content => /Mercurial is a distributed version control system/ }
409 :content => /Mercurial is a distributed version control system/ }
409
410
410 end
411 end
411 end
412 end
412
413
413 def test_annotate_latin_1_contents
414 def test_annotate_latin_1_contents
414 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
415 with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do
415 [27, '7bbf4c738e71'].each do |r1|
416 [27, '7bbf4c738e71'].each do |r1|
416 get :annotate, :id => PRJ_ID,
417 get :annotate, :id => PRJ_ID,
417 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
418 :path => ['latin-1-dir', "test-#{@char_1}.txt"], :rev => r1
418 assert_tag :tag => 'th',
419 assert_tag :tag => 'th',
419 :content => '1',
420 :content => '1',
420 :attributes => { :class => 'line-num' },
421 :attributes => { :class => 'line-num' },
421 :sibling => { :tag => 'td',
422 :sibling => { :tag => 'td',
422 :content => /test-#{@char_1}.txt/ }
423 :content => /test-#{@char_1}.txt/ }
423 end
424 end
424 end
425 end
425 end
426 end
426
427
427 def test_empty_revision
428 def test_empty_revision
428 @repository.fetch_changesets
429 @repository.fetch_changesets
429 @repository.reload
430 @repository.reload
430 ['', ' ', nil].each do |r|
431 ['', ' ', nil].each do |r|
431 get :revision, :id => PRJ_ID, :rev => r
432 get :revision, :id => PRJ_ID, :rev => r
432 assert_response 404
433 assert_response 404
433 assert_error_tag :content => /was not found/
434 assert_error_tag :content => /was not found/
434 end
435 end
435 end
436 end
436
437
437 def test_destroy_valid_repository
438 def test_destroy_valid_repository
438 @request.session[:user_id] = 1 # admin
439 @request.session[:user_id] = 1 # admin
439 @repository.fetch_changesets
440 @repository.fetch_changesets
440 @repository.reload
441 @repository.reload
441 assert @repository.changesets.count > 0
442 assert @repository.changesets.count > 0
442
443
443 get :destroy, :id => PRJ_ID
444 get :destroy, :id => PRJ_ID
444 assert_response 302
445 assert_response 302
445 @project.reload
446 @project.reload
446 assert_nil @project.repository
447 assert_nil @project.repository
447 end
448 end
448
449
449 def test_destroy_invalid_repository
450 def test_destroy_invalid_repository
450 @request.session[:user_id] = 1 # admin
451 @request.session[:user_id] = 1 # admin
451 @repository.fetch_changesets
452 @repository.fetch_changesets
452 @repository.reload
453 @repository.reload
453 assert @repository.changesets.count > 0
454 assert @repository.changesets.count > 0
454
455
455 get :destroy, :id => PRJ_ID
456 get :destroy, :id => PRJ_ID
456 assert_response 302
457 assert_response 302
457 @project.reload
458 @project.reload
458 assert_nil @project.repository
459 assert_nil @project.repository
459
460
460 @repository = Repository::Mercurial.create(
461 @repository = Repository::Mercurial.create(
461 :project => Project.find(PRJ_ID),
462 :project => Project.find(PRJ_ID),
462 :url => "/invalid",
463 :url => "/invalid",
463 :path_encoding => 'ISO-8859-1'
464 :path_encoding => 'ISO-8859-1'
464 )
465 )
465 assert @repository
466 assert @repository
466 @repository.fetch_changesets
467 @repository.fetch_changesets
467 @repository.reload
468 @repository.reload
468 assert_equal 0, @repository.changesets.count
469 assert_equal 0, @repository.changesets.count
469
470
470 get :destroy, :id => PRJ_ID
471 get :destroy, :id => PRJ_ID
471 assert_response 302
472 assert_response 302
472 @project.reload
473 @project.reload
473 assert_nil @project.repository
474 assert_nil @project.repository
474 end
475 end
475 else
476 else
476 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
477 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
477 def test_fake; assert true end
478 def test_fake; assert true end
478 end
479 end
479 end
480 end
General Comments 0
You need to be logged in to leave comments. Login now