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