##// END OF EJS Templates
scm: mercurial: test: model: fix failing test_parents on PostgreSQL (#5501)...
Toshi MARUYAMA -
r7599:4a5a4bad971d
parent child
Show More
@@ -1,343 +1,342
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
24 24 NUM_REV = 32
25 25 CHAR_1_HEX = "\xc3\x9c"
26 26
27 27 if File.directory?(REPOSITORY_PATH)
28 28 def setup
29 29 klass = Repository::Mercurial
30 30 assert_equal "Mercurial", klass.scm_name
31 31 assert klass.scm_adapter_class
32 32 assert_not_equal "", klass.scm_command
33 33 assert_equal true, klass.scm_available
34 34
35 35 @project = Project.find(3)
36 36 @repository = Repository::Mercurial.create(
37 37 :project => @project,
38 38 :url => REPOSITORY_PATH,
39 39 :path_encoding => 'ISO-8859-1'
40 40 )
41 41 assert @repository
42 42 @char_1 = CHAR_1_HEX.dup
43 43 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
44 44 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
45 45 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
46 46 if @char_1.respond_to?(:force_encoding)
47 47 @char_1.force_encoding('UTF-8')
48 48 @tag_char_1.force_encoding('UTF-8')
49 49 @branch_char_0.force_encoding('UTF-8')
50 50 @branch_char_1.force_encoding('UTF-8')
51 51 end
52 52 end
53 53
54 54 def test_fetch_changesets_from_scratch
55 55 assert_equal 0, @repository.changesets.count
56 56 @repository.fetch_changesets
57 57 @project.reload
58 58 assert_equal NUM_REV, @repository.changesets.count
59 59 assert_equal 46, @repository.changes.count
60 60 assert_equal "Initial import.\nThe repository contains 3 files.",
61 61 @repository.changesets.find_by_revision('0').comments
62 62 end
63 63
64 64 def test_fetch_changesets_incremental
65 65 assert_equal 0, @repository.changesets.count
66 66 @repository.fetch_changesets
67 67 @project.reload
68 68 assert_equal NUM_REV, @repository.changesets.count
69 69 # Remove changesets with revision > 2
70 70 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
71 71 @project.reload
72 72 assert_equal 3, @repository.changesets.count
73 73
74 74 @repository.fetch_changesets
75 75 @project.reload
76 76 assert_equal NUM_REV, @repository.changesets.count
77 77 end
78 78
79 79 def test_isodatesec
80 80 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
81 81 if @repository.scm.class.client_version_above?([1, 0])
82 82 assert_equal 0, @repository.changesets.count
83 83 @repository.fetch_changesets
84 84 @project.reload
85 85 assert_equal NUM_REV, @repository.changesets.count
86 86 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
87 87 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
88 88 end
89 89 end
90 90
91 91 def test_changeset_order_by_revision
92 92 assert_equal 0, @repository.changesets.count
93 93 @repository.fetch_changesets
94 94 @project.reload
95 95 assert_equal NUM_REV, @repository.changesets.count
96 96
97 97 c0 = @repository.latest_changeset
98 98 c1 = @repository.changesets.find_by_revision('0')
99 99 # sorted by revision (id), not by date
100 100 assert c0.revision.to_i > c1.revision.to_i
101 101 assert c0.committed_on < c1.committed_on
102 102 end
103 103
104 104 def test_latest_changesets
105 105 assert_equal 0, @repository.changesets.count
106 106 @repository.fetch_changesets
107 107 @project.reload
108 108 assert_equal NUM_REV, @repository.changesets.count
109 109
110 110 # with_limit
111 111 changesets = @repository.latest_changesets('', nil, 2)
112 112 assert_equal %w|31 30|, changesets.collect(&:revision)
113 113
114 114 # with_filepath
115 115 changesets = @repository.latest_changesets(
116 116 '/sql_escape/percent%dir/percent%file1.txt', nil)
117 117 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
118 118
119 119 changesets = @repository.latest_changesets(
120 120 '/sql_escape/underscore_dir/understrike_file.txt', nil)
121 121 assert_equal %w|30 12 9|, changesets.collect(&:revision)
122 122
123 123 changesets = @repository.latest_changesets('README', nil)
124 124 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
125 125
126 126 changesets = @repository.latest_changesets('README','8')
127 127 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
128 128
129 129 changesets = @repository.latest_changesets('README','8', 2)
130 130 assert_equal %w|8 6|, changesets.collect(&:revision)
131 131
132 132 # with_dirpath
133 133 changesets = @repository.latest_changesets('images', nil)
134 134 assert_equal %w|1 0|, changesets.collect(&:revision)
135 135
136 136 path = 'sql_escape/percent%dir'
137 137 changesets = @repository.latest_changesets(path, nil)
138 138 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
139 139
140 140 changesets = @repository.latest_changesets(path, '11')
141 141 assert_equal %w|11 10 9|, changesets.collect(&:revision)
142 142
143 143 changesets = @repository.latest_changesets(path, '11', 2)
144 144 assert_equal %w|11 10|, changesets.collect(&:revision)
145 145
146 146 path = 'sql_escape/underscore_dir'
147 147 changesets = @repository.latest_changesets(path, nil)
148 148 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
149 149
150 150 changesets = @repository.latest_changesets(path, '12')
151 151 assert_equal %w|12 9|, changesets.collect(&:revision)
152 152
153 153 changesets = @repository.latest_changesets(path, '12', 1)
154 154 assert_equal %w|12|, changesets.collect(&:revision)
155 155
156 156 # tag
157 157 changesets = @repository.latest_changesets('', 'tag_test.00')
158 158 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
159 159
160 160 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
161 161 assert_equal %w|5 4|, changesets.collect(&:revision)
162 162
163 163 changesets = @repository.latest_changesets('sources', 'tag_test.00')
164 164 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
165 165
166 166 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
167 167 assert_equal %w|4 3|, changesets.collect(&:revision)
168 168
169 169 # named branch
170 170 if @repository.scm.class.client_version_above?([1, 6])
171 171 changesets = @repository.latest_changesets('', @branch_char_1)
172 172 assert_equal %w|27 26|, changesets.collect(&:revision)
173 173 end
174 174
175 175 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
176 176 assert_equal %w|27|, changesets.collect(&:revision)
177 177 end
178 178
179 179 def test_copied_files
180 180 assert_equal 0, @repository.changesets.count
181 181 @repository.fetch_changesets
182 182 @project.reload
183 183 assert_equal NUM_REV, @repository.changesets.count
184 184
185 185 cs1 = @repository.changesets.find_by_revision('13')
186 186 assert_not_nil cs1
187 187 c1 = cs1.changes.sort_by(&:path)
188 188 assert_equal 2, c1.size
189 189
190 190 assert_equal 'A', c1[0].action
191 191 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
192 192 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
193 193 assert_equal '3a330eb32958', c1[0].from_revision
194 194
195 195 assert_equal 'A', c1[1].action
196 196 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
197 197 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
198 198
199 199 cs2 = @repository.changesets.find_by_revision('15')
200 200 c2 = cs2.changes
201 201 assert_equal 1, c2.size
202 202
203 203 assert_equal 'A', c2[0].action
204 204 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
205 205 assert_equal '/README', c2[0].from_path
206 206 assert_equal '933ca60293d7', c2[0].from_revision
207 207
208 208 cs3 = @repository.changesets.find_by_revision('19')
209 209 c3 = cs3.changes
210 210 assert_equal 1, c3.size
211 211 assert_equal 'A', c3[0].action
212 212 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
213 213 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
214 214 assert_equal '5d9891a1b425', c3[0].from_revision
215 215 end
216 216
217 217 def test_find_changeset_by_name
218 218 assert_equal 0, @repository.changesets.count
219 219 @repository.fetch_changesets
220 220 @project.reload
221 221 assert_equal NUM_REV, @repository.changesets.count
222 222 %w|2 400bb8672109 400|.each do |r|
223 223 assert_equal '2', @repository.find_changeset_by_name(r).revision
224 224 end
225 225 end
226 226
227 227 def test_find_changeset_by_invalid_name
228 228 assert_equal 0, @repository.changesets.count
229 229 @repository.fetch_changesets
230 230 @project.reload
231 231 assert_equal NUM_REV, @repository.changesets.count
232 232 assert_nil @repository.find_changeset_by_name('100000')
233 233 end
234 234
235 235 def test_identifier
236 236 assert_equal 0, @repository.changesets.count
237 237 @repository.fetch_changesets
238 238 @project.reload
239 239 assert_equal NUM_REV, @repository.changesets.count
240 240 c = @repository.changesets.find_by_revision('2')
241 241 assert_equal c.scmid, c.identifier
242 242 end
243 243
244 244 def test_format_identifier
245 245 assert_equal 0, @repository.changesets.count
246 246 @repository.fetch_changesets
247 247 @project.reload
248 248 assert_equal NUM_REV, @repository.changesets.count
249 249 c = @repository.changesets.find_by_revision('2')
250 250 assert_equal '2:400bb8672109', c.format_identifier
251 251 end
252 252
253 253 def test_find_changeset_by_empty_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 ['', ' ', nil].each do |r|
259 259 assert_nil @repository.find_changeset_by_name(r)
260 260 end
261 261 end
262 262
263 263 def test_parents
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 r1 = @repository.changesets.find_by_revision('0')
269 269 assert_equal [], r1.parents
270 270 r2 = @repository.changesets.find_by_revision('1')
271 271 assert_equal 1, r2.parents.length
272 272 assert_equal "0885933ad4f6",
273 273 r2.parents[0].identifier
274 274 r3 = @repository.changesets.find_by_revision('30')
275 275 assert_equal 2, r3.parents.length
276 assert_equal "a94b0528f24f",
277 r3.parents[0].identifier
278 assert_equal "3a330eb32958",
279 r3.parents[1].identifier
276 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
277 assert_equal "3a330eb32958", r4[0]
278 assert_equal "a94b0528f24f", r4[1]
280 279 end
281 280
282 281 def test_activities
283 282 c = Changeset.new(:repository => @repository,
284 283 :committed_on => Time.now,
285 284 :revision => '123',
286 285 :scmid => 'abc400bb8672',
287 286 :comments => 'test')
288 287 assert c.event_title.include?('123:abc400bb8672:')
289 288 assert_equal 'abc400bb8672', c.event_url[:rev]
290 289 end
291 290
292 291 def test_previous
293 292 assert_equal 0, @repository.changesets.count
294 293 @repository.fetch_changesets
295 294 @project.reload
296 295 assert_equal NUM_REV, @repository.changesets.count
297 296 %w|28 3ae45e2d177d 3ae45|.each do |r1|
298 297 changeset = @repository.find_changeset_by_name(r1)
299 298 %w|27 7bbf4c738e71 7bbf|.each do |r2|
300 299 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
301 300 end
302 301 end
303 302 end
304 303
305 304 def test_previous_nil
306 305 assert_equal 0, @repository.changesets.count
307 306 @repository.fetch_changesets
308 307 @project.reload
309 308 assert_equal NUM_REV, @repository.changesets.count
310 309 %w|0 0885933ad4f6 0885|.each do |r1|
311 310 changeset = @repository.find_changeset_by_name(r1)
312 311 assert_nil changeset.previous
313 312 end
314 313 end
315 314
316 315 def test_next
317 316 assert_equal 0, @repository.changesets.count
318 317 @repository.fetch_changesets
319 318 @project.reload
320 319 assert_equal NUM_REV, @repository.changesets.count
321 320 %w|27 7bbf4c738e71 7bbf|.each do |r2|
322 321 changeset = @repository.find_changeset_by_name(r2)
323 322 %w|28 3ae45e2d177d 3ae45|.each do |r1|
324 323 assert_equal @repository.find_changeset_by_name(r1), changeset.next
325 324 end
326 325 end
327 326 end
328 327
329 328 def test_next_nil
330 329 assert_equal 0, @repository.changesets.count
331 330 @repository.fetch_changesets
332 331 @project.reload
333 332 assert_equal NUM_REV, @repository.changesets.count
334 333 %w|31 31eeee7395c8 31eee|.each do |r1|
335 334 changeset = @repository.find_changeset_by_name(r1)
336 335 assert_nil changeset.next
337 336 end
338 337 end
339 338 else
340 339 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
341 340 def test_fake; assert true end
342 341 end
343 342 end
General Comments 0
You need to be logged in to leave comments. Login now