##// END OF EJS Templates
Rails3: scm: mercurial: fix error of test_latest_changesets at unit model test...
Toshi MARUYAMA -
r6996:51d14ea51113
parent child
Show More
@@ -1,318 +1,320
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 = 29
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 37, @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 29, @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 assert_equal 0, @repository.changesets.count
105 106 @repository.fetch_changesets
106 @repository.reload
107 @project.reload
108 assert_equal NUM_REV, @repository.changesets.count
107 109
108 110 # with_limit
109 111 changesets = @repository.latest_changesets('', nil, 2)
110 112 assert_equal %w|28 27|, changesets.collect(&:revision)
111 113
112 114 # with_filepath
113 115 changesets = @repository.latest_changesets(
114 116 '/sql_escape/percent%dir/percent%file1.txt', nil)
115 117 assert_equal %w|11 10 9|, changesets.collect(&:revision)
116 118
117 119 changesets = @repository.latest_changesets(
118 120 '/sql_escape/underscore_dir/understrike_file.txt', nil)
119 121 assert_equal %w|12 9|, changesets.collect(&:revision)
120 122
121 123 changesets = @repository.latest_changesets('README', nil)
122 124 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
123 125
124 126 changesets = @repository.latest_changesets('README','8')
125 127 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
126 128
127 129 changesets = @repository.latest_changesets('README','8', 2)
128 130 assert_equal %w|8 6|, changesets.collect(&:revision)
129 131
130 132 # with_dirpath
131 133 changesets = @repository.latest_changesets('images', nil)
132 134 assert_equal %w|1 0|, changesets.collect(&:revision)
133 135
134 136 path = 'sql_escape/percent%dir'
135 137 changesets = @repository.latest_changesets(path, nil)
136 138 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
137 139
138 140 changesets = @repository.latest_changesets(path, '11')
139 141 assert_equal %w|11 10 9|, changesets.collect(&:revision)
140 142
141 143 changesets = @repository.latest_changesets(path, '11', 2)
142 144 assert_equal %w|11 10|, changesets.collect(&:revision)
143 145
144 146 path = 'sql_escape/underscore_dir'
145 147 changesets = @repository.latest_changesets(path, nil)
146 148 assert_equal %w|13 12 9|, changesets.collect(&:revision)
147 149
148 150 changesets = @repository.latest_changesets(path, '12')
149 151 assert_equal %w|12 9|, changesets.collect(&:revision)
150 152
151 153 changesets = @repository.latest_changesets(path, '12', 1)
152 154 assert_equal %w|12|, changesets.collect(&:revision)
153 155
154 156 # tag
155 157 changesets = @repository.latest_changesets('', 'tag_test.00')
156 158 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
157 159
158 160 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
159 161 assert_equal %w|5 4|, changesets.collect(&:revision)
160 162
161 163 changesets = @repository.latest_changesets('sources', 'tag_test.00')
162 164 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
163 165
164 166 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
165 167 assert_equal %w|4 3|, changesets.collect(&:revision)
166 168
167 169 # named branch
168 170 changesets = @repository.latest_changesets('', @branch_char_1)
169 171 assert_equal %w|27 26|, changesets.collect(&:revision)
170 172
171 173 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
172 174 assert_equal %w|27|, changesets.collect(&:revision)
173 175 end
174 176
175 177 def test_copied_files
176 178 @repository.fetch_changesets
177 179 @repository.reload
178 180
179 181 cs1 = @repository.changesets.find_by_revision('13')
180 182 assert_not_nil cs1
181 183 c1 = cs1.changes.sort_by(&:path)
182 184 assert_equal 2, c1.size
183 185
184 186 assert_equal 'A', c1[0].action
185 187 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
186 188 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
187 189 assert_equal '3a330eb32958', c1[0].from_revision
188 190
189 191 assert_equal 'A', c1[1].action
190 192 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
191 193 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
192 194
193 195 cs2 = @repository.changesets.find_by_revision('15')
194 196 c2 = cs2.changes
195 197 assert_equal 1, c2.size
196 198
197 199 assert_equal 'A', c2[0].action
198 200 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
199 201 assert_equal '/README', c2[0].from_path
200 202 assert_equal '933ca60293d7', c2[0].from_revision
201 203
202 204 cs3 = @repository.changesets.find_by_revision('19')
203 205 c3 = cs3.changes
204 206 assert_equal 1, c3.size
205 207 assert_equal 'A', c3[0].action
206 208 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
207 209 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
208 210 assert_equal '5d9891a1b425', c3[0].from_revision
209 211 end
210 212
211 213 def test_find_changeset_by_name
212 214 assert_equal 0, @repository.changesets.count
213 215 @repository.fetch_changesets
214 216 @project.reload
215 217 assert_equal NUM_REV, @repository.changesets.count
216 218 %w|2 400bb8672109 400|.each do |r|
217 219 assert_equal '2', @repository.find_changeset_by_name(r).revision
218 220 end
219 221 end
220 222
221 223 def test_find_changeset_by_invalid_name
222 224 assert_equal 0, @repository.changesets.count
223 225 @repository.fetch_changesets
224 226 @project.reload
225 227 assert_equal NUM_REV, @repository.changesets.count
226 228 assert_nil @repository.find_changeset_by_name('100000')
227 229 end
228 230
229 231 def test_identifier
230 232 assert_equal 0, @repository.changesets.count
231 233 @repository.fetch_changesets
232 234 @project.reload
233 235 assert_equal NUM_REV, @repository.changesets.count
234 236 c = @repository.changesets.find_by_revision('2')
235 237 assert_equal c.scmid, c.identifier
236 238 end
237 239
238 240 def test_format_identifier
239 241 assert_equal 0, @repository.changesets.count
240 242 @repository.fetch_changesets
241 243 @project.reload
242 244 assert_equal NUM_REV, @repository.changesets.count
243 245 c = @repository.changesets.find_by_revision('2')
244 246 assert_equal '2:400bb8672109', c.format_identifier
245 247 end
246 248
247 249 def test_find_changeset_by_empty_name
248 250 assert_equal 0, @repository.changesets.count
249 251 @repository.fetch_changesets
250 252 @project.reload
251 253 assert_equal NUM_REV, @repository.changesets.count
252 254 ['', ' ', nil].each do |r|
253 255 assert_nil @repository.find_changeset_by_name(r)
254 256 end
255 257 end
256 258
257 259 def test_activities
258 260 c = Changeset.new(:repository => @repository,
259 261 :committed_on => Time.now,
260 262 :revision => '123',
261 263 :scmid => 'abc400bb8672',
262 264 :comments => 'test')
263 265 assert c.event_title.include?('123:abc400bb8672:')
264 266 assert_equal 'abc400bb8672', c.event_url[:rev]
265 267 end
266 268
267 269 def test_previous
268 270 assert_equal 0, @repository.changesets.count
269 271 @repository.fetch_changesets
270 272 @project.reload
271 273 assert_equal NUM_REV, @repository.changesets.count
272 274 %w|28 3ae45e2d177d 3ae45|.each do |r1|
273 275 changeset = @repository.find_changeset_by_name(r1)
274 276 %w|27 7bbf4c738e71 7bbf|.each do |r2|
275 277 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
276 278 end
277 279 end
278 280 end
279 281
280 282 def test_previous_nil
281 283 assert_equal 0, @repository.changesets.count
282 284 @repository.fetch_changesets
283 285 @project.reload
284 286 assert_equal NUM_REV, @repository.changesets.count
285 287 %w|0 0885933ad4f6 0885|.each do |r1|
286 288 changeset = @repository.find_changeset_by_name(r1)
287 289 assert_nil changeset.previous
288 290 end
289 291 end
290 292
291 293 def test_next
292 294 assert_equal 0, @repository.changesets.count
293 295 @repository.fetch_changesets
294 296 @project.reload
295 297 assert_equal NUM_REV, @repository.changesets.count
296 298 %w|27 7bbf4c738e71 7bbf|.each do |r2|
297 299 changeset = @repository.find_changeset_by_name(r2)
298 300 %w|28 3ae45e2d177d 3ae45|.each do |r1|
299 301 assert_equal @repository.find_changeset_by_name(r1), changeset.next
300 302 end
301 303 end
302 304 end
303 305
304 306 def test_next_nil
305 307 assert_equal 0, @repository.changesets.count
306 308 @repository.fetch_changesets
307 309 @project.reload
308 310 assert_equal NUM_REV, @repository.changesets.count
309 311 %w|28 3ae45e2d177d 3ae45|.each do |r1|
310 312 changeset = @repository.find_changeset_by_name(r1)
311 313 assert_nil changeset.next
312 314 end
313 315 end
314 316 else
315 317 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
316 318 def test_fake; assert true end
317 319 end
318 320 end
General Comments 0
You need to be logged in to leave comments. Login now