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