##// END OF EJS Templates
Rails3: mercurial: git: fix error of test_fetch_changesets_from_scratch at unit model test...
Toshi MARUYAMA -
r6979:9ed7bf1d7249
parent child
Show More
@@ -1,291 +1,292
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
2 # Copyright (C) 2006-2011 Jean-Philippe Lang
3 #
3 #
4 # This program is free software; you can redistribute it and/or
4 # This program is free software; you can redistribute it and/or
5 # modify it under the terms of the GNU General Public License
5 # modify it under the terms of the GNU General Public License
6 # as published by the Free Software Foundation; either version 2
6 # as published by the Free Software Foundation; either version 2
7 # of the License, or (at your option) any later version.
7 # of the License, or (at your option) any later version.
8 #
8 #
9 # This program is distributed in the hope that it will be useful,
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
12 # GNU General Public License for more details.
13 #
13 #
14 # You should have received a copy of the GNU General Public License
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
16 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17
17
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 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
23 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
24 NUM_REV = 29
24 NUM_REV = 29
25 CHAR_1_HEX = "\xc3\x9c"
25 CHAR_1_HEX = "\xc3\x9c"
26
26
27 if File.directory?(REPOSITORY_PATH)
27 if File.directory?(REPOSITORY_PATH)
28 def setup
28 def setup
29 klass = Repository::Mercurial
29 klass = Repository::Mercurial
30 assert_equal "Mercurial", klass.scm_name
30 assert_equal "Mercurial", klass.scm_name
31 assert klass.scm_adapter_class
31 assert klass.scm_adapter_class
32 assert_not_equal "", klass.scm_command
32 assert_not_equal "", klass.scm_command
33 assert_equal true, klass.scm_available
33 assert_equal true, klass.scm_available
34
34
35 @project = Project.find(3)
35 @project = Project.find(3)
36 @repository = Repository::Mercurial.create(
36 @repository = Repository::Mercurial.create(
37 :project => @project,
37 :project => @project,
38 :url => REPOSITORY_PATH,
38 :url => REPOSITORY_PATH,
39 :path_encoding => 'ISO-8859-1'
39 :path_encoding => 'ISO-8859-1'
40 )
40 )
41 assert @repository
41 assert @repository
42 @char_1 = CHAR_1_HEX.dup
42 @char_1 = CHAR_1_HEX.dup
43 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
43 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
44 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
44 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
45 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
45 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
46 if @char_1.respond_to?(:force_encoding)
46 if @char_1.respond_to?(:force_encoding)
47 @char_1.force_encoding('UTF-8')
47 @char_1.force_encoding('UTF-8')
48 @tag_char_1.force_encoding('UTF-8')
48 @tag_char_1.force_encoding('UTF-8')
49 @branch_char_0.force_encoding('UTF-8')
49 @branch_char_0.force_encoding('UTF-8')
50 @branch_char_1.force_encoding('UTF-8')
50 @branch_char_1.force_encoding('UTF-8')
51 end
51 end
52 end
52 end
53
53
54 def test_fetch_changesets_from_scratch
54 def test_fetch_changesets_from_scratch
55 assert_equal 0, @repository.changesets.count
55 @repository.fetch_changesets
56 @repository.fetch_changesets
56 @repository.reload
57 @project.reload
57 assert_equal 29, @repository.changesets.count
58 assert_equal NUM_REV, @repository.changesets.count
58 assert_equal 37, @repository.changes.count
59 assert_equal 37, @repository.changes.count
59 assert_equal "Initial import.\nThe repository contains 3 files.",
60 assert_equal "Initial import.\nThe repository contains 3 files.",
60 @repository.changesets.find_by_revision('0').comments
61 @repository.changesets.find_by_revision('0').comments
61 end
62 end
62
63
63 def test_fetch_changesets_incremental
64 def test_fetch_changesets_incremental
64 @repository.fetch_changesets
65 @repository.fetch_changesets
65 # Remove changesets with revision > 2
66 # Remove changesets with revision > 2
66 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
67 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
67 @repository.reload
68 @repository.reload
68 assert_equal 3, @repository.changesets.count
69 assert_equal 3, @repository.changesets.count
69
70
70 @repository.fetch_changesets
71 @repository.fetch_changesets
71 assert_equal 29, @repository.changesets.count
72 assert_equal 29, @repository.changesets.count
72 end
73 end
73
74
74 def test_isodatesec
75 def test_isodatesec
75 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
76 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
76 if @repository.scm.class.client_version_above?([1, 0])
77 if @repository.scm.class.client_version_above?([1, 0])
77 @repository.fetch_changesets
78 @repository.fetch_changesets
78 @repository.reload
79 @repository.reload
79 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
80 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
80 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
81 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
81 end
82 end
82 end
83 end
83
84
84 def test_changeset_order_by_revision
85 def test_changeset_order_by_revision
85 @repository.fetch_changesets
86 @repository.fetch_changesets
86 @repository.reload
87 @repository.reload
87
88
88 c0 = @repository.latest_changeset
89 c0 = @repository.latest_changeset
89 c1 = @repository.changesets.find_by_revision('0')
90 c1 = @repository.changesets.find_by_revision('0')
90 # sorted by revision (id), not by date
91 # sorted by revision (id), not by date
91 assert c0.revision.to_i > c1.revision.to_i
92 assert c0.revision.to_i > c1.revision.to_i
92 assert c0.committed_on < c1.committed_on
93 assert c0.committed_on < c1.committed_on
93 end
94 end
94
95
95 def test_latest_changesets
96 def test_latest_changesets
96 @repository.fetch_changesets
97 @repository.fetch_changesets
97 @repository.reload
98 @repository.reload
98
99
99 # with_limit
100 # with_limit
100 changesets = @repository.latest_changesets('', nil, 2)
101 changesets = @repository.latest_changesets('', nil, 2)
101 assert_equal %w|28 27|, changesets.collect(&:revision)
102 assert_equal %w|28 27|, changesets.collect(&:revision)
102
103
103 # with_filepath
104 # with_filepath
104 changesets = @repository.latest_changesets(
105 changesets = @repository.latest_changesets(
105 '/sql_escape/percent%dir/percent%file1.txt', nil)
106 '/sql_escape/percent%dir/percent%file1.txt', nil)
106 assert_equal %w|11 10 9|, changesets.collect(&:revision)
107 assert_equal %w|11 10 9|, changesets.collect(&:revision)
107
108
108 changesets = @repository.latest_changesets(
109 changesets = @repository.latest_changesets(
109 '/sql_escape/underscore_dir/understrike_file.txt', nil)
110 '/sql_escape/underscore_dir/understrike_file.txt', nil)
110 assert_equal %w|12 9|, changesets.collect(&:revision)
111 assert_equal %w|12 9|, changesets.collect(&:revision)
111
112
112 changesets = @repository.latest_changesets('README', nil)
113 changesets = @repository.latest_changesets('README', nil)
113 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
114 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
114
115
115 changesets = @repository.latest_changesets('README','8')
116 changesets = @repository.latest_changesets('README','8')
116 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
117 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
117
118
118 changesets = @repository.latest_changesets('README','8', 2)
119 changesets = @repository.latest_changesets('README','8', 2)
119 assert_equal %w|8 6|, changesets.collect(&:revision)
120 assert_equal %w|8 6|, changesets.collect(&:revision)
120
121
121 # with_dirpath
122 # with_dirpath
122 changesets = @repository.latest_changesets('images', nil)
123 changesets = @repository.latest_changesets('images', nil)
123 assert_equal %w|1 0|, changesets.collect(&:revision)
124 assert_equal %w|1 0|, changesets.collect(&:revision)
124
125
125 path = 'sql_escape/percent%dir'
126 path = 'sql_escape/percent%dir'
126 changesets = @repository.latest_changesets(path, nil)
127 changesets = @repository.latest_changesets(path, nil)
127 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
128 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
128
129
129 changesets = @repository.latest_changesets(path, '11')
130 changesets = @repository.latest_changesets(path, '11')
130 assert_equal %w|11 10 9|, changesets.collect(&:revision)
131 assert_equal %w|11 10 9|, changesets.collect(&:revision)
131
132
132 changesets = @repository.latest_changesets(path, '11', 2)
133 changesets = @repository.latest_changesets(path, '11', 2)
133 assert_equal %w|11 10|, changesets.collect(&:revision)
134 assert_equal %w|11 10|, changesets.collect(&:revision)
134
135
135 path = 'sql_escape/underscore_dir'
136 path = 'sql_escape/underscore_dir'
136 changesets = @repository.latest_changesets(path, nil)
137 changesets = @repository.latest_changesets(path, nil)
137 assert_equal %w|13 12 9|, changesets.collect(&:revision)
138 assert_equal %w|13 12 9|, changesets.collect(&:revision)
138
139
139 changesets = @repository.latest_changesets(path, '12')
140 changesets = @repository.latest_changesets(path, '12')
140 assert_equal %w|12 9|, changesets.collect(&:revision)
141 assert_equal %w|12 9|, changesets.collect(&:revision)
141
142
142 changesets = @repository.latest_changesets(path, '12', 1)
143 changesets = @repository.latest_changesets(path, '12', 1)
143 assert_equal %w|12|, changesets.collect(&:revision)
144 assert_equal %w|12|, changesets.collect(&:revision)
144
145
145 # tag
146 # tag
146 changesets = @repository.latest_changesets('', 'tag_test.00')
147 changesets = @repository.latest_changesets('', 'tag_test.00')
147 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
148 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
148
149
149 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
150 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
150 assert_equal %w|5 4|, changesets.collect(&:revision)
151 assert_equal %w|5 4|, changesets.collect(&:revision)
151
152
152 changesets = @repository.latest_changesets('sources', 'tag_test.00')
153 changesets = @repository.latest_changesets('sources', 'tag_test.00')
153 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
154 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
154
155
155 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
156 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
156 assert_equal %w|4 3|, changesets.collect(&:revision)
157 assert_equal %w|4 3|, changesets.collect(&:revision)
157
158
158 # named branch
159 # named branch
159 changesets = @repository.latest_changesets('', @branch_char_1)
160 changesets = @repository.latest_changesets('', @branch_char_1)
160 assert_equal %w|27 26|, changesets.collect(&:revision)
161 assert_equal %w|27 26|, changesets.collect(&:revision)
161
162
162 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
163 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
163 assert_equal %w|27|, changesets.collect(&:revision)
164 assert_equal %w|27|, changesets.collect(&:revision)
164 end
165 end
165
166
166 def test_copied_files
167 def test_copied_files
167 @repository.fetch_changesets
168 @repository.fetch_changesets
168 @repository.reload
169 @repository.reload
169
170
170 cs1 = @repository.changesets.find_by_revision('13')
171 cs1 = @repository.changesets.find_by_revision('13')
171 assert_not_nil cs1
172 assert_not_nil cs1
172 c1 = cs1.changes.sort_by(&:path)
173 c1 = cs1.changes.sort_by(&:path)
173 assert_equal 2, c1.size
174 assert_equal 2, c1.size
174
175
175 assert_equal 'A', c1[0].action
176 assert_equal 'A', c1[0].action
176 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
177 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
177 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
178 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
178 assert_equal '3a330eb32958', c1[0].from_revision
179 assert_equal '3a330eb32958', c1[0].from_revision
179
180
180 assert_equal 'A', c1[1].action
181 assert_equal 'A', c1[1].action
181 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
182 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
182 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
183 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
183
184
184 cs2 = @repository.changesets.find_by_revision('15')
185 cs2 = @repository.changesets.find_by_revision('15')
185 c2 = cs2.changes
186 c2 = cs2.changes
186 assert_equal 1, c2.size
187 assert_equal 1, c2.size
187
188
188 assert_equal 'A', c2[0].action
189 assert_equal 'A', c2[0].action
189 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
190 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
190 assert_equal '/README', c2[0].from_path
191 assert_equal '/README', c2[0].from_path
191 assert_equal '933ca60293d7', c2[0].from_revision
192 assert_equal '933ca60293d7', c2[0].from_revision
192
193
193 cs3 = @repository.changesets.find_by_revision('19')
194 cs3 = @repository.changesets.find_by_revision('19')
194 c3 = cs3.changes
195 c3 = cs3.changes
195 assert_equal 1, c3.size
196 assert_equal 1, c3.size
196 assert_equal 'A', c3[0].action
197 assert_equal 'A', c3[0].action
197 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
198 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
198 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
199 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
199 assert_equal '5d9891a1b425', c3[0].from_revision
200 assert_equal '5d9891a1b425', c3[0].from_revision
200 end
201 end
201
202
202 def test_find_changeset_by_name
203 def test_find_changeset_by_name
203 @repository.fetch_changesets
204 @repository.fetch_changesets
204 @repository.reload
205 @repository.reload
205 %w|2 400bb8672109 400|.each do |r|
206 %w|2 400bb8672109 400|.each do |r|
206 assert_equal '2', @repository.find_changeset_by_name(r).revision
207 assert_equal '2', @repository.find_changeset_by_name(r).revision
207 end
208 end
208 end
209 end
209
210
210 def test_find_changeset_by_invalid_name
211 def test_find_changeset_by_invalid_name
211 @repository.fetch_changesets
212 @repository.fetch_changesets
212 @repository.reload
213 @repository.reload
213 assert_nil @repository.find_changeset_by_name('100000')
214 assert_nil @repository.find_changeset_by_name('100000')
214 end
215 end
215
216
216 def test_identifier
217 def test_identifier
217 @repository.fetch_changesets
218 @repository.fetch_changesets
218 @repository.reload
219 @repository.reload
219 c = @repository.changesets.find_by_revision('2')
220 c = @repository.changesets.find_by_revision('2')
220 assert_equal c.scmid, c.identifier
221 assert_equal c.scmid, c.identifier
221 end
222 end
222
223
223 def test_format_identifier
224 def test_format_identifier
224 @repository.fetch_changesets
225 @repository.fetch_changesets
225 @repository.reload
226 @repository.reload
226 c = @repository.changesets.find_by_revision('2')
227 c = @repository.changesets.find_by_revision('2')
227 assert_equal '2:400bb8672109', c.format_identifier
228 assert_equal '2:400bb8672109', c.format_identifier
228 end
229 end
229
230
230 def test_find_changeset_by_empty_name
231 def test_find_changeset_by_empty_name
231 @repository.fetch_changesets
232 @repository.fetch_changesets
232 @repository.reload
233 @repository.reload
233 ['', ' ', nil].each do |r|
234 ['', ' ', nil].each do |r|
234 assert_nil @repository.find_changeset_by_name(r)
235 assert_nil @repository.find_changeset_by_name(r)
235 end
236 end
236 end
237 end
237
238
238 def test_activities
239 def test_activities
239 c = Changeset.new(:repository => @repository,
240 c = Changeset.new(:repository => @repository,
240 :committed_on => Time.now,
241 :committed_on => Time.now,
241 :revision => '123',
242 :revision => '123',
242 :scmid => 'abc400bb8672',
243 :scmid => 'abc400bb8672',
243 :comments => 'test')
244 :comments => 'test')
244 assert c.event_title.include?('123:abc400bb8672:')
245 assert c.event_title.include?('123:abc400bb8672:')
245 assert_equal 'abc400bb8672', c.event_url[:rev]
246 assert_equal 'abc400bb8672', c.event_url[:rev]
246 end
247 end
247
248
248 def test_previous
249 def test_previous
249 @repository.fetch_changesets
250 @repository.fetch_changesets
250 @repository.reload
251 @repository.reload
251 %w|28 3ae45e2d177d 3ae45|.each do |r1|
252 %w|28 3ae45e2d177d 3ae45|.each do |r1|
252 changeset = @repository.find_changeset_by_name(r1)
253 changeset = @repository.find_changeset_by_name(r1)
253 %w|27 7bbf4c738e71 7bbf|.each do |r2|
254 %w|27 7bbf4c738e71 7bbf|.each do |r2|
254 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
255 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
255 end
256 end
256 end
257 end
257 end
258 end
258
259
259 def test_previous_nil
260 def test_previous_nil
260 @repository.fetch_changesets
261 @repository.fetch_changesets
261 @repository.reload
262 @repository.reload
262 %w|0 0885933ad4f6 0885|.each do |r1|
263 %w|0 0885933ad4f6 0885|.each do |r1|
263 changeset = @repository.find_changeset_by_name(r1)
264 changeset = @repository.find_changeset_by_name(r1)
264 assert_nil changeset.previous
265 assert_nil changeset.previous
265 end
266 end
266 end
267 end
267
268
268 def test_next
269 def test_next
269 @repository.fetch_changesets
270 @repository.fetch_changesets
270 @repository.reload
271 @repository.reload
271 %w|27 7bbf4c738e71 7bbf|.each do |r2|
272 %w|27 7bbf4c738e71 7bbf|.each do |r2|
272 changeset = @repository.find_changeset_by_name(r2)
273 changeset = @repository.find_changeset_by_name(r2)
273 %w|28 3ae45e2d177d 3ae45|.each do |r1|
274 %w|28 3ae45e2d177d 3ae45|.each do |r1|
274 assert_equal @repository.find_changeset_by_name(r1), changeset.next
275 assert_equal @repository.find_changeset_by_name(r1), changeset.next
275 end
276 end
276 end
277 end
277 end
278 end
278
279
279 def test_next_nil
280 def test_next_nil
280 @repository.fetch_changesets
281 @repository.fetch_changesets
281 @repository.reload
282 @repository.reload
282 %w|28 3ae45e2d177d 3ae45|.each do |r1|
283 %w|28 3ae45e2d177d 3ae45|.each do |r1|
283 changeset = @repository.find_changeset_by_name(r1)
284 changeset = @repository.find_changeset_by_name(r1)
284 assert_nil changeset.next
285 assert_nil changeset.next
285 end
286 end
286 end
287 end
287 else
288 else
288 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
289 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
289 def test_fake; assert true end
290 def test_fake; assert true end
290 end
291 end
291 end
292 end
General Comments 0
You need to be logged in to leave comments. Login now