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