##// END OF EJS Templates
remove unneeded Relation#all from RepositoryMercurialTest...
Toshi MARUYAMA -
r12301:e41271f2bd7c
parent child
Show More
@@ -1,378 +1,378
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2013 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 26 NUM_REV = 32
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 @repository.changesets.all.each {|c| c.destroy if c.revision.to_i > 2}
105 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
106 106 @project.reload
107 107 @repository.reload
108 108 assert_equal 3, @repository.changesets.count
109 109
110 110 @repository.fetch_changesets
111 111 @project.reload
112 112 assert_equal NUM_REV, @repository.changesets.count
113 113 end
114 114
115 115 def test_isodatesec
116 116 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
117 117 if @repository.scm.class.client_version_above?([1, 0])
118 118 assert_equal 0, @repository.changesets.count
119 119 @repository.fetch_changesets
120 120 @project.reload
121 121 assert_equal NUM_REV, @repository.changesets.count
122 122 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
123 123 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
124 124 end
125 125 end
126 126
127 127 def test_changeset_order_by_revision
128 128 assert_equal 0, @repository.changesets.count
129 129 @repository.fetch_changesets
130 130 @project.reload
131 131 assert_equal NUM_REV, @repository.changesets.count
132 132
133 133 c0 = @repository.latest_changeset
134 134 c1 = @repository.changesets.find_by_revision('0')
135 135 # sorted by revision (id), not by date
136 136 assert c0.revision.to_i > c1.revision.to_i
137 137 assert c0.committed_on < c1.committed_on
138 138 end
139 139
140 140 def test_latest_changesets
141 141 assert_equal 0, @repository.changesets.count
142 142 @repository.fetch_changesets
143 143 @project.reload
144 144 assert_equal NUM_REV, @repository.changesets.count
145 145
146 146 # with_limit
147 147 changesets = @repository.latest_changesets('', nil, 2)
148 148 assert_equal %w|31 30|, changesets.collect(&:revision)
149 149
150 150 # with_filepath
151 151 changesets = @repository.latest_changesets(
152 152 '/sql_escape/percent%dir/percent%file1.txt', nil)
153 153 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
154 154
155 155 changesets = @repository.latest_changesets(
156 156 '/sql_escape/underscore_dir/understrike_file.txt', nil)
157 157 assert_equal %w|30 12 9|, changesets.collect(&:revision)
158 158
159 159 changesets = @repository.latest_changesets('README', nil)
160 160 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
161 161
162 162 changesets = @repository.latest_changesets('README','8')
163 163 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
164 164
165 165 changesets = @repository.latest_changesets('README','8', 2)
166 166 assert_equal %w|8 6|, changesets.collect(&:revision)
167 167
168 168 # with_dirpath
169 169 changesets = @repository.latest_changesets('images', nil)
170 170 assert_equal %w|1 0|, changesets.collect(&:revision)
171 171
172 172 path = 'sql_escape/percent%dir'
173 173 changesets = @repository.latest_changesets(path, nil)
174 174 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
175 175
176 176 changesets = @repository.latest_changesets(path, '11')
177 177 assert_equal %w|11 10 9|, changesets.collect(&:revision)
178 178
179 179 changesets = @repository.latest_changesets(path, '11', 2)
180 180 assert_equal %w|11 10|, changesets.collect(&:revision)
181 181
182 182 path = 'sql_escape/underscore_dir'
183 183 changesets = @repository.latest_changesets(path, nil)
184 184 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
185 185
186 186 changesets = @repository.latest_changesets(path, '12')
187 187 assert_equal %w|12 9|, changesets.collect(&:revision)
188 188
189 189 changesets = @repository.latest_changesets(path, '12', 1)
190 190 assert_equal %w|12|, changesets.collect(&:revision)
191 191
192 192 # tag
193 193 changesets = @repository.latest_changesets('', 'tag_test.00')
194 194 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
195 195
196 196 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
197 197 assert_equal %w|5 4|, changesets.collect(&:revision)
198 198
199 199 changesets = @repository.latest_changesets('sources', 'tag_test.00')
200 200 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
201 201
202 202 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
203 203 assert_equal %w|4 3|, changesets.collect(&:revision)
204 204
205 205 # named branch
206 206 if @repository.scm.class.client_version_above?([1, 6])
207 207 changesets = @repository.latest_changesets('', @branch_char_1)
208 208 assert_equal %w|27 26|, changesets.collect(&:revision)
209 209 end
210 210
211 211 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
212 212 assert_equal %w|27|, changesets.collect(&:revision)
213 213 end
214 214
215 215 def test_copied_files
216 216 assert_equal 0, @repository.changesets.count
217 217 @repository.fetch_changesets
218 218 @project.reload
219 219 assert_equal NUM_REV, @repository.changesets.count
220 220
221 221 cs1 = @repository.changesets.find_by_revision('13')
222 222 assert_not_nil cs1
223 223 c1 = cs1.filechanges.sort_by(&:path)
224 224 assert_equal 2, c1.size
225 225
226 226 assert_equal 'A', c1[0].action
227 227 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
228 228 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
229 229 assert_equal '3a330eb32958', c1[0].from_revision
230 230
231 231 assert_equal 'A', c1[1].action
232 232 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
233 233 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
234 234
235 235 cs2 = @repository.changesets.find_by_revision('15')
236 236 c2 = cs2.filechanges
237 237 assert_equal 1, c2.size
238 238
239 239 assert_equal 'A', c2[0].action
240 240 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
241 241 assert_equal '/README', c2[0].from_path
242 242 assert_equal '933ca60293d7', c2[0].from_revision
243 243
244 244 cs3 = @repository.changesets.find_by_revision('19')
245 245 c3 = cs3.filechanges
246 246 assert_equal 1, c3.size
247 247 assert_equal 'A', c3[0].action
248 248 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
249 249 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
250 250 assert_equal '5d9891a1b425', c3[0].from_revision
251 251 end
252 252
253 253 def test_find_changeset_by_name
254 254 assert_equal 0, @repository.changesets.count
255 255 @repository.fetch_changesets
256 256 @project.reload
257 257 assert_equal NUM_REV, @repository.changesets.count
258 258 %w|2 400bb8672109 400|.each do |r|
259 259 assert_equal '2', @repository.find_changeset_by_name(r).revision
260 260 end
261 261 end
262 262
263 263 def test_find_changeset_by_invalid_name
264 264 assert_equal 0, @repository.changesets.count
265 265 @repository.fetch_changesets
266 266 @project.reload
267 267 assert_equal NUM_REV, @repository.changesets.count
268 268 assert_nil @repository.find_changeset_by_name('100000')
269 269 end
270 270
271 271 def test_identifier
272 272 assert_equal 0, @repository.changesets.count
273 273 @repository.fetch_changesets
274 274 @project.reload
275 275 assert_equal NUM_REV, @repository.changesets.count
276 276 c = @repository.changesets.find_by_revision('2')
277 277 assert_equal c.scmid, c.identifier
278 278 end
279 279
280 280 def test_format_identifier
281 281 assert_equal 0, @repository.changesets.count
282 282 @repository.fetch_changesets
283 283 @project.reload
284 284 assert_equal NUM_REV, @repository.changesets.count
285 285 c = @repository.changesets.find_by_revision('2')
286 286 assert_equal '2:400bb8672109', c.format_identifier
287 287 end
288 288
289 289 def test_find_changeset_by_empty_name
290 290 assert_equal 0, @repository.changesets.count
291 291 @repository.fetch_changesets
292 292 @project.reload
293 293 assert_equal NUM_REV, @repository.changesets.count
294 294 ['', ' ', nil].each do |r|
295 295 assert_nil @repository.find_changeset_by_name(r)
296 296 end
297 297 end
298 298
299 299 def test_parents
300 300 assert_equal 0, @repository.changesets.count
301 301 @repository.fetch_changesets
302 302 @project.reload
303 303 assert_equal NUM_REV, @repository.changesets.count
304 304 r1 = @repository.changesets.find_by_revision('0')
305 305 assert_equal [], r1.parents
306 306 r2 = @repository.changesets.find_by_revision('1')
307 307 assert_equal 1, r2.parents.length
308 308 assert_equal "0885933ad4f6",
309 309 r2.parents[0].identifier
310 310 r3 = @repository.changesets.find_by_revision('30')
311 311 assert_equal 2, r3.parents.length
312 312 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
313 313 assert_equal "3a330eb32958", r4[0]
314 314 assert_equal "a94b0528f24f", r4[1]
315 315 end
316 316
317 317 def test_activities
318 318 c = Changeset.new(:repository => @repository,
319 319 :committed_on => Time.now,
320 320 :revision => '123',
321 321 :scmid => 'abc400bb8672',
322 322 :comments => 'test')
323 323 assert c.event_title.include?('123:abc400bb8672:')
324 324 assert_equal 'abc400bb8672', c.event_url[:rev]
325 325 end
326 326
327 327 def test_previous
328 328 assert_equal 0, @repository.changesets.count
329 329 @repository.fetch_changesets
330 330 @project.reload
331 331 assert_equal NUM_REV, @repository.changesets.count
332 332 %w|28 3ae45e2d177d 3ae45|.each do |r1|
333 333 changeset = @repository.find_changeset_by_name(r1)
334 334 %w|27 7bbf4c738e71 7bbf|.each do |r2|
335 335 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
336 336 end
337 337 end
338 338 end
339 339
340 340 def test_previous_nil
341 341 assert_equal 0, @repository.changesets.count
342 342 @repository.fetch_changesets
343 343 @project.reload
344 344 assert_equal NUM_REV, @repository.changesets.count
345 345 %w|0 0885933ad4f6 0885|.each do |r1|
346 346 changeset = @repository.find_changeset_by_name(r1)
347 347 assert_nil changeset.previous
348 348 end
349 349 end
350 350
351 351 def test_next
352 352 assert_equal 0, @repository.changesets.count
353 353 @repository.fetch_changesets
354 354 @project.reload
355 355 assert_equal NUM_REV, @repository.changesets.count
356 356 %w|27 7bbf4c738e71 7bbf|.each do |r2|
357 357 changeset = @repository.find_changeset_by_name(r2)
358 358 %w|28 3ae45e2d177d 3ae45|.each do |r1|
359 359 assert_equal @repository.find_changeset_by_name(r1), changeset.next
360 360 end
361 361 end
362 362 end
363 363
364 364 def test_next_nil
365 365 assert_equal 0, @repository.changesets.count
366 366 @repository.fetch_changesets
367 367 @project.reload
368 368 assert_equal NUM_REV, @repository.changesets.count
369 369 %w|31 31eeee7395c8 31eee|.each do |r1|
370 370 changeset = @repository.find_changeset_by_name(r1)
371 371 assert_nil changeset.next
372 372 end
373 373 end
374 374 else
375 375 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
376 376 def test_fake; assert true end
377 377 end
378 378 end
General Comments 0
You need to be logged in to leave comments. Login now