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