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