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