Mercurial > hg > soundsoftware-site
comparison test/unit/repository_mercurial_test.rb @ 909:cbb26bc654de redmine-1.3
Update to Redmine 1.3-stable branch (Redmine SVN rev 8964)
author | Chris Cannam |
---|---|
date | Fri, 24 Feb 2012 19:09:32 +0000 |
parents | cbce1fd3b1b7 |
children | 5e80956cc792 433d4f72a19b |
comparison
equal
deleted
inserted
replaced
908:c6c2cbd0afee | 909:cbb26bc654de |
---|---|
18 require File.expand_path('../../test_helper', __FILE__) | 18 require File.expand_path('../../test_helper', __FILE__) |
19 | 19 |
20 class RepositoryMercurialTest < ActiveSupport::TestCase | 20 class RepositoryMercurialTest < ActiveSupport::TestCase |
21 fixtures :projects | 21 fixtures :projects |
22 | 22 |
23 # No '..' in the repository path | 23 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s |
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository' | 24 NUM_REV = 32 |
25 | |
26 CHAR_1_HEX = "\xc3\x9c" | 25 CHAR_1_HEX = "\xc3\x9c" |
27 | 26 |
28 if File.directory?(REPOSITORY_PATH) | 27 if File.directory?(REPOSITORY_PATH) |
29 | |
30 def setup | 28 def setup |
31 klass = Repository::Mercurial | 29 klass = Repository::Mercurial |
32 assert_equal "Mercurial", klass.scm_name | 30 assert_equal "Mercurial", klass.scm_name |
33 assert klass.scm_adapter_class | 31 assert klass.scm_adapter_class |
34 assert_not_equal "", klass.scm_command | 32 assert_not_equal "", klass.scm_command |
35 assert_equal true, klass.scm_available | 33 assert_equal true, klass.scm_available |
36 | 34 |
37 @project = Project.find(3) | 35 @project = Project.find(3) |
38 @repository = Repository::Mercurial.create( | 36 @repository = Repository::Mercurial.create( |
39 :project => @project, | 37 :project => @project, |
40 :url => REPOSITORY_PATH, | 38 :url => REPOSITORY_PATH, |
41 :path_encoding => 'ISO-8859-1' | 39 :path_encoding => 'ISO-8859-1' |
42 ) | 40 ) |
52 @branch_char_1.force_encoding('UTF-8') | 50 @branch_char_1.force_encoding('UTF-8') |
53 end | 51 end |
54 end | 52 end |
55 | 53 |
56 def test_fetch_changesets_from_scratch | 54 def test_fetch_changesets_from_scratch |
57 @repository.fetch_changesets | 55 assert_equal 0, @repository.changesets.count |
58 @repository.reload | 56 @repository.fetch_changesets |
59 assert_equal 29, @repository.changesets.count | 57 @project.reload |
60 assert_equal 37, @repository.changes.count | 58 assert_equal NUM_REV, @repository.changesets.count |
59 assert_equal 46, @repository.changes.count | |
61 assert_equal "Initial import.\nThe repository contains 3 files.", | 60 assert_equal "Initial import.\nThe repository contains 3 files.", |
62 @repository.changesets.find_by_revision('0').comments | 61 @repository.changesets.find_by_revision('0').comments |
63 end | 62 end |
64 | 63 |
65 def test_fetch_changesets_incremental | 64 def test_fetch_changesets_incremental |
66 @repository.fetch_changesets | 65 assert_equal 0, @repository.changesets.count |
66 @repository.fetch_changesets | |
67 @project.reload | |
68 assert_equal NUM_REV, @repository.changesets.count | |
67 # Remove changesets with revision > 2 | 69 # Remove changesets with revision > 2 |
68 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} | 70 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2} |
69 @repository.reload | 71 @project.reload |
70 assert_equal 3, @repository.changesets.count | 72 assert_equal 3, @repository.changesets.count |
71 | 73 |
72 @repository.fetch_changesets | 74 @repository.fetch_changesets |
73 assert_equal 29, @repository.changesets.count | 75 @project.reload |
76 assert_equal NUM_REV, @repository.changesets.count | |
74 end | 77 end |
75 | 78 |
76 def test_isodatesec | 79 def test_isodatesec |
77 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher | 80 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher |
78 if @repository.scm.class.client_version_above?([1, 0]) | 81 if @repository.scm.class.client_version_above?([1, 0]) |
82 assert_equal 0, @repository.changesets.count | |
79 @repository.fetch_changesets | 83 @repository.fetch_changesets |
80 @repository.reload | 84 @project.reload |
85 assert_equal NUM_REV, @repository.changesets.count | |
81 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) | 86 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52) |
82 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on | 87 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on |
83 end | 88 end |
84 end | 89 end |
85 | 90 |
86 def test_changeset_order_by_revision | 91 def test_changeset_order_by_revision |
87 @repository.fetch_changesets | 92 assert_equal 0, @repository.changesets.count |
88 @repository.reload | 93 @repository.fetch_changesets |
94 @project.reload | |
95 assert_equal NUM_REV, @repository.changesets.count | |
89 | 96 |
90 c0 = @repository.latest_changeset | 97 c0 = @repository.latest_changeset |
91 c1 = @repository.changesets.find_by_revision('0') | 98 c1 = @repository.changesets.find_by_revision('0') |
92 # sorted by revision (id), not by date | 99 # sorted by revision (id), not by date |
93 assert c0.revision.to_i > c1.revision.to_i | 100 assert c0.revision.to_i > c1.revision.to_i |
94 assert c0.committed_on < c1.committed_on | 101 assert c0.committed_on < c1.committed_on |
95 end | 102 end |
96 | 103 |
97 def test_latest_changesets | 104 def test_latest_changesets |
98 @repository.fetch_changesets | 105 assert_equal 0, @repository.changesets.count |
99 @repository.reload | 106 @repository.fetch_changesets |
107 @project.reload | |
108 assert_equal NUM_REV, @repository.changesets.count | |
100 | 109 |
101 # with_limit | 110 # with_limit |
102 changesets = @repository.latest_changesets('', nil, 2) | 111 changesets = @repository.latest_changesets('', nil, 2) |
103 assert_equal %w|28 27|, changesets.collect(&:revision) | 112 assert_equal %w|31 30|, changesets.collect(&:revision) |
104 | 113 |
105 # with_filepath | 114 # with_filepath |
106 changesets = @repository.latest_changesets( | 115 changesets = @repository.latest_changesets( |
107 '/sql_escape/percent%dir/percent%file1.txt', nil) | 116 '/sql_escape/percent%dir/percent%file1.txt', nil) |
108 assert_equal %w|11 10 9|, changesets.collect(&:revision) | 117 assert_equal %w|30 11 10 9|, changesets.collect(&:revision) |
109 | 118 |
110 changesets = @repository.latest_changesets( | 119 changesets = @repository.latest_changesets( |
111 '/sql_escape/underscore_dir/understrike_file.txt', nil) | 120 '/sql_escape/underscore_dir/understrike_file.txt', nil) |
112 assert_equal %w|12 9|, changesets.collect(&:revision) | 121 assert_equal %w|30 12 9|, changesets.collect(&:revision) |
113 | 122 |
114 changesets = @repository.latest_changesets('README', nil) | 123 changesets = @repository.latest_changesets('README', nil) |
115 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision) | 124 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision) |
116 | 125 |
117 changesets = @repository.latest_changesets('README','8') | 126 changesets = @repository.latest_changesets('README','8') |
118 assert_equal %w|8 6 1 0|, changesets.collect(&:revision) | 127 assert_equal %w|8 6 1 0|, changesets.collect(&:revision) |
119 | 128 |
120 changesets = @repository.latest_changesets('README','8', 2) | 129 changesets = @repository.latest_changesets('README','8', 2) |
124 changesets = @repository.latest_changesets('images', nil) | 133 changesets = @repository.latest_changesets('images', nil) |
125 assert_equal %w|1 0|, changesets.collect(&:revision) | 134 assert_equal %w|1 0|, changesets.collect(&:revision) |
126 | 135 |
127 path = 'sql_escape/percent%dir' | 136 path = 'sql_escape/percent%dir' |
128 changesets = @repository.latest_changesets(path, nil) | 137 changesets = @repository.latest_changesets(path, nil) |
129 assert_equal %w|13 11 10 9|, changesets.collect(&:revision) | 138 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision) |
130 | 139 |
131 changesets = @repository.latest_changesets(path, '11') | 140 changesets = @repository.latest_changesets(path, '11') |
132 assert_equal %w|11 10 9|, changesets.collect(&:revision) | 141 assert_equal %w|11 10 9|, changesets.collect(&:revision) |
133 | 142 |
134 changesets = @repository.latest_changesets(path, '11', 2) | 143 changesets = @repository.latest_changesets(path, '11', 2) |
135 assert_equal %w|11 10|, changesets.collect(&:revision) | 144 assert_equal %w|11 10|, changesets.collect(&:revision) |
136 | 145 |
137 path = 'sql_escape/underscore_dir' | 146 path = 'sql_escape/underscore_dir' |
138 changesets = @repository.latest_changesets(path, nil) | 147 changesets = @repository.latest_changesets(path, nil) |
139 assert_equal %w|13 12 9|, changesets.collect(&:revision) | 148 assert_equal %w|30 13 12 9|, changesets.collect(&:revision) |
140 | 149 |
141 changesets = @repository.latest_changesets(path, '12') | 150 changesets = @repository.latest_changesets(path, '12') |
142 assert_equal %w|12 9|, changesets.collect(&:revision) | 151 assert_equal %w|12 9|, changesets.collect(&:revision) |
143 | 152 |
144 changesets = @repository.latest_changesets(path, '12', 1) | 153 changesets = @repository.latest_changesets(path, '12', 1) |
156 | 165 |
157 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) | 166 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2) |
158 assert_equal %w|4 3|, changesets.collect(&:revision) | 167 assert_equal %w|4 3|, changesets.collect(&:revision) |
159 | 168 |
160 # named branch | 169 # named branch |
161 changesets = @repository.latest_changesets('', @branch_char_1) | 170 if @repository.scm.class.client_version_above?([1, 6]) |
162 assert_equal %w|27 26|, changesets.collect(&:revision) | 171 changesets = @repository.latest_changesets('', @branch_char_1) |
172 assert_equal %w|27 26|, changesets.collect(&:revision) | |
173 end | |
163 | 174 |
164 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) | 175 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1) |
165 assert_equal %w|27|, changesets.collect(&:revision) | 176 assert_equal %w|27|, changesets.collect(&:revision) |
166 end | 177 end |
167 | 178 |
168 def test_copied_files | 179 def test_copied_files |
169 @repository.fetch_changesets | 180 assert_equal 0, @repository.changesets.count |
170 @repository.reload | 181 @repository.fetch_changesets |
182 @project.reload | |
183 assert_equal NUM_REV, @repository.changesets.count | |
171 | 184 |
172 cs1 = @repository.changesets.find_by_revision('13') | 185 cs1 = @repository.changesets.find_by_revision('13') |
173 assert_not_nil cs1 | 186 assert_not_nil cs1 |
174 c1 = cs1.changes.sort_by(&:path) | 187 c1 = cs1.changes.sort_by(&:path) |
175 assert_equal 2, c1.size | 188 assert_equal 2, c1.size |
200 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path | 213 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path |
201 assert_equal '5d9891a1b425', c3[0].from_revision | 214 assert_equal '5d9891a1b425', c3[0].from_revision |
202 end | 215 end |
203 | 216 |
204 def test_find_changeset_by_name | 217 def test_find_changeset_by_name |
205 @repository.fetch_changesets | 218 assert_equal 0, @repository.changesets.count |
206 @repository.reload | 219 @repository.fetch_changesets |
220 @project.reload | |
221 assert_equal NUM_REV, @repository.changesets.count | |
207 %w|2 400bb8672109 400|.each do |r| | 222 %w|2 400bb8672109 400|.each do |r| |
208 assert_equal '2', @repository.find_changeset_by_name(r).revision | 223 assert_equal '2', @repository.find_changeset_by_name(r).revision |
209 end | 224 end |
210 end | 225 end |
211 | 226 |
212 def test_find_changeset_by_invalid_name | 227 def test_find_changeset_by_invalid_name |
213 @repository.fetch_changesets | 228 assert_equal 0, @repository.changesets.count |
214 @repository.reload | 229 @repository.fetch_changesets |
230 @project.reload | |
231 assert_equal NUM_REV, @repository.changesets.count | |
215 assert_nil @repository.find_changeset_by_name('100000') | 232 assert_nil @repository.find_changeset_by_name('100000') |
216 end | 233 end |
217 | 234 |
218 def test_identifier | 235 def test_identifier |
219 @repository.fetch_changesets | 236 assert_equal 0, @repository.changesets.count |
220 @repository.reload | 237 @repository.fetch_changesets |
238 @project.reload | |
239 assert_equal NUM_REV, @repository.changesets.count | |
221 c = @repository.changesets.find_by_revision('2') | 240 c = @repository.changesets.find_by_revision('2') |
222 assert_equal c.scmid, c.identifier | 241 assert_equal c.scmid, c.identifier |
223 end | 242 end |
224 | 243 |
225 def test_format_identifier | 244 def test_format_identifier |
226 @repository.fetch_changesets | 245 assert_equal 0, @repository.changesets.count |
227 @repository.reload | 246 @repository.fetch_changesets |
247 @project.reload | |
248 assert_equal NUM_REV, @repository.changesets.count | |
228 c = @repository.changesets.find_by_revision('2') | 249 c = @repository.changesets.find_by_revision('2') |
229 assert_equal '2:400bb8672109', c.format_identifier | 250 assert_equal '2:400bb8672109', c.format_identifier |
230 end | 251 end |
231 | 252 |
232 def test_find_changeset_by_empty_name | 253 def test_find_changeset_by_empty_name |
233 @repository.fetch_changesets | 254 assert_equal 0, @repository.changesets.count |
234 @repository.reload | 255 @repository.fetch_changesets |
256 @project.reload | |
257 assert_equal NUM_REV, @repository.changesets.count | |
235 ['', ' ', nil].each do |r| | 258 ['', ' ', nil].each do |r| |
236 assert_nil @repository.find_changeset_by_name(r) | 259 assert_nil @repository.find_changeset_by_name(r) |
237 end | 260 end |
261 end | |
262 | |
263 def test_parents | |
264 assert_equal 0, @repository.changesets.count | |
265 @repository.fetch_changesets | |
266 @project.reload | |
267 assert_equal NUM_REV, @repository.changesets.count | |
268 r1 = @repository.changesets.find_by_revision('0') | |
269 assert_equal [], r1.parents | |
270 r2 = @repository.changesets.find_by_revision('1') | |
271 assert_equal 1, r2.parents.length | |
272 assert_equal "0885933ad4f6", | |
273 r2.parents[0].identifier | |
274 r3 = @repository.changesets.find_by_revision('30') | |
275 assert_equal 2, r3.parents.length | |
276 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort | |
277 assert_equal "3a330eb32958", r4[0] | |
278 assert_equal "a94b0528f24f", r4[1] | |
238 end | 279 end |
239 | 280 |
240 def test_activities | 281 def test_activities |
241 c = Changeset.new(:repository => @repository, | 282 c = Changeset.new(:repository => @repository, |
242 :committed_on => Time.now, | 283 :committed_on => Time.now, |
246 assert c.event_title.include?('123:abc400bb8672:') | 287 assert c.event_title.include?('123:abc400bb8672:') |
247 assert_equal 'abc400bb8672', c.event_url[:rev] | 288 assert_equal 'abc400bb8672', c.event_url[:rev] |
248 end | 289 end |
249 | 290 |
250 def test_previous | 291 def test_previous |
251 @repository.fetch_changesets | 292 assert_equal 0, @repository.changesets.count |
252 @repository.reload | 293 @repository.fetch_changesets |
294 @project.reload | |
295 assert_equal NUM_REV, @repository.changesets.count | |
253 %w|28 3ae45e2d177d 3ae45|.each do |r1| | 296 %w|28 3ae45e2d177d 3ae45|.each do |r1| |
254 changeset = @repository.find_changeset_by_name(r1) | 297 changeset = @repository.find_changeset_by_name(r1) |
255 %w|27 7bbf4c738e71 7bbf|.each do |r2| | 298 %w|27 7bbf4c738e71 7bbf|.each do |r2| |
256 assert_equal @repository.find_changeset_by_name(r2), changeset.previous | 299 assert_equal @repository.find_changeset_by_name(r2), changeset.previous |
257 end | 300 end |
258 end | 301 end |
259 end | 302 end |
260 | 303 |
261 def test_previous_nil | 304 def test_previous_nil |
262 @repository.fetch_changesets | 305 assert_equal 0, @repository.changesets.count |
263 @repository.reload | 306 @repository.fetch_changesets |
307 @project.reload | |
308 assert_equal NUM_REV, @repository.changesets.count | |
264 %w|0 0885933ad4f6 0885|.each do |r1| | 309 %w|0 0885933ad4f6 0885|.each do |r1| |
265 changeset = @repository.find_changeset_by_name(r1) | 310 changeset = @repository.find_changeset_by_name(r1) |
266 assert_nil changeset.previous | 311 assert_nil changeset.previous |
267 end | 312 end |
268 end | 313 end |
269 | 314 |
270 def test_next | 315 def test_next |
271 @repository.fetch_changesets | 316 assert_equal 0, @repository.changesets.count |
272 @repository.reload | 317 @repository.fetch_changesets |
318 @project.reload | |
319 assert_equal NUM_REV, @repository.changesets.count | |
273 %w|27 7bbf4c738e71 7bbf|.each do |r2| | 320 %w|27 7bbf4c738e71 7bbf|.each do |r2| |
274 changeset = @repository.find_changeset_by_name(r2) | 321 changeset = @repository.find_changeset_by_name(r2) |
275 %w|28 3ae45e2d177d 3ae45|.each do |r1| | 322 %w|28 3ae45e2d177d 3ae45|.each do |r1| |
276 assert_equal @repository.find_changeset_by_name(r1), changeset.next | 323 assert_equal @repository.find_changeset_by_name(r1), changeset.next |
277 end | 324 end |
278 end | 325 end |
279 end | 326 end |
280 | 327 |
281 def test_next_nil | 328 def test_next_nil |
282 @repository.fetch_changesets | 329 assert_equal 0, @repository.changesets.count |
283 @repository.reload | 330 @repository.fetch_changesets |
284 %w|28 3ae45e2d177d 3ae45|.each do |r1| | 331 @project.reload |
332 assert_equal NUM_REV, @repository.changesets.count | |
333 %w|31 31eeee7395c8 31eee|.each do |r1| | |
285 changeset = @repository.find_changeset_by_name(r1) | 334 changeset = @repository.find_changeset_by_name(r1) |
286 assert_nil changeset.next | 335 assert_nil changeset.next |
287 end | 336 end |
288 end | 337 end |
289 else | 338 else |