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