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