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