|
1 | NO CONTENT: modified file, binary diff hidden |
@@ -1,526 +1,526 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 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 | |
|
20 | 20 | class RepositoriesMercurialControllerTest < ActionController::TestCase |
|
21 | 21 | tests RepositoriesController |
|
22 | 22 | |
|
23 | 23 | fixtures :projects, :users, :roles, :members, :member_roles, |
|
24 | 24 | :repositories, :enabled_modules |
|
25 | 25 | |
|
26 | 26 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
27 | 27 | CHAR_1_HEX = "\xc3\x9c" |
|
28 | 28 | PRJ_ID = 3 |
|
29 |
NUM_REV = 3 |
|
|
29 | NUM_REV = 34 | |
|
30 | 30 | |
|
31 | 31 | ruby19_non_utf8_pass = |
|
32 | 32 | (RUBY_VERSION >= '1.9' && Encoding.default_external.to_s != 'UTF-8') |
|
33 | 33 | |
|
34 | 34 | def setup |
|
35 | 35 | User.current = nil |
|
36 | 36 | @project = Project.find(PRJ_ID) |
|
37 | 37 | @repository = Repository::Mercurial.create( |
|
38 | 38 | :project => @project, |
|
39 | 39 | :url => REPOSITORY_PATH, |
|
40 | 40 | :path_encoding => 'ISO-8859-1' |
|
41 | 41 | ) |
|
42 | 42 | assert @repository |
|
43 | 43 | @diff_c_support = true |
|
44 | 44 | @char_1 = CHAR_1_HEX.dup |
|
45 | 45 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
46 | 46 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
47 | 47 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
48 | 48 | if @char_1.respond_to?(:force_encoding) |
|
49 | 49 | @char_1.force_encoding('UTF-8') |
|
50 | 50 | @tag_char_1.force_encoding('UTF-8') |
|
51 | 51 | @branch_char_0.force_encoding('UTF-8') |
|
52 | 52 | @branch_char_1.force_encoding('UTF-8') |
|
53 | 53 | end |
|
54 | 54 | end |
|
55 | 55 | |
|
56 | 56 | if ruby19_non_utf8_pass |
|
57 | 57 | puts "TODO: Mercurial functional test fails in Ruby 1.9 " + |
|
58 | 58 | "and Encoding.default_external is not UTF-8. " + |
|
59 | 59 | "Current value is '#{Encoding.default_external.to_s}'" |
|
60 | 60 | def test_fake; assert true end |
|
61 | 61 | elsif File.directory?(REPOSITORY_PATH) |
|
62 | 62 | |
|
63 | 63 | def test_get_new |
|
64 | 64 | @request.session[:user_id] = 1 |
|
65 | 65 | @project.repository.destroy |
|
66 | 66 | get :new, :project_id => 'subproject1', :repository_scm => 'Mercurial' |
|
67 | 67 | assert_response :success |
|
68 | 68 | assert_template 'new' |
|
69 | 69 | assert_kind_of Repository::Mercurial, assigns(:repository) |
|
70 | 70 | assert assigns(:repository).new_record? |
|
71 | 71 | end |
|
72 | 72 | |
|
73 | 73 | def test_show_root |
|
74 | 74 | assert_equal 0, @repository.changesets.count |
|
75 | 75 | @repository.fetch_changesets |
|
76 | 76 | @project.reload |
|
77 | 77 | assert_equal NUM_REV, @repository.changesets.count |
|
78 | 78 | get :show, :id => PRJ_ID |
|
79 | 79 | assert_response :success |
|
80 | 80 | assert_template 'show' |
|
81 | 81 | assert_not_nil assigns(:entries) |
|
82 | 82 | assert_equal 4, assigns(:entries).size |
|
83 | 83 | assert assigns(:entries).detect {|e| e.name == 'images' && e.kind == 'dir'} |
|
84 | 84 | assert assigns(:entries).detect {|e| e.name == 'sources' && e.kind == 'dir'} |
|
85 | 85 | assert assigns(:entries).detect {|e| e.name == 'README' && e.kind == 'file'} |
|
86 | 86 | assert_not_nil assigns(:changesets) |
|
87 | 87 | assert assigns(:changesets).size > 0 |
|
88 | 88 | end |
|
89 | 89 | |
|
90 | 90 | def test_show_directory |
|
91 | 91 | assert_equal 0, @repository.changesets.count |
|
92 | 92 | @repository.fetch_changesets |
|
93 | 93 | @project.reload |
|
94 | 94 | assert_equal NUM_REV, @repository.changesets.count |
|
95 | 95 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param] |
|
96 | 96 | assert_response :success |
|
97 | 97 | assert_template 'show' |
|
98 | 98 | assert_not_nil assigns(:entries) |
|
99 | 99 | assert_equal ['delete.png', 'edit.png'], assigns(:entries).collect(&:name) |
|
100 | 100 | entry = assigns(:entries).detect {|e| e.name == 'edit.png'} |
|
101 | 101 | assert_not_nil entry |
|
102 | 102 | assert_equal 'file', entry.kind |
|
103 | 103 | assert_equal 'images/edit.png', entry.path |
|
104 | 104 | assert_not_nil assigns(:changesets) |
|
105 | 105 | assert assigns(:changesets).size > 0 |
|
106 | 106 | end |
|
107 | 107 | |
|
108 | 108 | def test_show_at_given_revision |
|
109 | 109 | assert_equal 0, @repository.changesets.count |
|
110 | 110 | @repository.fetch_changesets |
|
111 | 111 | @project.reload |
|
112 | 112 | assert_equal NUM_REV, @repository.changesets.count |
|
113 | 113 | [0, '0', '0885933ad4f6'].each do |r1| |
|
114 | 114 | get :show, :id => PRJ_ID, :path => repository_path_hash(['images'])[:param], |
|
115 | 115 | :rev => r1 |
|
116 | 116 | assert_response :success |
|
117 | 117 | assert_template 'show' |
|
118 | 118 | assert_not_nil assigns(:entries) |
|
119 | 119 | assert_equal ['delete.png'], assigns(:entries).collect(&:name) |
|
120 | 120 | assert_not_nil assigns(:changesets) |
|
121 | 121 | assert assigns(:changesets).size > 0 |
|
122 | 122 | end |
|
123 | 123 | end |
|
124 | 124 | |
|
125 | 125 | def test_show_directory_sql_escape_percent |
|
126 | 126 | assert_equal 0, @repository.changesets.count |
|
127 | 127 | @repository.fetch_changesets |
|
128 | 128 | @project.reload |
|
129 | 129 | assert_equal NUM_REV, @repository.changesets.count |
|
130 | 130 | [13, '13', '3a330eb32958'].each do |r1| |
|
131 | 131 | get :show, :id => PRJ_ID, |
|
132 | 132 | :path => repository_path_hash(['sql_escape', 'percent%dir'])[:param], |
|
133 | 133 | :rev => r1 |
|
134 | 134 | assert_response :success |
|
135 | 135 | assert_template 'show' |
|
136 | 136 | |
|
137 | 137 | assert_not_nil assigns(:entries) |
|
138 | 138 | assert_equal ['percent%file1.txt', 'percentfile1.txt'], |
|
139 | 139 | assigns(:entries).collect(&:name) |
|
140 | 140 | changesets = assigns(:changesets) |
|
141 | 141 | assert_not_nil changesets |
|
142 | 142 | assert assigns(:changesets).size > 0 |
|
143 | 143 | assert_equal %w(13 11 10 9), changesets.collect(&:revision) |
|
144 | 144 | end |
|
145 | 145 | end |
|
146 | 146 | |
|
147 | 147 | def test_show_directory_latin_1_path |
|
148 | 148 | assert_equal 0, @repository.changesets.count |
|
149 | 149 | @repository.fetch_changesets |
|
150 | 150 | @project.reload |
|
151 | 151 | assert_equal NUM_REV, @repository.changesets.count |
|
152 | 152 | [21, '21', 'adf805632193'].each do |r1| |
|
153 | 153 | get :show, :id => PRJ_ID, |
|
154 | 154 | :path => repository_path_hash(['latin-1-dir'])[:param], |
|
155 | 155 | :rev => r1 |
|
156 | 156 | assert_response :success |
|
157 | 157 | assert_template 'show' |
|
158 | 158 | |
|
159 | 159 | assert_not_nil assigns(:entries) |
|
160 | 160 | assert_equal ["make-latin-1-file.rb", |
|
161 | 161 | "test-#{@char_1}-1.txt", |
|
162 | 162 | "test-#{@char_1}-2.txt", |
|
163 | 163 | "test-#{@char_1}.txt"], assigns(:entries).collect(&:name) |
|
164 | 164 | changesets = assigns(:changesets) |
|
165 | 165 | assert_not_nil changesets |
|
166 | 166 | assert_equal %w(21 20 19 18 17), changesets.collect(&:revision) |
|
167 | 167 | end |
|
168 | 168 | end |
|
169 | 169 | |
|
170 | 170 | def show_should_show_branch_selection_form |
|
171 | 171 | @repository.fetch_changesets |
|
172 | 172 | @project.reload |
|
173 | 173 | get :show, :id => PRJ_ID |
|
174 | 174 | assert_tag 'form', :attributes => {:id => 'revision_selector', :action => '/projects/subproject1/repository/show'} |
|
175 | 175 | assert_tag 'select', :attributes => {:name => 'branch'}, |
|
176 | 176 | :child => {:tag => 'option', :attributes => {:value => 'test-branch-01'}}, |
|
177 | 177 | :parent => {:tag => 'form', :attributes => {:id => 'revision_selector'}} |
|
178 | 178 | end |
|
179 | 179 | |
|
180 | 180 | def test_show_branch |
|
181 | 181 | assert_equal 0, @repository.changesets.count |
|
182 | 182 | @repository.fetch_changesets |
|
183 | 183 | @project.reload |
|
184 | 184 | assert_equal NUM_REV, @repository.changesets.count |
|
185 | 185 | [ |
|
186 | 186 | 'default', |
|
187 | 187 | @branch_char_1, |
|
188 | 188 | 'branch (1)[2]&,%.-3_4', |
|
189 | 189 | @branch_char_0, |
|
190 | 190 | 'test_branch.latin-1', |
|
191 | 191 | 'test-branch-00', |
|
192 | 192 | ].each do |bra| |
|
193 | 193 | get :show, :id => PRJ_ID, :rev => bra |
|
194 | 194 | assert_response :success |
|
195 | 195 | assert_template 'show' |
|
196 | 196 | assert_not_nil assigns(:entries) |
|
197 | 197 | assert assigns(:entries).size > 0 |
|
198 | 198 | assert_not_nil assigns(:changesets) |
|
199 | 199 | assert assigns(:changesets).size > 0 |
|
200 | 200 | end |
|
201 | 201 | end |
|
202 | 202 | |
|
203 | 203 | def test_show_tag |
|
204 | 204 | assert_equal 0, @repository.changesets.count |
|
205 | 205 | @repository.fetch_changesets |
|
206 | 206 | @project.reload |
|
207 | 207 | assert_equal NUM_REV, @repository.changesets.count |
|
208 | 208 | [ |
|
209 | 209 | @tag_char_1, |
|
210 | 210 | 'tag_test.00', |
|
211 | 211 | 'tag-init-revision' |
|
212 | 212 | ].each do |tag| |
|
213 | 213 | get :show, :id => PRJ_ID, :rev => tag |
|
214 | 214 | assert_response :success |
|
215 | 215 | assert_template 'show' |
|
216 | 216 | assert_not_nil assigns(:entries) |
|
217 | 217 | assert assigns(:entries).size > 0 |
|
218 | 218 | assert_not_nil assigns(:changesets) |
|
219 | 219 | assert assigns(:changesets).size > 0 |
|
220 | 220 | end |
|
221 | 221 | end |
|
222 | 222 | |
|
223 | 223 | def test_changes |
|
224 | 224 | get :changes, :id => PRJ_ID, |
|
225 | 225 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
226 | 226 | assert_response :success |
|
227 | 227 | assert_template 'changes' |
|
228 | 228 | assert_tag :tag => 'h2', :content => 'edit.png' |
|
229 | 229 | end |
|
230 | 230 | |
|
231 | 231 | def test_entry_show |
|
232 | 232 | get :entry, :id => PRJ_ID, |
|
233 | 233 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
234 | 234 | assert_response :success |
|
235 | 235 | assert_template 'entry' |
|
236 | 236 | # Line 10 |
|
237 | 237 | assert_tag :tag => 'th', |
|
238 | 238 | :content => '10', |
|
239 | 239 | :attributes => { :class => 'line-num' }, |
|
240 | 240 | :sibling => { :tag => 'td', :content => /WITHOUT ANY WARRANTY/ } |
|
241 | 241 | end |
|
242 | 242 | |
|
243 | 243 | def test_entry_show_latin_1_path |
|
244 | 244 | [21, '21', 'adf805632193'].each do |r1| |
|
245 | 245 | get :entry, :id => PRJ_ID, |
|
246 | 246 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], |
|
247 | 247 | :rev => r1 |
|
248 | 248 | assert_response :success |
|
249 | 249 | assert_template 'entry' |
|
250 | 250 | assert_tag :tag => 'th', |
|
251 | 251 | :content => '1', |
|
252 | 252 | :attributes => { :class => 'line-num' }, |
|
253 | 253 | :sibling => { :tag => 'td', |
|
254 | 254 | :content => /Mercurial is a distributed version control system/ } |
|
255 | 255 | end |
|
256 | 256 | end |
|
257 | 257 | |
|
258 | 258 | def test_entry_show_latin_1_contents |
|
259 | 259 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
260 | 260 | [27, '27', '7bbf4c738e71'].each do |r1| |
|
261 | 261 | get :entry, :id => PRJ_ID, |
|
262 | 262 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
263 | 263 | :rev => r1 |
|
264 | 264 | assert_response :success |
|
265 | 265 | assert_template 'entry' |
|
266 | 266 | assert_tag :tag => 'th', |
|
267 | 267 | :content => '1', |
|
268 | 268 | :attributes => { :class => 'line-num' }, |
|
269 | 269 | :sibling => { :tag => 'td', |
|
270 | 270 | :content => /test-#{@char_1}.txt/ } |
|
271 | 271 | end |
|
272 | 272 | end |
|
273 | 273 | end |
|
274 | 274 | |
|
275 | 275 | def test_entry_download |
|
276 | 276 | get :entry, :id => PRJ_ID, |
|
277 | 277 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param], |
|
278 | 278 | :format => 'raw' |
|
279 | 279 | assert_response :success |
|
280 | 280 | # File content |
|
281 | 281 | assert @response.body.include?('WITHOUT ANY WARRANTY') |
|
282 | 282 | end |
|
283 | 283 | |
|
284 | 284 | def test_entry_binary_force_download |
|
285 | 285 | get :entry, :id => PRJ_ID, :rev => 1, |
|
286 | 286 | :path => repository_path_hash(['images', 'edit.png'])[:param] |
|
287 | 287 | assert_response :success |
|
288 | 288 | assert_equal 'image/png', @response.content_type |
|
289 | 289 | end |
|
290 | 290 | |
|
291 | 291 | def test_directory_entry |
|
292 | 292 | get :entry, :id => PRJ_ID, |
|
293 | 293 | :path => repository_path_hash(['sources'])[:param] |
|
294 | 294 | assert_response :success |
|
295 | 295 | assert_template 'show' |
|
296 | 296 | assert_not_nil assigns(:entry) |
|
297 | 297 | assert_equal 'sources', assigns(:entry).name |
|
298 | 298 | end |
|
299 | 299 | |
|
300 | 300 | def test_diff |
|
301 | 301 | assert_equal 0, @repository.changesets.count |
|
302 | 302 | @repository.fetch_changesets |
|
303 | 303 | @project.reload |
|
304 | 304 | assert_equal NUM_REV, @repository.changesets.count |
|
305 | 305 | [4, '4', 'def6d2f1254a'].each do |r1| |
|
306 | 306 | # Full diff of changeset 4 |
|
307 | 307 | ['inline', 'sbs'].each do |dt| |
|
308 | 308 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
309 | 309 | assert_response :success |
|
310 | 310 | assert_template 'diff' |
|
311 | 311 | if @diff_c_support |
|
312 | 312 | # Line 22 removed |
|
313 | 313 | assert_tag :tag => 'th', |
|
314 | 314 | :content => '22', |
|
315 | 315 | :sibling => { :tag => 'td', |
|
316 | 316 | :attributes => { :class => /diff_out/ }, |
|
317 | 317 | :content => /def remove/ } |
|
318 | 318 | assert_tag :tag => 'h2', :content => /4:def6d2f1254a/ |
|
319 | 319 | end |
|
320 | 320 | end |
|
321 | 321 | end |
|
322 | 322 | end |
|
323 | 323 | |
|
324 | 324 | def test_diff_two_revs |
|
325 | 325 | assert_equal 0, @repository.changesets.count |
|
326 | 326 | @repository.fetch_changesets |
|
327 | 327 | @project.reload |
|
328 | 328 | assert_equal NUM_REV, @repository.changesets.count |
|
329 | 329 | [2, '400bb8672109', '400', 400].each do |r1| |
|
330 | 330 | [4, 'def6d2f1254a'].each do |r2| |
|
331 | 331 | ['inline', 'sbs'].each do |dt| |
|
332 | 332 | get :diff, |
|
333 | 333 | :id => PRJ_ID, |
|
334 | 334 | :rev => r1, |
|
335 | 335 | :rev_to => r2, |
|
336 | 336 | :type => dt |
|
337 | 337 | assert_response :success |
|
338 | 338 | assert_template 'diff' |
|
339 | 339 | diff = assigns(:diff) |
|
340 | 340 | assert_not_nil diff |
|
341 | 341 | assert_tag :tag => 'h2', |
|
342 | 342 | :content => /4:def6d2f1254a 2:400bb8672109/ |
|
343 | 343 | end |
|
344 | 344 | end |
|
345 | 345 | end |
|
346 | 346 | end |
|
347 | 347 | |
|
348 | 348 | def test_diff_latin_1_path |
|
349 | 349 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
350 | 350 | [21, 'adf805632193'].each do |r1| |
|
351 | 351 | ['inline', 'sbs'].each do |dt| |
|
352 | 352 | get :diff, :id => PRJ_ID, :rev => r1, :type => dt |
|
353 | 353 | assert_response :success |
|
354 | 354 | assert_template 'diff' |
|
355 | 355 | assert_tag :tag => 'thead', |
|
356 | 356 | :descendant => { |
|
357 | 357 | :tag => 'th', |
|
358 | 358 | :attributes => { :class => 'filename' } , |
|
359 | 359 | :content => /latin-1-dir\/test-#{@char_1}-2.txt/ , |
|
360 | 360 | }, |
|
361 | 361 | :sibling => { |
|
362 | 362 | :tag => 'tbody', |
|
363 | 363 | :descendant => { |
|
364 | 364 | :tag => 'td', |
|
365 | 365 | :attributes => { :class => /diff_in/ }, |
|
366 | 366 | :content => /It is written in Python/ |
|
367 | 367 | } |
|
368 | 368 | } |
|
369 | 369 | end |
|
370 | 370 | end |
|
371 | 371 | end |
|
372 | 372 | end |
|
373 | 373 | |
|
374 | 374 | def test_diff_should_show_modified_filenames |
|
375 | 375 | get :diff, :id => PRJ_ID, :rev => '400bb8672109', :type => 'inline' |
|
376 | 376 | assert_response :success |
|
377 | 377 | assert_template 'diff' |
|
378 | 378 | assert_select 'th.filename', :text => 'sources/watchers_controller.rb' |
|
379 | 379 | end |
|
380 | 380 | |
|
381 | 381 | def test_diff_should_show_deleted_filenames |
|
382 | 382 | get :diff, :id => PRJ_ID, :rev => 'b3a615152df8', :type => 'inline' |
|
383 | 383 | assert_response :success |
|
384 | 384 | assert_template 'diff' |
|
385 | 385 | assert_select 'th.filename', :text => 'sources/welcome_controller.rb' |
|
386 | 386 | end |
|
387 | 387 | |
|
388 | 388 | def test_annotate |
|
389 | 389 | get :annotate, :id => PRJ_ID, |
|
390 | 390 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
391 | 391 | assert_response :success |
|
392 | 392 | assert_template 'annotate' |
|
393 | 393 | |
|
394 | 394 | # Line 22, revision 4:def6d2f1254a |
|
395 | 395 | assert_select 'tr' do |
|
396 | 396 | assert_select 'th.line-num', :text => '22' |
|
397 | 397 | assert_select 'td.revision', :text => '4:def6d2f1254a' |
|
398 | 398 | assert_select 'td.author', :text => 'jsmith' |
|
399 | 399 | assert_select 'td', :text => /remove_watcher/ |
|
400 | 400 | end |
|
401 | 401 | end |
|
402 | 402 | |
|
403 | 403 | def test_annotate_not_in_tip |
|
404 | 404 | assert_equal 0, @repository.changesets.count |
|
405 | 405 | @repository.fetch_changesets |
|
406 | 406 | @project.reload |
|
407 | 407 | assert_equal NUM_REV, @repository.changesets.count |
|
408 | 408 | get :annotate, :id => PRJ_ID, |
|
409 | 409 | :path => repository_path_hash(['sources', 'welcome_controller.rb'])[:param] |
|
410 | 410 | assert_response 404 |
|
411 | 411 | assert_error_tag :content => /was not found/ |
|
412 | 412 | end |
|
413 | 413 | |
|
414 | 414 | def test_annotate_at_given_revision |
|
415 | 415 | assert_equal 0, @repository.changesets.count |
|
416 | 416 | @repository.fetch_changesets |
|
417 | 417 | @project.reload |
|
418 | 418 | assert_equal NUM_REV, @repository.changesets.count |
|
419 | 419 | [2, '400bb8672109', '400', 400].each do |r1| |
|
420 | 420 | get :annotate, :id => PRJ_ID, :rev => r1, |
|
421 | 421 | :path => repository_path_hash(['sources', 'watchers_controller.rb'])[:param] |
|
422 | 422 | assert_response :success |
|
423 | 423 | assert_template 'annotate' |
|
424 | 424 | assert_tag :tag => 'h2', :content => /@ 2:400bb8672109/ |
|
425 | 425 | end |
|
426 | 426 | end |
|
427 | 427 | |
|
428 | 428 | def test_annotate_latin_1_path |
|
429 | 429 | [21, '21', 'adf805632193'].each do |r1| |
|
430 | 430 | get :annotate, :id => PRJ_ID, |
|
431 | 431 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}-2.txt"])[:param], |
|
432 | 432 | :rev => r1 |
|
433 | 433 | assert_response :success |
|
434 | 434 | assert_template 'annotate' |
|
435 | 435 | assert_select "th.line-num", :text => '1' do |
|
436 | 436 | assert_select "+ td.revision" do |
|
437 | 437 | assert_select "a", :text => '20:709858aafd1b' |
|
438 | 438 | assert_select "+ td.author", :text => "jsmith" do |
|
439 | 439 | assert_select "+ td", |
|
440 | 440 | :text => "Mercurial is a distributed version control system." |
|
441 | 441 | end |
|
442 | 442 | end |
|
443 | 443 | end |
|
444 | 444 | end |
|
445 | 445 | end |
|
446 | 446 | |
|
447 | 447 | def test_annotate_latin_1_contents |
|
448 | 448 | with_settings :repositories_encodings => 'UTF-8,ISO-8859-1' do |
|
449 | 449 | [27, '7bbf4c738e71'].each do |r1| |
|
450 | 450 | get :annotate, :id => PRJ_ID, |
|
451 | 451 | :path => repository_path_hash(['latin-1-dir', "test-#{@char_1}.txt"])[:param], |
|
452 | 452 | :rev => r1 |
|
453 | 453 | assert_tag :tag => 'th', |
|
454 | 454 | :content => '1', |
|
455 | 455 | :attributes => { :class => 'line-num' }, |
|
456 | 456 | :sibling => { :tag => 'td', |
|
457 | 457 | :content => /test-#{@char_1}.txt/ } |
|
458 | 458 | end |
|
459 | 459 | end |
|
460 | 460 | end |
|
461 | 461 | |
|
462 | 462 | def test_revision |
|
463 | 463 | assert_equal 0, @repository.changesets.count |
|
464 | 464 | @repository.fetch_changesets |
|
465 | 465 | @project.reload |
|
466 | 466 | assert_equal NUM_REV, @repository.changesets.count |
|
467 | 467 | ['1', '9d5b5b', '9d5b5b004199'].each do |r| |
|
468 | 468 | with_settings :default_language => "en" do |
|
469 | 469 | get :revision, :id => PRJ_ID, :rev => r |
|
470 | 470 | assert_response :success |
|
471 | 471 | assert_template 'revision' |
|
472 | 472 | assert_select 'title', |
|
473 | 473 | :text => 'Revision 1:9d5b5b004199 - Added 2 files and modified one. - eCookbook Subproject 1 - Redmine' |
|
474 | 474 | end |
|
475 | 475 | end |
|
476 | 476 | end |
|
477 | 477 | |
|
478 | 478 | def test_empty_revision |
|
479 | 479 | assert_equal 0, @repository.changesets.count |
|
480 | 480 | @repository.fetch_changesets |
|
481 | 481 | @project.reload |
|
482 | 482 | assert_equal NUM_REV, @repository.changesets.count |
|
483 | 483 | ['', ' ', nil].each do |r| |
|
484 | 484 | get :revision, :id => PRJ_ID, :rev => r |
|
485 | 485 | assert_response 404 |
|
486 | 486 | assert_error_tag :content => /was not found/ |
|
487 | 487 | end |
|
488 | 488 | end |
|
489 | 489 | |
|
490 | 490 | def test_destroy_valid_repository |
|
491 | 491 | @request.session[:user_id] = 1 # admin |
|
492 | 492 | assert_equal 0, @repository.changesets.count |
|
493 | 493 | @repository.fetch_changesets |
|
494 | 494 | assert_equal NUM_REV, @repository.changesets.count |
|
495 | 495 | |
|
496 | 496 | assert_difference 'Repository.count', -1 do |
|
497 | 497 | delete :destroy, :id => @repository.id |
|
498 | 498 | end |
|
499 | 499 | assert_response 302 |
|
500 | 500 | @project.reload |
|
501 | 501 | assert_nil @project.repository |
|
502 | 502 | end |
|
503 | 503 | |
|
504 | 504 | def test_destroy_invalid_repository |
|
505 | 505 | @request.session[:user_id] = 1 # admin |
|
506 | 506 | @project.repository.destroy |
|
507 | 507 | @repository = Repository::Mercurial.create!( |
|
508 | 508 | :project => Project.find(PRJ_ID), |
|
509 | 509 | :url => "/invalid", |
|
510 | 510 | :path_encoding => 'ISO-8859-1' |
|
511 | 511 | ) |
|
512 | 512 | @repository.fetch_changesets |
|
513 | 513 | assert_equal 0, @repository.changesets.count |
|
514 | 514 | |
|
515 | 515 | assert_difference 'Repository.count', -1 do |
|
516 | 516 | delete :destroy, :id => @repository.id |
|
517 | 517 | end |
|
518 | 518 | assert_response 302 |
|
519 | 519 | @project.reload |
|
520 | 520 | assert_nil @project.repository |
|
521 | 521 | end |
|
522 | 522 | else |
|
523 | 523 | puts "Mercurial test repository NOT FOUND. Skipping functional tests !!!" |
|
524 | 524 | def test_fake; assert true end |
|
525 | 525 | end |
|
526 | 526 | end |
@@ -1,434 +1,434 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 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 | begin |
|
20 | 20 | require 'mocha/setup' |
|
21 | 21 | |
|
22 | 22 | class MercurialAdapterTest < ActiveSupport::TestCase |
|
23 | 23 | HELPERS_DIR = Redmine::Scm::Adapters::MercurialAdapter::HELPERS_DIR |
|
24 | 24 | TEMPLATE_NAME = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_NAME |
|
25 | 25 | TEMPLATE_EXTENSION = Redmine::Scm::Adapters::MercurialAdapter::TEMPLATE_EXTENSION |
|
26 | 26 | |
|
27 | 27 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
28 | 28 | CHAR_1_HEX = "\xc3\x9c" |
|
29 | 29 | |
|
30 | 30 | if File.directory?(REPOSITORY_PATH) |
|
31 | 31 | def setup |
|
32 | 32 | adapter_class = Redmine::Scm::Adapters::MercurialAdapter |
|
33 | 33 | assert adapter_class |
|
34 | 34 | assert adapter_class.client_command |
|
35 | 35 | assert_equal true, adapter_class.client_available |
|
36 | 36 | assert_equal true, adapter_class.client_version_above?([0, 9, 5]) |
|
37 | 37 | |
|
38 | 38 | @adapter = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
39 | 39 | REPOSITORY_PATH, |
|
40 | 40 | nil, |
|
41 | 41 | nil, |
|
42 | 42 | nil, |
|
43 | 43 | 'ISO-8859-1') |
|
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 @tag_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 | def test_hgversion |
|
58 | 58 | to_test = { "Mercurial Distributed SCM (version 0.9.5)\n" => [0,9,5], |
|
59 | 59 | "Mercurial Distributed SCM (1.0)\n" => [1,0], |
|
60 | 60 | "Mercurial Distributed SCM (1e4ddc9ac9f7+20080325)\n" => nil, |
|
61 | 61 | "Mercurial Distributed SCM (1.0.1+20080525)\n" => [1,0,1], |
|
62 | 62 | "Mercurial Distributed SCM (1916e629a29d)\n" => nil, |
|
63 | 63 | "Mercurial SCM Distribuito (versione 0.9.5)\n" => [0,9,5], |
|
64 | 64 | "(1.6)\n(1.7)\n(1.8)" => [1,6], |
|
65 | 65 | "(1.7.1)\r\n(1.8.1)\r\n(1.9.1)" => [1,7,1]} |
|
66 | 66 | |
|
67 | 67 | to_test.each do |s, v| |
|
68 | 68 | test_hgversion_for(s, v) |
|
69 | 69 | end |
|
70 | 70 | end |
|
71 | 71 | |
|
72 | 72 | def test_template_path |
|
73 | 73 | to_test = { |
|
74 | 74 | [1,2] => "1.0", |
|
75 | 75 | [] => "1.0", |
|
76 | 76 | [1,2,1] => "1.0", |
|
77 | 77 | [1,7] => "1.0", |
|
78 | 78 | [1,7,1] => "1.0", |
|
79 | 79 | [2,0] => "1.0", |
|
80 | 80 | } |
|
81 | 81 | to_test.each do |v, template| |
|
82 | 82 | test_template_path_for(v, template) |
|
83 | 83 | end |
|
84 | 84 | end |
|
85 | 85 | |
|
86 | 86 | def test_info |
|
87 | 87 | [REPOSITORY_PATH, REPOSITORY_PATH + "/", |
|
88 | 88 | REPOSITORY_PATH + "//"].each do |repo| |
|
89 | 89 | adp = Redmine::Scm::Adapters::MercurialAdapter.new(repo) |
|
90 | 90 | repo_path = adp.info.root_url.gsub(/\\/, "/") |
|
91 | 91 | assert_equal REPOSITORY_PATH, repo_path |
|
92 |
assert_equal '3 |
|
|
93 |
assert_equal ' |
|
|
92 | assert_equal '33', adp.info.lastrev.revision | |
|
93 | assert_equal '2e6d54642923',adp.info.lastrev.scmid | |
|
94 | 94 | end |
|
95 | 95 | end |
|
96 | 96 | |
|
97 | 97 | def test_revisions |
|
98 | 98 | revisions = @adapter.revisions(nil, 2, 4) |
|
99 | 99 | assert_equal 3, revisions.size |
|
100 | 100 | assert_equal '2', revisions[0].revision |
|
101 | 101 | assert_equal '400bb8672109', revisions[0].scmid |
|
102 | 102 | assert_equal '4', revisions[2].revision |
|
103 | 103 | assert_equal 'def6d2f1254a', revisions[2].scmid |
|
104 | 104 | |
|
105 | 105 | revisions = @adapter.revisions(nil, 2, 4, {:limit => 2}) |
|
106 | 106 | assert_equal 2, revisions.size |
|
107 | 107 | assert_equal '2', revisions[0].revision |
|
108 | 108 | assert_equal '400bb8672109', revisions[0].scmid |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | def test_parents |
|
112 | 112 | revs1 = @adapter.revisions(nil, 0, 0) |
|
113 | 113 | assert_equal 1, revs1.size |
|
114 | 114 | assert_equal [], revs1[0].parents |
|
115 | 115 | revs2 = @adapter.revisions(nil, 1, 1) |
|
116 | 116 | assert_equal 1, revs2.size |
|
117 | 117 | assert_equal 1, revs2[0].parents.size |
|
118 | 118 | assert_equal "0885933ad4f6", revs2[0].parents[0] |
|
119 | 119 | revs3 = @adapter.revisions(nil, 30, 30) |
|
120 | 120 | assert_equal 1, revs3.size |
|
121 | 121 | assert_equal 2, revs3[0].parents.size |
|
122 | 122 | assert_equal "a94b0528f24f", revs3[0].parents[0] |
|
123 | 123 | assert_equal "3a330eb32958", revs3[0].parents[1] |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_diff |
|
127 | 127 | if @adapter.class.client_version_above?([1, 2]) |
|
128 | 128 | assert_nil @adapter.diff(nil, '100000') |
|
129 | 129 | end |
|
130 | 130 | assert_nil @adapter.diff(nil, '100000', '200000') |
|
131 | 131 | [2, '400bb8672109', '400', 400].each do |r1| |
|
132 | 132 | diff1 = @adapter.diff(nil, r1) |
|
133 | 133 | if @diff_c_support |
|
134 | 134 | assert_equal 28, diff1.size |
|
135 | 135 | buf = diff1[24].gsub(/\r\n|\r|\n/, "") |
|
136 | 136 | assert_equal "+ return true unless klass.respond_to?('watched_by')", buf |
|
137 | 137 | else |
|
138 | 138 | assert_equal 0, diff1.size |
|
139 | 139 | end |
|
140 | 140 | [4, 'def6d2f1254a'].each do |r2| |
|
141 | 141 | diff2 = @adapter.diff(nil, r1, r2) |
|
142 | 142 | assert_equal 49, diff2.size |
|
143 | 143 | buf = diff2[41].gsub(/\r\n|\r|\n/, "") |
|
144 | 144 | assert_equal "+class WelcomeController < ApplicationController", buf |
|
145 | 145 | diff3 = @adapter.diff('sources/watchers_controller.rb', r1, r2) |
|
146 | 146 | assert_equal 20, diff3.size |
|
147 | 147 | buf = diff3[12].gsub(/\r\n|\r|\n/, "") |
|
148 | 148 | assert_equal "+ @watched.remove_watcher(user)", buf |
|
149 | 149 | |
|
150 | 150 | diff4 = @adapter.diff(nil, r2, r1) |
|
151 | 151 | assert_equal 49, diff4.size |
|
152 | 152 | buf = diff4[41].gsub(/\r\n|\r|\n/, "") |
|
153 | 153 | assert_equal "-class WelcomeController < ApplicationController", buf |
|
154 | 154 | diff5 = @adapter.diff('sources/watchers_controller.rb', r2, r1) |
|
155 | 155 | assert_equal 20, diff5.size |
|
156 | 156 | buf = diff5[9].gsub(/\r\n|\r|\n/, "") |
|
157 | 157 | assert_equal "- @watched.remove_watcher(user)", buf |
|
158 | 158 | end |
|
159 | 159 | end |
|
160 | 160 | end |
|
161 | 161 | |
|
162 | 162 | def test_diff_made_by_revision |
|
163 | 163 | if @diff_c_support |
|
164 | 164 | [24, '24', '4cddb4e45f52'].each do |r1| |
|
165 | 165 | diff1 = @adapter.diff(nil, r1) |
|
166 | 166 | assert_equal 5, diff1.size |
|
167 | 167 | buf = diff1[4].gsub(/\r\n|\r|\n/, "") |
|
168 | 168 | assert_equal '+0885933ad4f68d77c2649cd11f8311276e7ef7ce tag-init-revision', buf |
|
169 | 169 | end |
|
170 | 170 | end |
|
171 | 171 | end |
|
172 | 172 | |
|
173 | 173 | def test_cat |
|
174 | 174 | [2, '400bb8672109', '400', 400].each do |r| |
|
175 | 175 | buf = @adapter.cat('sources/welcome_controller.rb', r) |
|
176 | 176 | assert buf |
|
177 | 177 | lines = buf.split("\r\n") |
|
178 | 178 | assert_equal 25, lines.length |
|
179 | 179 | assert_equal 'class WelcomeController < ApplicationController', lines[17] |
|
180 | 180 | end |
|
181 | 181 | assert_nil @adapter.cat('sources/welcome_controller.rb') |
|
182 | 182 | end |
|
183 | 183 | |
|
184 | 184 | def test_annotate |
|
185 | 185 | assert_equal [], @adapter.annotate("sources/welcome_controller.rb").lines |
|
186 | 186 | [2, '400bb8672109', '400', 400].each do |r| |
|
187 | 187 | ann = @adapter.annotate('sources/welcome_controller.rb', r) |
|
188 | 188 | assert ann |
|
189 | 189 | assert_equal '1', ann.revisions[17].revision |
|
190 | 190 | assert_equal '9d5b5b004199', ann.revisions[17].identifier |
|
191 | 191 | assert_equal 'jsmith', ann.revisions[0].author |
|
192 | 192 | assert_equal 25, ann.lines.length |
|
193 | 193 | assert_equal 'class WelcomeController < ApplicationController', ann.lines[17] |
|
194 | 194 | end |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def test_entries |
|
198 | 198 | assert_nil @adapter.entries(nil, '100000') |
|
199 | 199 | |
|
200 | 200 | assert_equal 1, @adapter.entries("sources", 3).size |
|
201 | 201 | assert_equal 1, @adapter.entries("sources", 'b3a615152df8').size |
|
202 | 202 | |
|
203 | 203 | [2, '400bb8672109', '400', 400].each do |r| |
|
204 | 204 | entries1 = @adapter.entries(nil, r) |
|
205 | 205 | assert entries1 |
|
206 | 206 | assert_equal 3, entries1.size |
|
207 | 207 | assert_equal 'sources', entries1[1].name |
|
208 | 208 | assert_equal 'sources', entries1[1].path |
|
209 | 209 | assert_equal 'dir', entries1[1].kind |
|
210 | 210 | readme = entries1[2] |
|
211 | 211 | assert_equal 'README', readme.name |
|
212 | 212 | assert_equal 'README', readme.path |
|
213 | 213 | assert_equal 'file', readme.kind |
|
214 | 214 | assert_equal 27, readme.size |
|
215 | 215 | assert_equal '1', readme.lastrev.revision |
|
216 | 216 | assert_equal '9d5b5b004199', readme.lastrev.identifier |
|
217 | 217 | # 2007-12-14 10:24:01 +0100 |
|
218 | 218 | assert_equal Time.gm(2007, 12, 14, 9, 24, 1), readme.lastrev.time |
|
219 | 219 | |
|
220 | 220 | entries2 = @adapter.entries('sources', r) |
|
221 | 221 | assert entries2 |
|
222 | 222 | assert_equal 2, entries2.size |
|
223 | 223 | assert_equal 'watchers_controller.rb', entries2[0].name |
|
224 | 224 | assert_equal 'sources/watchers_controller.rb', entries2[0].path |
|
225 | 225 | assert_equal 'file', entries2[0].kind |
|
226 | 226 | assert_equal 'welcome_controller.rb', entries2[1].name |
|
227 | 227 | assert_equal 'sources/welcome_controller.rb', entries2[1].path |
|
228 | 228 | assert_equal 'file', entries2[1].kind |
|
229 | 229 | end |
|
230 | 230 | end |
|
231 | 231 | |
|
232 | 232 | def test_entries_tag |
|
233 | 233 | entries1 = @adapter.entries(nil, 'tag_test.00') |
|
234 | 234 | assert entries1 |
|
235 | 235 | assert_equal 3, entries1.size |
|
236 | 236 | assert_equal 'sources', entries1[1].name |
|
237 | 237 | assert_equal 'sources', entries1[1].path |
|
238 | 238 | assert_equal 'dir', entries1[1].kind |
|
239 | 239 | readme = entries1[2] |
|
240 | 240 | assert_equal 'README', readme.name |
|
241 | 241 | assert_equal 'README', readme.path |
|
242 | 242 | assert_equal 'file', readme.kind |
|
243 | 243 | assert_equal 21, readme.size |
|
244 | 244 | assert_equal '0', readme.lastrev.revision |
|
245 | 245 | assert_equal '0885933ad4f6', readme.lastrev.identifier |
|
246 | 246 | # 2007-12-14 10:22:52 +0100 |
|
247 | 247 | assert_equal Time.gm(2007, 12, 14, 9, 22, 52), readme.lastrev.time |
|
248 | 248 | end |
|
249 | 249 | |
|
250 | 250 | def test_entries_branch |
|
251 | 251 | entries1 = @adapter.entries(nil, 'test-branch-00') |
|
252 | 252 | assert entries1 |
|
253 | 253 | assert_equal 5, entries1.size |
|
254 | 254 | assert_equal 'sql_escape', entries1[2].name |
|
255 | 255 | assert_equal 'sql_escape', entries1[2].path |
|
256 | 256 | assert_equal 'dir', entries1[2].kind |
|
257 | 257 | readme = entries1[4] |
|
258 | 258 | assert_equal 'README', readme.name |
|
259 | 259 | assert_equal 'README', readme.path |
|
260 | 260 | assert_equal 'file', readme.kind |
|
261 | 261 | assert_equal 365, readme.size |
|
262 | 262 | assert_equal '8', readme.lastrev.revision |
|
263 | 263 | assert_equal 'c51f5bb613cd', readme.lastrev.identifier |
|
264 | 264 | # 2001-02-01 00:00:00 -0900 |
|
265 | 265 | assert_equal Time.gm(2001, 2, 1, 9, 0, 0), readme.lastrev.time |
|
266 | 266 | end |
|
267 | 267 | |
|
268 | 268 | def test_locate_on_outdated_repository |
|
269 | 269 | assert_equal 1, @adapter.entries("images", 0).size |
|
270 | 270 | assert_equal 2, @adapter.entries("images").size |
|
271 | 271 | assert_equal 2, @adapter.entries("images", 2).size |
|
272 | 272 | end |
|
273 | 273 | |
|
274 | 274 | def test_access_by_nodeid |
|
275 | 275 | path = 'sources/welcome_controller.rb' |
|
276 | 276 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400bb8672109') |
|
277 | 277 | end |
|
278 | 278 | |
|
279 | 279 | def test_access_by_fuzzy_nodeid |
|
280 | 280 | path = 'sources/welcome_controller.rb' |
|
281 | 281 | # falls back to nodeid |
|
282 | 282 | assert_equal @adapter.cat(path, 2), @adapter.cat(path, '400') |
|
283 | 283 | end |
|
284 | 284 | |
|
285 | 285 | def test_tags |
|
286 | 286 | assert_equal [@tag_char_1, 'tag_test.00', 'tag-init-revision'], @adapter.tags |
|
287 | 287 | end |
|
288 | 288 | |
|
289 | 289 | def test_tagmap |
|
290 | 290 | tm = { |
|
291 | 291 | @tag_char_1 => 'adf805632193', |
|
292 | 292 | 'tag_test.00' => '6987191f453a', |
|
293 | 293 | 'tag-init-revision' => '0885933ad4f6', |
|
294 | 294 | } |
|
295 | 295 | assert_equal tm, @adapter.tagmap |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | 298 | def test_branches |
|
299 | 299 | brs = [] |
|
300 | 300 | @adapter.branches.each do |b| |
|
301 | 301 | brs << b |
|
302 | 302 | end |
|
303 | 303 | assert_equal 7, brs.length |
|
304 | 304 | assert_equal 'default', brs[0].to_s |
|
305 | 305 | assert_equal '31', brs[0].revision |
|
306 | 306 | assert_equal '31eeee7395c8', brs[0].scmid |
|
307 | 307 | assert_equal 'test-branch-01', brs[1].to_s |
|
308 | 308 | assert_equal '30', brs[1].revision |
|
309 | 309 | assert_equal 'ad4dc4f80284', brs[1].scmid |
|
310 | 310 | assert_equal @branch_char_1, brs[2].to_s |
|
311 | 311 | assert_equal '27', brs[2].revision |
|
312 | 312 | assert_equal '7bbf4c738e71', brs[2].scmid |
|
313 | 313 | assert_equal 'branch (1)[2]&,%.-3_4', brs[3].to_s |
|
314 | 314 | assert_equal '25', brs[3].revision |
|
315 | 315 | assert_equal 'afc61e85bde7', brs[3].scmid |
|
316 | 316 | assert_equal @branch_char_0, brs[4].to_s |
|
317 | 317 | assert_equal '23', brs[4].revision |
|
318 | 318 | assert_equal 'c8d3e4887474', brs[4].scmid |
|
319 | 319 | assert_equal 'test_branch.latin-1', brs[5].to_s |
|
320 | 320 | assert_equal '22', brs[5].revision |
|
321 | 321 | assert_equal 'c2ffe7da686a', brs[5].scmid |
|
322 | 322 | assert_equal 'test-branch-00', brs[6].to_s |
|
323 | 323 | assert_equal '13', brs[6].revision |
|
324 | 324 | assert_equal '3a330eb32958', brs[6].scmid |
|
325 | 325 | end |
|
326 | 326 | |
|
327 | 327 | def test_branchmap |
|
328 | 328 | bm = { |
|
329 | 329 | 'default' => '31eeee7395c8', |
|
330 | 330 | 'test_branch.latin-1' => 'c2ffe7da686a', |
|
331 | 331 | 'branch (1)[2]&,%.-3_4' => 'afc61e85bde7', |
|
332 | 332 | 'test-branch-00' => '3a330eb32958', |
|
333 | 333 | "test-branch-01" => 'ad4dc4f80284', |
|
334 | 334 | @branch_char_0 => 'c8d3e4887474', |
|
335 | 335 | @branch_char_1 => '7bbf4c738e71', |
|
336 | 336 | } |
|
337 | 337 | assert_equal bm, @adapter.branchmap |
|
338 | 338 | end |
|
339 | 339 | |
|
340 | 340 | def test_path_space |
|
341 | 341 | p = 'README (1)[2]&,%.-3_4' |
|
342 | 342 | [15, '933ca60293d7'].each do |r1| |
|
343 | 343 | assert @adapter.diff(p, r1) |
|
344 | 344 | assert @adapter.cat(p, r1) |
|
345 | 345 | assert_equal 1, @adapter.annotate(p, r1).lines.length |
|
346 | 346 | [25, 'afc61e85bde7'].each do |r2| |
|
347 | 347 | assert @adapter.diff(p, r1, r2) |
|
348 | 348 | end |
|
349 | 349 | end |
|
350 | 350 | end |
|
351 | 351 | |
|
352 | 352 | def test_tag_non_ascii |
|
353 | 353 | p = "latin-1-dir/test-#{@char_1}-1.txt" |
|
354 | 354 | assert @adapter.cat(p, @tag_char_1) |
|
355 | 355 | assert_equal 1, @adapter.annotate(p, @tag_char_1).lines.length |
|
356 | 356 | end |
|
357 | 357 | |
|
358 | 358 | def test_branch_non_ascii |
|
359 | 359 | p = "latin-1-dir/test-#{@char_1}-subdir/test-#{@char_1}-1.txt" |
|
360 | 360 | assert @adapter.cat(p, @branch_char_1) |
|
361 | 361 | assert_equal 1, @adapter.annotate(p, @branch_char_1).lines.length |
|
362 | 362 | end |
|
363 | 363 | |
|
364 | 364 | def test_nodes_in_branch |
|
365 | 365 | [ |
|
366 | 366 | 'default', |
|
367 | 367 | @branch_char_1, |
|
368 | 368 | 'branch (1)[2]&,%.-3_4', |
|
369 | 369 | @branch_char_0, |
|
370 | 370 | 'test_branch.latin-1', |
|
371 | 371 | 'test-branch-00', |
|
372 | 372 | ].each do |bra| |
|
373 | 373 | nib0 = @adapter.nodes_in_branch(bra) |
|
374 | 374 | assert nib0 |
|
375 | 375 | nib1 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
376 | 376 | assert_equal 1, nib1.size |
|
377 | 377 | case bra |
|
378 | 378 | when 'branch (1)[2]&,%.-3_4' |
|
379 | 379 | if @adapter.class.client_version_above?([1, 6]) |
|
380 | 380 | assert_equal 3, nib0.size |
|
381 | 381 | assert_equal nib0[0], 'afc61e85bde7' |
|
382 | 382 | nib2 = @adapter.nodes_in_branch(bra, :limit => 2) |
|
383 | 383 | assert_equal 2, nib2.size |
|
384 | 384 | assert_equal nib2[1], '933ca60293d7' |
|
385 | 385 | end |
|
386 | 386 | when @branch_char_1 |
|
387 | 387 | if @adapter.class.client_version_above?([1, 6]) |
|
388 | 388 | assert_equal 2, nib0.size |
|
389 | 389 | assert_equal nib0[1], '08ff3227303e' |
|
390 | 390 | nib2 = @adapter.nodes_in_branch(bra, :limit => 1) |
|
391 | 391 | assert_equal 1, nib2.size |
|
392 | 392 | assert_equal nib2[0], '7bbf4c738e71' |
|
393 | 393 | end |
|
394 | 394 | end |
|
395 | 395 | end |
|
396 | 396 | end |
|
397 | 397 | |
|
398 | 398 | def test_path_encoding_default_utf8 |
|
399 | 399 | adpt1 = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
400 | 400 | REPOSITORY_PATH |
|
401 | 401 | ) |
|
402 | 402 | assert_equal "UTF-8", adpt1.path_encoding |
|
403 | 403 | adpt2 = Redmine::Scm::Adapters::MercurialAdapter.new( |
|
404 | 404 | REPOSITORY_PATH, |
|
405 | 405 | nil, |
|
406 | 406 | nil, |
|
407 | 407 | nil, |
|
408 | 408 | "" |
|
409 | 409 | ) |
|
410 | 410 | assert_equal "UTF-8", adpt2.path_encoding |
|
411 | 411 | end |
|
412 | 412 | |
|
413 | 413 | private |
|
414 | 414 | |
|
415 | 415 | def test_hgversion_for(hgversion, version) |
|
416 | 416 | @adapter.class.expects(:hgversion_from_command_line).returns(hgversion) |
|
417 | 417 | assert_equal version, @adapter.class.hgversion |
|
418 | 418 | end |
|
419 | 419 | |
|
420 | 420 | def test_template_path_for(version, template) |
|
421 | 421 | assert_equal "#{HELPERS_DIR}/#{TEMPLATE_NAME}-#{template}.#{TEMPLATE_EXTENSION}", |
|
422 | 422 | @adapter.class.template_path_for(version) |
|
423 | 423 | assert File.exist?(@adapter.class.template_path_for(version)) |
|
424 | 424 | end |
|
425 | 425 | else |
|
426 | 426 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
427 | 427 | def test_fake; assert true end |
|
428 | 428 | end |
|
429 | 429 | end |
|
430 | 430 | rescue LoadError |
|
431 | 431 | class MercurialMochaFake < ActiveSupport::TestCase |
|
432 | 432 | def test_fake; assert(false, "Requires mocha to run those tests") end |
|
433 | 433 | end |
|
434 | 434 | end |
@@ -1,377 +1,377 | |||
|
1 | 1 | # Redmine - project management software |
|
2 | 2 | # Copyright (C) 2006-2014 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 | |
|
20 | 20 | class RepositoryMercurialTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects |
|
22 | 22 | |
|
23 | 23 | include Redmine::I18n |
|
24 | 24 | |
|
25 | 25 | REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
|
26 |
NUM_REV = 3 |
|
|
26 | NUM_REV = 34 | |
|
27 | 27 | CHAR_1_HEX = "\xc3\x9c" |
|
28 | 28 | |
|
29 | 29 | def setup |
|
30 | 30 | @project = Project.find(3) |
|
31 | 31 | @repository = Repository::Mercurial.create( |
|
32 | 32 | :project => @project, |
|
33 | 33 | :url => REPOSITORY_PATH, |
|
34 | 34 | :path_encoding => 'ISO-8859-1' |
|
35 | 35 | ) |
|
36 | 36 | assert @repository |
|
37 | 37 | @char_1 = CHAR_1_HEX.dup |
|
38 | 38 | @tag_char_1 = "tag-#{CHAR_1_HEX}-00" |
|
39 | 39 | @branch_char_0 = "branch-#{CHAR_1_HEX}-00" |
|
40 | 40 | @branch_char_1 = "branch-#{CHAR_1_HEX}-01" |
|
41 | 41 | if @char_1.respond_to?(:force_encoding) |
|
42 | 42 | @char_1.force_encoding('UTF-8') |
|
43 | 43 | @tag_char_1.force_encoding('UTF-8') |
|
44 | 44 | @branch_char_0.force_encoding('UTF-8') |
|
45 | 45 | @branch_char_1.force_encoding('UTF-8') |
|
46 | 46 | end |
|
47 | 47 | end |
|
48 | 48 | |
|
49 | 49 | |
|
50 | 50 | def test_blank_path_to_repository_error_message |
|
51 | 51 | set_language_if_valid 'en' |
|
52 | 52 | repo = Repository::Mercurial.new( |
|
53 | 53 | :project => @project, |
|
54 | 54 | :identifier => 'test' |
|
55 | 55 | ) |
|
56 | 56 | assert !repo.save |
|
57 | 57 | assert_include "Path to repository can't be blank", |
|
58 | 58 | repo.errors.full_messages |
|
59 | 59 | end |
|
60 | 60 | |
|
61 | 61 | def test_blank_path_to_repository_error_message_fr |
|
62 | 62 | set_language_if_valid 'fr' |
|
63 | 63 | str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)" |
|
64 | 64 | str.force_encoding('UTF-8') if str.respond_to?(:force_encoding) |
|
65 | 65 | repo = Repository::Mercurial.new( |
|
66 | 66 | :project => @project, |
|
67 | 67 | :url => "", |
|
68 | 68 | :identifier => 'test', |
|
69 | 69 | :path_encoding => '' |
|
70 | 70 | ) |
|
71 | 71 | assert !repo.save |
|
72 | 72 | assert_include str, repo.errors.full_messages |
|
73 | 73 | end |
|
74 | 74 | |
|
75 | 75 | if File.directory?(REPOSITORY_PATH) |
|
76 | 76 | def test_scm_available |
|
77 | 77 | klass = Repository::Mercurial |
|
78 | 78 | assert_equal "Mercurial", klass.scm_name |
|
79 | 79 | assert klass.scm_adapter_class |
|
80 | 80 | assert_not_equal "", klass.scm_command |
|
81 | 81 | assert_equal true, klass.scm_available |
|
82 | 82 | end |
|
83 | 83 | |
|
84 | 84 | def test_entries |
|
85 | 85 | entries = @repository.entries |
|
86 | 86 | assert_kind_of Redmine::Scm::Adapters::Entries, entries |
|
87 | 87 | end |
|
88 | 88 | |
|
89 | 89 | def test_fetch_changesets_from_scratch |
|
90 | 90 | assert_equal 0, @repository.changesets.count |
|
91 | 91 | @repository.fetch_changesets |
|
92 | 92 | @project.reload |
|
93 | 93 | assert_equal NUM_REV, @repository.changesets.count |
|
94 | 94 | assert_equal 46, @repository.filechanges.count |
|
95 | 95 | assert_equal "Initial import.\nThe repository contains 3 files.", |
|
96 | 96 | @repository.changesets.find_by_revision('0').comments |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | def test_fetch_changesets_incremental |
|
100 | 100 | assert_equal 0, @repository.changesets.count |
|
101 | 101 | @repository.fetch_changesets |
|
102 | 102 | @project.reload |
|
103 | 103 | assert_equal NUM_REV, @repository.changesets.count |
|
104 | 104 | # Remove changesets with revision > 2 |
|
105 | 105 | @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2} |
|
106 | 106 | @project.reload |
|
107 | 107 | assert_equal 3, @repository.changesets.count |
|
108 | 108 | |
|
109 | 109 | @repository.fetch_changesets |
|
110 | 110 | @project.reload |
|
111 | 111 | assert_equal NUM_REV, @repository.changesets.count |
|
112 | 112 | end |
|
113 | 113 | |
|
114 | 114 | def test_isodatesec |
|
115 | 115 | # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
|
116 | 116 | if @repository.scm.class.client_version_above?([1, 0]) |
|
117 | 117 | assert_equal 0, @repository.changesets.count |
|
118 | 118 | @repository.fetch_changesets |
|
119 | 119 | @project.reload |
|
120 | 120 | assert_equal NUM_REV, @repository.changesets.count |
|
121 | 121 | rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
|
122 | 122 | assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
|
123 | 123 | end |
|
124 | 124 | end |
|
125 | 125 | |
|
126 | 126 | def test_changeset_order_by_revision |
|
127 | 127 | assert_equal 0, @repository.changesets.count |
|
128 | 128 | @repository.fetch_changesets |
|
129 | 129 | @project.reload |
|
130 | 130 | assert_equal NUM_REV, @repository.changesets.count |
|
131 | 131 | |
|
132 | 132 | c0 = @repository.latest_changeset |
|
133 | 133 | c1 = @repository.changesets.find_by_revision('0') |
|
134 | 134 | # sorted by revision (id), not by date |
|
135 | 135 | assert c0.revision.to_i > c1.revision.to_i |
|
136 | 136 | assert c0.committed_on < c1.committed_on |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | def test_latest_changesets |
|
140 | 140 | assert_equal 0, @repository.changesets.count |
|
141 | 141 | @repository.fetch_changesets |
|
142 | 142 | @project.reload |
|
143 | 143 | assert_equal NUM_REV, @repository.changesets.count |
|
144 | 144 | |
|
145 | 145 | # with_limit |
|
146 | 146 | changesets = @repository.latest_changesets('', nil, 2) |
|
147 |
assert_equal |
|
|
147 | assert_equal ["#{NUM_REV - 1}", "#{NUM_REV - 2}"], changesets.collect(&:revision) | |
|
148 | 148 | |
|
149 | 149 | # with_filepath |
|
150 | 150 | changesets = @repository.latest_changesets( |
|
151 | 151 | '/sql_escape/percent%dir/percent%file1.txt', nil) |
|
152 | 152 | assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
|
153 | 153 | |
|
154 | 154 | changesets = @repository.latest_changesets( |
|
155 | 155 | '/sql_escape/underscore_dir/understrike_file.txt', nil) |
|
156 | 156 | assert_equal %w|30 12 9|, changesets.collect(&:revision) |
|
157 | 157 | |
|
158 | 158 | changesets = @repository.latest_changesets('README', nil) |
|
159 | 159 | assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
|
160 | 160 | |
|
161 | 161 | changesets = @repository.latest_changesets('README','8') |
|
162 | 162 | assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
|
163 | 163 | |
|
164 | 164 | changesets = @repository.latest_changesets('README','8', 2) |
|
165 | 165 | assert_equal %w|8 6|, changesets.collect(&:revision) |
|
166 | 166 | |
|
167 | 167 | # with_dirpath |
|
168 | 168 | changesets = @repository.latest_changesets('images', nil) |
|
169 | 169 | assert_equal %w|1 0|, changesets.collect(&:revision) |
|
170 | 170 | |
|
171 | 171 | path = 'sql_escape/percent%dir' |
|
172 | 172 | changesets = @repository.latest_changesets(path, nil) |
|
173 | 173 | assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
|
174 | 174 | |
|
175 | 175 | changesets = @repository.latest_changesets(path, '11') |
|
176 | 176 | assert_equal %w|11 10 9|, changesets.collect(&:revision) |
|
177 | 177 | |
|
178 | 178 | changesets = @repository.latest_changesets(path, '11', 2) |
|
179 | 179 | assert_equal %w|11 10|, changesets.collect(&:revision) |
|
180 | 180 | |
|
181 | 181 | path = 'sql_escape/underscore_dir' |
|
182 | 182 | changesets = @repository.latest_changesets(path, nil) |
|
183 | 183 | assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
|
184 | 184 | |
|
185 | 185 | changesets = @repository.latest_changesets(path, '12') |
|
186 | 186 | assert_equal %w|12 9|, changesets.collect(&:revision) |
|
187 | 187 | |
|
188 | 188 | changesets = @repository.latest_changesets(path, '12', 1) |
|
189 | 189 | assert_equal %w|12|, changesets.collect(&:revision) |
|
190 | 190 | |
|
191 | 191 | # tag |
|
192 | 192 | changesets = @repository.latest_changesets('', 'tag_test.00') |
|
193 | 193 | assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision) |
|
194 | 194 | |
|
195 | 195 | changesets = @repository.latest_changesets('', 'tag_test.00', 2) |
|
196 | 196 | assert_equal %w|5 4|, changesets.collect(&:revision) |
|
197 | 197 | |
|
198 | 198 | changesets = @repository.latest_changesets('sources', 'tag_test.00') |
|
199 | 199 | assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision) |
|
200 | 200 | |
|
201 | 201 | changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
|
202 | 202 | assert_equal %w|4 3|, changesets.collect(&:revision) |
|
203 | 203 | |
|
204 | 204 | # named branch |
|
205 | 205 | if @repository.scm.class.client_version_above?([1, 6]) |
|
206 | 206 | changesets = @repository.latest_changesets('', @branch_char_1) |
|
207 | 207 | assert_equal %w|27 26|, changesets.collect(&:revision) |
|
208 | 208 | end |
|
209 | 209 | |
|
210 | 210 | changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
|
211 | 211 | assert_equal %w|27|, changesets.collect(&:revision) |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | def test_copied_files |
|
215 | 215 | assert_equal 0, @repository.changesets.count |
|
216 | 216 | @repository.fetch_changesets |
|
217 | 217 | @project.reload |
|
218 | 218 | assert_equal NUM_REV, @repository.changesets.count |
|
219 | 219 | |
|
220 | 220 | cs1 = @repository.changesets.find_by_revision('13') |
|
221 | 221 | assert_not_nil cs1 |
|
222 | 222 | c1 = cs1.filechanges.sort_by(&:path) |
|
223 | 223 | assert_equal 2, c1.size |
|
224 | 224 | |
|
225 | 225 | assert_equal 'A', c1[0].action |
|
226 | 226 | assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path |
|
227 | 227 | assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path |
|
228 | 228 | assert_equal '3a330eb32958', c1[0].from_revision |
|
229 | 229 | |
|
230 | 230 | assert_equal 'A', c1[1].action |
|
231 | 231 | assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path |
|
232 | 232 | assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path |
|
233 | 233 | |
|
234 | 234 | cs2 = @repository.changesets.find_by_revision('15') |
|
235 | 235 | c2 = cs2.filechanges |
|
236 | 236 | assert_equal 1, c2.size |
|
237 | 237 | |
|
238 | 238 | assert_equal 'A', c2[0].action |
|
239 | 239 | assert_equal '/README (1)[2]&,%.-3_4', c2[0].path |
|
240 | 240 | assert_equal '/README', c2[0].from_path |
|
241 | 241 | assert_equal '933ca60293d7', c2[0].from_revision |
|
242 | 242 | |
|
243 | 243 | cs3 = @repository.changesets.find_by_revision('19') |
|
244 | 244 | c3 = cs3.filechanges |
|
245 | 245 | assert_equal 1, c3.size |
|
246 | 246 | assert_equal 'A', c3[0].action |
|
247 | 247 | assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path |
|
248 | 248 | assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
|
249 | 249 | assert_equal '5d9891a1b425', c3[0].from_revision |
|
250 | 250 | end |
|
251 | 251 | |
|
252 | 252 | def test_find_changeset_by_name |
|
253 | 253 | assert_equal 0, @repository.changesets.count |
|
254 | 254 | @repository.fetch_changesets |
|
255 | 255 | @project.reload |
|
256 | 256 | assert_equal NUM_REV, @repository.changesets.count |
|
257 | 257 | %w|2 400bb8672109 400|.each do |r| |
|
258 | 258 | assert_equal '2', @repository.find_changeset_by_name(r).revision |
|
259 | 259 | end |
|
260 | 260 | end |
|
261 | 261 | |
|
262 | 262 | def test_find_changeset_by_invalid_name |
|
263 | 263 | assert_equal 0, @repository.changesets.count |
|
264 | 264 | @repository.fetch_changesets |
|
265 | 265 | @project.reload |
|
266 | 266 | assert_equal NUM_REV, @repository.changesets.count |
|
267 | 267 | assert_nil @repository.find_changeset_by_name('100000') |
|
268 | 268 | end |
|
269 | 269 | |
|
270 | 270 | def test_identifier |
|
271 | 271 | assert_equal 0, @repository.changesets.count |
|
272 | 272 | @repository.fetch_changesets |
|
273 | 273 | @project.reload |
|
274 | 274 | assert_equal NUM_REV, @repository.changesets.count |
|
275 | 275 | c = @repository.changesets.find_by_revision('2') |
|
276 | 276 | assert_equal c.scmid, c.identifier |
|
277 | 277 | end |
|
278 | 278 | |
|
279 | 279 | def test_format_identifier |
|
280 | 280 | assert_equal 0, @repository.changesets.count |
|
281 | 281 | @repository.fetch_changesets |
|
282 | 282 | @project.reload |
|
283 | 283 | assert_equal NUM_REV, @repository.changesets.count |
|
284 | 284 | c = @repository.changesets.find_by_revision('2') |
|
285 | 285 | assert_equal '2:400bb8672109', c.format_identifier |
|
286 | 286 | end |
|
287 | 287 | |
|
288 | 288 | def test_find_changeset_by_empty_name |
|
289 | 289 | assert_equal 0, @repository.changesets.count |
|
290 | 290 | @repository.fetch_changesets |
|
291 | 291 | @project.reload |
|
292 | 292 | assert_equal NUM_REV, @repository.changesets.count |
|
293 | 293 | ['', ' ', nil].each do |r| |
|
294 | 294 | assert_nil @repository.find_changeset_by_name(r) |
|
295 | 295 | end |
|
296 | 296 | end |
|
297 | 297 | |
|
298 | 298 | def test_parents |
|
299 | 299 | assert_equal 0, @repository.changesets.count |
|
300 | 300 | @repository.fetch_changesets |
|
301 | 301 | @project.reload |
|
302 | 302 | assert_equal NUM_REV, @repository.changesets.count |
|
303 | 303 | r1 = @repository.changesets.find_by_revision('0') |
|
304 | 304 | assert_equal [], r1.parents |
|
305 | 305 | r2 = @repository.changesets.find_by_revision('1') |
|
306 | 306 | assert_equal 1, r2.parents.length |
|
307 | 307 | assert_equal "0885933ad4f6", |
|
308 | 308 | r2.parents[0].identifier |
|
309 | 309 | r3 = @repository.changesets.find_by_revision('30') |
|
310 | 310 | assert_equal 2, r3.parents.length |
|
311 | 311 | r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort |
|
312 | 312 | assert_equal "3a330eb32958", r4[0] |
|
313 | 313 | assert_equal "a94b0528f24f", r4[1] |
|
314 | 314 | end |
|
315 | 315 | |
|
316 | 316 | def test_activities |
|
317 | 317 | c = Changeset.new(:repository => @repository, |
|
318 | 318 | :committed_on => Time.now, |
|
319 | 319 | :revision => '123', |
|
320 | 320 | :scmid => 'abc400bb8672', |
|
321 | 321 | :comments => 'test') |
|
322 | 322 | assert c.event_title.include?('123:abc400bb8672:') |
|
323 | 323 | assert_equal 'abc400bb8672', c.event_url[:rev] |
|
324 | 324 | end |
|
325 | 325 | |
|
326 | 326 | def test_previous |
|
327 | 327 | assert_equal 0, @repository.changesets.count |
|
328 | 328 | @repository.fetch_changesets |
|
329 | 329 | @project.reload |
|
330 | 330 | assert_equal NUM_REV, @repository.changesets.count |
|
331 | 331 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
332 | 332 | changeset = @repository.find_changeset_by_name(r1) |
|
333 | 333 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
334 | 334 | assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
|
335 | 335 | end |
|
336 | 336 | end |
|
337 | 337 | end |
|
338 | 338 | |
|
339 | 339 | def test_previous_nil |
|
340 | 340 | assert_equal 0, @repository.changesets.count |
|
341 | 341 | @repository.fetch_changesets |
|
342 | 342 | @project.reload |
|
343 | 343 | assert_equal NUM_REV, @repository.changesets.count |
|
344 | 344 | %w|0 0885933ad4f6 0885|.each do |r1| |
|
345 | 345 | changeset = @repository.find_changeset_by_name(r1) |
|
346 | 346 | assert_nil changeset.previous |
|
347 | 347 | end |
|
348 | 348 | end |
|
349 | 349 | |
|
350 | 350 | def test_next |
|
351 | 351 | assert_equal 0, @repository.changesets.count |
|
352 | 352 | @repository.fetch_changesets |
|
353 | 353 | @project.reload |
|
354 | 354 | assert_equal NUM_REV, @repository.changesets.count |
|
355 | 355 | %w|27 7bbf4c738e71 7bbf|.each do |r2| |
|
356 | 356 | changeset = @repository.find_changeset_by_name(r2) |
|
357 | 357 | %w|28 3ae45e2d177d 3ae45|.each do |r1| |
|
358 | 358 | assert_equal @repository.find_changeset_by_name(r1), changeset.next |
|
359 | 359 | end |
|
360 | 360 | end |
|
361 | 361 | end |
|
362 | 362 | |
|
363 | 363 | def test_next_nil |
|
364 | 364 | assert_equal 0, @repository.changesets.count |
|
365 | 365 | @repository.fetch_changesets |
|
366 | 366 | @project.reload |
|
367 | 367 | assert_equal NUM_REV, @repository.changesets.count |
|
368 | %w|31 31eeee7395c8 31eee|.each do |r1| | |
|
368 | ["#{NUM_REV - 1}", "2e6d54642923", "2e6d5"].each do |r1| | |
|
369 | 369 | changeset = @repository.find_changeset_by_name(r1) |
|
370 | 370 | assert_nil changeset.next |
|
371 | 371 | end |
|
372 | 372 | end |
|
373 | 373 | else |
|
374 | 374 | puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!" |
|
375 | 375 | def test_fake; assert true end |
|
376 | 376 | end |
|
377 | 377 | end |
General Comments 0
You need to be logged in to leave comments.
Login now