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