##// END OF EJS Templates
scm: mercurial: prepare tests of named branch and tag in functional test (#1981, #7246)....
Toshi MARUYAMA -
r4998:f3822e18bd60
parent child
Show More
@@ -1,316 +1,322
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2008 Jean-Philippe Lang
2 # Copyright (C) 2006-2008 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, :repositories, :enabled_modules
25 fixtures :projects, :users, :roles, :members, :member_roles, :repositories, :enabled_modules
26
26
27 # No '..' in the repository path
27 # No '..' in the repository path
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
28 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
29 CHAR_1_HEX = "\xc3\x9c"
29 CHAR_1_HEX = "\xc3\x9c"
30
30
31 ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
31 ruby19_non_utf8_pass = (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8')
32
32
33 def setup
33 def setup
34 @controller = RepositoriesController.new
34 @controller = RepositoriesController.new
35 @request = ActionController::TestRequest.new
35 @request = ActionController::TestRequest.new
36 @response = ActionController::TestResponse.new
36 @response = ActionController::TestResponse.new
37 User.current = nil
37 User.current = nil
38 @repository = Repository::Mercurial.create(
38 @repository = Repository::Mercurial.create(
39 :project => Project.find(3),
39 :project => Project.find(3),
40 :url => REPOSITORY_PATH,
40 :url => REPOSITORY_PATH,
41 :path_encoding => 'ISO-8859-1'
41 :path_encoding => 'ISO-8859-1'
42 )
42 )
43 assert @repository
43 assert @repository
44 @diff_c_support = true
44 @diff_c_support = true
45 @char_1 = CHAR_1_HEX.dup
45 @char_1 = CHAR_1_HEX.dup
46 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
47 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
48 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
46 if @char_1.respond_to?(:force_encoding)
49 if @char_1.respond_to?(:force_encoding)
47 @char_1.force_encoding('UTF-8')
50 @char_1.force_encoding('UTF-8')
51 @tag_char_1.force_encoding('UTF-8')
52 @branch_char_0.force_encoding('UTF-8')
53 @branch_char_1.force_encoding('UTF-8')
48 end
54 end
49 end
55 end
50
56
51 if ruby19_non_utf8_pass
57 if ruby19_non_utf8_pass
52 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
58 puts "TODO: Mercurial functional test fails in Ruby 1.9 " +
53 "and Encoding.default_external is not UTF-8. " +
59 "and Encoding.default_external is not UTF-8. " +
54 "Current value is '#{Encoding.default_external.to_s}'"
60 "Current value is '#{Encoding.default_external.to_s}'"
55 def test_fake; assert true end
61 def test_fake; assert true end
56 elsif File.directory?(REPOSITORY_PATH)
62 elsif File.directory?(REPOSITORY_PATH)
57 def test_show
63 def test_show
58 get :show, :id => 3
64 get :show, :id => 3
59 assert_response :success
65 assert_response :success
60 assert_template 'show'
66 assert_template 'show'
61 assert_not_nil assigns(:entries)
67 assert_not_nil assigns(:entries)
62 assert_not_nil assigns(:changesets)
68 assert_not_nil assigns(:changesets)
63 end
69 end
64
70
65 def test_show_root
71 def test_show_root
66 get :show, :id => 3
72 get :show, :id => 3
67 assert_response :success
73 assert_response :success
68 assert_template 'show'
74 assert_template 'show'
69 assert_not_nil assigns(:entries)
75 assert_not_nil assigns(:entries)
70 assert_equal 4, assigns(:entries).size
76 assert_equal 4, assigns(:entries).size
71 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
77 assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'}
72 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
78 assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'}
73 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
79 assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'}
74 end
80 end
75
81
76 def test_show_directory
82 def test_show_directory
77 get :show, :id => 3, :path => ['images']
83 get :show, :id => 3, :path => ['images']
78 assert_response :success
84 assert_response :success
79 assert_template 'show'
85 assert_template 'show'
80 assert_not_nil assigns(:entries)
86 assert_not_nil assigns(:entries)
81 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
87 assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name)
82 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
88 entry = assigns(:entries).detect {|e| e.name == 'edit.png'}
83 assert_not_nil entry
89 assert_not_nil entry
84 assert_equal 'file', entry.kind
90 assert_equal 'file', entry.kind
85 assert_equal 'images/edit.png', entry.path
91 assert_equal 'images/edit.png', entry.path
86 end
92 end
87
93
88 def test_show_at_given_revision
94 def test_show_at_given_revision
89 [0, '0', '0885933ad4f6'].each do |r1|
95 [0, '0', '0885933ad4f6'].each do |r1|
90 get :show, :id => 3, :path => ['images'], :rev => r1
96 get :show, :id => 3, :path => ['images'], :rev => r1
91 assert_response :success
97 assert_response :success
92 assert_template 'show'
98 assert_template 'show'
93 assert_not_nil assigns(:entries)
99 assert_not_nil assigns(:entries)
94 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
100 assert_equal ['delete.png'], assigns(:entries).collect(&:name)
95 end
101 end
96 end
102 end
97
103
98 def test_show_directory_sql_escape_percent
104 def test_show_directory_sql_escape_percent
99 [13, '13', '3a330eb32958'].each do |r1|
105 [13, '13', '3a330eb32958'].each do |r1|
100 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
106 get :show, :id => 3, :path => ['sql_escape', 'percent%dir'], :rev => r1
101 assert_response :success
107 assert_response :success
102 assert_template 'show'
108 assert_template 'show'
103
109
104 assert_not_nil assigns(:entries)
110 assert_not_nil assigns(:entries)
105 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
111 assert_equal ['percent%file1.txt', 'percentfile1.txt'], assigns(:entries).collect(&:name)
106 changesets = assigns(:changesets)
112 changesets = assigns(:changesets)
107
113
108 ## This is not yet implemented.
114 ## This is not yet implemented.
109 # assert_not_nil changesets
115 # assert_not_nil changesets
110 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
116 # assert_equal %w(13 11 10 9), changesets.collect(&:revision)
111 end
117 end
112 end
118 end
113
119
114 def test_show_directory_latin_1
120 def test_show_directory_latin_1
115 @repository.fetch_changesets
121 @repository.fetch_changesets
116 @repository.reload
122 @repository.reload
117 [21, '21', 'adf805632193'].each do |r1|
123 [21, '21', 'adf805632193'].each do |r1|
118 get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1
124 get :show, :id => 3, :path => ['latin-1-dir'], :rev => r1
119 assert_response :success
125 assert_response :success
120 assert_template 'show'
126 assert_template 'show'
121
127
122 assert_not_nil assigns(:entries)
128 assert_not_nil assigns(:entries)
123 assert_equal ["make-latin-1-file.rb",
129 assert_equal ["make-latin-1-file.rb",
124 "test-#{@char_1}-1.txt",
130 "test-#{@char_1}-1.txt",
125 "test-#{@char_1}-2.txt",
131 "test-#{@char_1}-2.txt",
126 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
132 "test-#{@char_1}.txt"], assigns(:entries).collect(&:name)
127 changesets = assigns(:changesets)
133 changesets = assigns(:changesets)
128 assert_not_nil changesets
134 assert_not_nil changesets
129 assert_equal %w(27 21 20 19 18 17), changesets.collect(&:revision)
135 assert_equal %w(27 21 20 19 18 17), changesets.collect(&:revision)
130 end
136 end
131 end
137 end
132
138
133 def test_changes
139 def test_changes
134 get :changes, :id => 3, :path => ['images', 'edit.png']
140 get :changes, :id => 3, :path => ['images', 'edit.png']
135 assert_response :success
141 assert_response :success
136 assert_template 'changes'
142 assert_template 'changes'
137 assert_tag :tag => 'h2', :content => 'edit.png'
143 assert_tag :tag => 'h2', :content => 'edit.png'
138 end
144 end
139
145
140 def test_entry_show
146 def test_entry_show
141 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
147 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb']
142 assert_response :success
148 assert_response :success
143 assert_template 'entry'
149 assert_template 'entry'
144 # Line 10
150 # Line 10
145 assert_tag :tag => 'th',
151 assert_tag :tag => 'th',
146 :content => '10',
152 :content => '10',
147 :attributes => { :class => 'line-num' },
153 :attributes => { :class => 'line-num' },
148 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
154 :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ }
149 end
155 end
150
156
151 def test_entry_show_latin_1
157 def test_entry_show_latin_1
152 [21, '21', 'adf805632193'].each do |r1|
158 [21, '21', 'adf805632193'].each do |r1|
153 get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
159 get :entry, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
154 assert_response :success
160 assert_response :success
155 assert_template 'entry'
161 assert_template 'entry'
156 assert_tag :tag => 'th',
162 assert_tag :tag => 'th',
157 :content => '1',
163 :content => '1',
158 :attributes => { :class => 'line-num' },
164 :attributes => { :class => 'line-num' },
159 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
165 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
160 end
166 end
161 end
167 end
162
168
163 def test_entry_download
169 def test_entry_download
164 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
170 get :entry, :id => 3, :path => ['sources', 'watchers_controller.rb'], :format => 'raw'
165 assert_response :success
171 assert_response :success
166 # File content
172 # File content
167 assert @response.body.include?('WITHOUT ANY WARRANTY')
173 assert @response.body.include?('WITHOUT ANY WARRANTY')
168 end
174 end
169
175
170 def test_directory_entry
176 def test_directory_entry
171 get :entry, :id => 3, :path => ['sources']
177 get :entry, :id => 3, :path => ['sources']
172 assert_response :success
178 assert_response :success
173 assert_template 'show'
179 assert_template 'show'
174 assert_not_nil assigns(:entry)
180 assert_not_nil assigns(:entry)
175 assert_equal 'sources', assigns(:entry).name
181 assert_equal 'sources', assigns(:entry).name
176 end
182 end
177
183
178 def test_diff
184 def test_diff
179 @repository.fetch_changesets
185 @repository.fetch_changesets
180 @repository.reload
186 @repository.reload
181
187
182 [4, '4', 'def6d2f1254a'].each do |r1|
188 [4, '4', 'def6d2f1254a'].each do |r1|
183 # Full diff of changeset 4
189 # Full diff of changeset 4
184 get :diff, :id => 3, :rev => r1
190 get :diff, :id => 3, :rev => r1
185 assert_response :success
191 assert_response :success
186 assert_template 'diff'
192 assert_template 'diff'
187
193
188 if @diff_c_support
194 if @diff_c_support
189 # Line 22 removed
195 # Line 22 removed
190 assert_tag :tag => 'th',
196 assert_tag :tag => 'th',
191 :content => '22',
197 :content => '22',
192 :sibling => { :tag => 'td',
198 :sibling => { :tag => 'td',
193 :attributes => { :class => /diff_out/ },
199 :attributes => { :class => /diff_out/ },
194 :content => /def remove/ }
200 :content => /def remove/ }
195 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
201 assert_tag :tag => 'h2', :content => /4:def6d2f1254a/
196 end
202 end
197 end
203 end
198 end
204 end
199
205
200 def test_diff_two_revs
206 def test_diff_two_revs
201 @repository.fetch_changesets
207 @repository.fetch_changesets
202 @repository.reload
208 @repository.reload
203
209
204 [2, '400bb8672109', '400', 400].each do |r1|
210 [2, '400bb8672109', '400', 400].each do |r1|
205 [4, 'def6d2f1254a'].each do |r2|
211 [4, 'def6d2f1254a'].each do |r2|
206 get :diff, :id => 3, :rev => r1,
212 get :diff, :id => 3, :rev => r1,
207 :rev_to => r2
213 :rev_to => r2
208 assert_response :success
214 assert_response :success
209 assert_template 'diff'
215 assert_template 'diff'
210
216
211 diff = assigns(:diff)
217 diff = assigns(:diff)
212 assert_not_nil diff
218 assert_not_nil diff
213 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
219 assert_tag :tag => 'h2', :content => /4:def6d2f1254a 2:400bb8672109/
214 end
220 end
215 end
221 end
216 end
222 end
217
223
218 def test_diff_latin_1
224 def test_diff_latin_1
219 [21, 'adf805632193'].each do |r1|
225 [21, 'adf805632193'].each do |r1|
220 get :diff, :id => 3, :rev => r1
226 get :diff, :id => 3, :rev => r1
221 assert_response :success
227 assert_response :success
222 assert_template 'diff'
228 assert_template 'diff'
223 assert_tag :tag => 'th',
229 assert_tag :tag => 'th',
224 :content => '2',
230 :content => '2',
225 :sibling => { :tag => 'td',
231 :sibling => { :tag => 'td',
226 :attributes => { :class => /diff_in/ },
232 :attributes => { :class => /diff_in/ },
227 :content => /It is written in Python/ }
233 :content => /It is written in Python/ }
228 end
234 end
229 end
235 end
230
236
231 def test_annotate
237 def test_annotate
232 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
238 get :annotate, :id => 3, :path => ['sources', 'watchers_controller.rb']
233 assert_response :success
239 assert_response :success
234 assert_template 'annotate'
240 assert_template 'annotate'
235 # Line 23, revision 4:def6d2f1254a
241 # Line 23, revision 4:def6d2f1254a
236 assert_tag :tag => 'th',
242 assert_tag :tag => 'th',
237 :content => '23',
243 :content => '23',
238 :attributes => { :class => 'line-num' },
244 :attributes => { :class => 'line-num' },
239 :sibling =>
245 :sibling =>
240 {
246 {
241 :tag => 'td',
247 :tag => 'td',
242 :attributes => { :class => 'revision' },
248 :attributes => { :class => 'revision' },
243 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
249 :child => { :tag => 'a', :content => '4:def6d2f1254a' }
244 }
250 }
245 assert_tag :tag => 'th',
251 assert_tag :tag => 'th',
246 :content => '23',
252 :content => '23',
247 :attributes => { :class => 'line-num' },
253 :attributes => { :class => 'line-num' },
248 :sibling =>
254 :sibling =>
249 {
255 {
250 :tag => 'td' ,
256 :tag => 'td' ,
251 :content => 'jsmith' ,
257 :content => 'jsmith' ,
252 :attributes => { :class => 'author' },
258 :attributes => { :class => 'author' },
253 }
259 }
254 assert_tag :tag => 'th',
260 assert_tag :tag => 'th',
255 :content => '23',
261 :content => '23',
256 :attributes => { :class => 'line-num' },
262 :attributes => { :class => 'line-num' },
257 :sibling => { :tag => 'td', :content => /watcher =/ }
263 :sibling => { :tag => 'td', :content => /watcher =/ }
258 end
264 end
259
265
260 def test_annotate_at_given_revision
266 def test_annotate_at_given_revision
261 @repository.fetch_changesets
267 @repository.fetch_changesets
262 @repository.reload
268 @repository.reload
263 [2, '400bb8672109', '400', 400].each do |r1|
269 [2, '400bb8672109', '400', 400].each do |r1|
264 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
270 get :annotate, :id => 3, :rev => r1, :path => ['sources', 'watchers_controller.rb']
265 assert_response :success
271 assert_response :success
266 assert_template 'annotate'
272 assert_template 'annotate'
267 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
273 assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/
268 end
274 end
269 end
275 end
270
276
271 def test_annotate_latin_1
277 def test_annotate_latin_1
272 [21, '21', 'adf805632193'].each do |r1|
278 [21, '21', 'adf805632193'].each do |r1|
273 get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
279 get :annotate, :id => 3, :path => ['latin-1-dir', "test-#{@char_1}-2.txt"], :rev => r1
274 assert_response :success
280 assert_response :success
275 assert_template 'annotate'
281 assert_template 'annotate'
276 assert_tag :tag => 'th',
282 assert_tag :tag => 'th',
277 :content => '1',
283 :content => '1',
278 :attributes => { :class => 'line-num' },
284 :attributes => { :class => 'line-num' },
279 :sibling =>
285 :sibling =>
280 {
286 {
281 :tag => 'td',
287 :tag => 'td',
282 :attributes => { :class => 'revision' },
288 :attributes => { :class => 'revision' },
283 :child => { :tag => 'a', :content => '20:709858aafd1b' }
289 :child => { :tag => 'a', :content => '20:709858aafd1b' }
284 }
290 }
285 assert_tag :tag => 'th',
291 assert_tag :tag => 'th',
286 :content => '1',
292 :content => '1',
287 :attributes => { :class => 'line-num' },
293 :attributes => { :class => 'line-num' },
288 :sibling =>
294 :sibling =>
289 {
295 {
290 :tag => 'td' ,
296 :tag => 'td' ,
291 :content => 'jsmith' ,
297 :content => 'jsmith' ,
292 :attributes => { :class => 'author' },
298 :attributes => { :class => 'author' },
293
299
294 }
300 }
295 assert_tag :tag => 'th',
301 assert_tag :tag => 'th',
296 :content => '1',
302 :content => '1',
297 :attributes => { :class => 'line-num' },
303 :attributes => { :class => 'line-num' },
298 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
304 :sibling => { :tag => 'td', :content => /Mercurial is a distributed version control system/ }
299
305
300 end
306 end
301 end
307 end
302
308
303 def test_empty_revision
309 def test_empty_revision
304 @repository.fetch_changesets
310 @repository.fetch_changesets
305 @repository.reload
311 @repository.reload
306 ['', ' ', nil].each do |r|
312 ['', ' ', nil].each do |r|
307 get :revision, :id => 3, :rev => r
313 get :revision, :id => 3, :rev => r
308 assert_response 404
314 assert_response 404
309 assert_error_tag :content => /was not found/
315 assert_error_tag :content => /was not found/
310 end
316 end
311 end
317 end
312 else
318 else
313 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
319 puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!"
314 def test_fake; assert true end
320 def test_fake; assert true end
315 end
321 end
316 end
322 end
General Comments 0
You need to be logged in to leave comments. Login now