##// END OF EJS Templates
scm: mercurial: use scmid_for_assert in assert_entry (#14361)...
Toshi MARUYAMA -
r12498:642f13605ecb
parent child
Show More
@@ -1,528 +1,530
1 # Redmine - project management software
1 # Redmine - project management software
2 # Copyright (C) 2006-2014 Jean-Philippe Lang
2 # Copyright (C) 2006-2014 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 include Redmine::I18n
23 include Redmine::I18n
24
24
25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
25 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 NUM_REV = 32
26 NUM_REV = 32
27 CHAR_1_HEX = "\xc3\x9c"
27 CHAR_1_HEX = "\xc3\x9c"
28
28
29 def setup
29 def setup
30 @project = Project.find(3)
30 @project = Project.find(3)
31 @repository = Repository::Mercurial.create(
31 @repository = Repository::Mercurial.create(
32 :project => @project,
32 :project => @project,
33 :url => REPOSITORY_PATH,
33 :url => REPOSITORY_PATH,
34 :path_encoding => 'ISO-8859-1'
34 :path_encoding => 'ISO-8859-1'
35 )
35 )
36 assert @repository
36 assert @repository
37 @char_1 = CHAR_1_HEX.dup
37 @char_1 = CHAR_1_HEX.dup
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
38 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
39 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
40 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
41 if @char_1.respond_to?(:force_encoding)
41 if @char_1.respond_to?(:force_encoding)
42 @char_1.force_encoding('UTF-8')
42 @char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
43 @tag_char_1.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
44 @branch_char_0.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
45 @branch_char_1.force_encoding('UTF-8')
46 end
46 end
47 end
47 end
48
48
49 def test_blank_path_to_repository_error_message
49 def test_blank_path_to_repository_error_message
50 set_language_if_valid 'en'
50 set_language_if_valid 'en'
51 repo = Repository::Mercurial.new(
51 repo = Repository::Mercurial.new(
52 :project => @project,
52 :project => @project,
53 :identifier => 'test'
53 :identifier => 'test'
54 )
54 )
55 assert !repo.save
55 assert !repo.save
56 assert_include "Path to repository can't be blank",
56 assert_include "Path to repository can't be blank",
57 repo.errors.full_messages
57 repo.errors.full_messages
58 end
58 end
59
59
60 def test_blank_path_to_repository_error_message_fr
60 def test_blank_path_to_repository_error_message_fr
61 set_language_if_valid 'fr'
61 set_language_if_valid 'fr'
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
62 str = "Chemin du d\xc3\xa9p\xc3\xb4t doit \xc3\xaatre renseign\xc3\xa9(e)"
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
63 str.force_encoding('UTF-8') if str.respond_to?(:force_encoding)
64 repo = Repository::Mercurial.new(
64 repo = Repository::Mercurial.new(
65 :project => @project,
65 :project => @project,
66 :url => "",
66 :url => "",
67 :identifier => 'test',
67 :identifier => 'test',
68 :path_encoding => ''
68 :path_encoding => ''
69 )
69 )
70 assert !repo.save
70 assert !repo.save
71 assert_include str, repo.errors.full_messages
71 assert_include str, repo.errors.full_messages
72 end
72 end
73
73
74 if File.directory?(REPOSITORY_PATH)
74 if File.directory?(REPOSITORY_PATH)
75 def test_scm_available
75 def test_scm_available
76 klass = Repository::Mercurial
76 klass = Repository::Mercurial
77 assert_equal "Mercurial", klass.scm_name
77 assert_equal "Mercurial", klass.scm_name
78 assert klass.scm_adapter_class
78 assert klass.scm_adapter_class
79 assert_not_equal "", klass.scm_command
79 assert_not_equal "", klass.scm_command
80 assert_equal true, klass.scm_available
80 assert_equal true, klass.scm_available
81 end
81 end
82
82
83 def test_entries_on_tip
83 def test_entries_on_tip
84 entries = @repository.entries
84 entries = @repository.entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
85 assert_kind_of Redmine::Scm::Adapters::Entries, entries
86 end
86 end
87
87
88 def assert_entries
88 def assert_entries
89 [2, '400bb8672109', '400', 400].each do |r|
89 [2, '400bb8672109', '400', 400].each do |r|
90 entries1 = @repository.entries(nil, r)
90 entries1 = @repository.entries(nil, r)
91 assert entries1
91 assert entries1
92 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
92 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
93 assert_equal 3, entries1.size
93 assert_equal 3, entries1.size
94 readme = entries1[2]
94 readme = entries1[2]
95 assert_equal '1', readme.lastrev.revision
95 assert_equal '1', readme.lastrev.revision
96 assert_equal '9d5b5b004199', readme.lastrev.identifier
96 assert_equal '9d5b5b004199', readme.lastrev.identifier
97 assert_equal '1', readme.changeset.revision
97 assert_equal '1', readme.changeset.revision
98 assert_equal '9d5b5b004199', readme.changeset.scmid
98 assert_equal '9d5b5b004199', readme.changeset.scmid
99 end
99 end
100 end
100 end
101 private :assert_entries
101 private :assert_entries
102
102
103 def test_entries_short_id
103 def test_entries_short_id
104 assert_equal 0, @repository.changesets.count
104 assert_equal 0, @repository.changesets.count
105 @repository.fetch_changesets
105 @repository.fetch_changesets
106 @project.reload
106 @project.reload
107 assert_equal NUM_REV, @repository.changesets.count
107 assert_equal NUM_REV, @repository.changesets.count
108 assert_entries
108 assert_entries
109 end
109 end
110
110
111 def test_entry_on_tip
111 def test_entry_on_tip
112 entry = @repository.entry
112 entry = @repository.entry
113 assert_kind_of Redmine::Scm::Adapters::Entry, entry
113 assert_kind_of Redmine::Scm::Adapters::Entry, entry
114 assert_equal "", entry.path
114 assert_equal "", entry.path
115 assert_equal 'dir', entry.kind
115 assert_equal 'dir', entry.kind
116 end
116 end
117
117
118 def assert_entry
118 def assert_entry(is_short_scmid=true)
119 hex = "0885933ad4f68d77c2649cd11f8311276e7ef7ce"
120 scmid = scmid_for_assert(hex, is_short_scmid)
119 ["README", "/README"].each do |path|
121 ["README", "/README"].each do |path|
120 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
122 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
121 entry = @repository.entry(path, rev)
123 entry = @repository.entry(path, rev)
122 assert_kind_of Redmine::Scm::Adapters::Entry, entry
124 assert_kind_of Redmine::Scm::Adapters::Entry, entry
123 assert_equal "README", entry.path
125 assert_equal "README", entry.path
124 assert_equal "file", entry.kind
126 assert_equal "file", entry.kind
125 assert_equal '0', entry.lastrev.revision
127 assert_equal '0', entry.lastrev.revision
126 assert_equal '0885933ad4f6', entry.lastrev.identifier
128 assert_equal scmid, entry.lastrev.identifier
127 end
129 end
128 end
130 end
129 ["sources", "/sources", "/sources/"].each do |path|
131 ["sources", "/sources", "/sources/"].each do |path|
130 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
132 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
131 entry = @repository.entry(path, rev)
133 entry = @repository.entry(path, rev)
132 assert_kind_of Redmine::Scm::Adapters::Entry, entry
134 assert_kind_of Redmine::Scm::Adapters::Entry, entry
133 assert_equal "sources", entry.path
135 assert_equal "sources", entry.path
134 assert_equal "dir", entry.kind
136 assert_equal "dir", entry.kind
135 end
137 end
136 end
138 end
137 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
139 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
138 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
140 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
139 entry = @repository.entry(path, rev)
141 entry = @repository.entry(path, rev)
140 assert_kind_of Redmine::Scm::Adapters::Entry, entry
142 assert_kind_of Redmine::Scm::Adapters::Entry, entry
141 assert_equal "sources/watchers_controller.rb", entry.path
143 assert_equal "sources/watchers_controller.rb", entry.path
142 assert_equal "file", entry.kind
144 assert_equal "file", entry.kind
143 assert_equal '0', entry.lastrev.revision
145 assert_equal '0', entry.lastrev.revision
144 assert_equal '0885933ad4f6', entry.lastrev.identifier
146 assert_equal scmid, entry.lastrev.identifier
145 end
147 end
146 end
148 end
147 end
149 end
148 private :assert_entry
150 private :assert_entry
149
151
150 def test_entry_short_id
152 def test_entry_short_id
151 assert_entry
153 assert_entry(true)
152 end
154 end
153
155
154 def test_fetch_changesets_from_scratch
156 def test_fetch_changesets_from_scratch
155 assert_equal 0, @repository.changesets.count
157 assert_equal 0, @repository.changesets.count
156 @repository.fetch_changesets
158 @repository.fetch_changesets
157 @project.reload
159 @project.reload
158 assert_equal NUM_REV, @repository.changesets.count
160 assert_equal NUM_REV, @repository.changesets.count
159 assert_equal 46, @repository.filechanges.count
161 assert_equal 46, @repository.filechanges.count
160 rev0 = @repository.changesets.find_by_revision('0')
162 rev0 = @repository.changesets.find_by_revision('0')
161 assert_equal "Initial import.\nThe repository contains 3 files.",
163 assert_equal "Initial import.\nThe repository contains 3 files.",
162 rev0.comments
164 rev0.comments
163 assert_equal "0885933ad4f6", rev0.scmid
165 assert_equal "0885933ad4f6", rev0.scmid
164 end
166 end
165
167
166 def test_fetch_changesets_incremental
168 def test_fetch_changesets_incremental
167 assert_equal 0, @repository.changesets.count
169 assert_equal 0, @repository.changesets.count
168 @repository.fetch_changesets
170 @repository.fetch_changesets
169 @project.reload
171 @project.reload
170 assert_equal NUM_REV, @repository.changesets.count
172 assert_equal NUM_REV, @repository.changesets.count
171 # Remove changesets with revision > 2
173 # Remove changesets with revision > 2
172 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
174 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
173 @project.reload
175 @project.reload
174 @repository.reload
176 @repository.reload
175 assert_equal 3, @repository.changesets.count
177 assert_equal 3, @repository.changesets.count
176
178
177 @repository.fetch_changesets
179 @repository.fetch_changesets
178 @project.reload
180 @project.reload
179 assert_equal NUM_REV, @repository.changesets.count
181 assert_equal NUM_REV, @repository.changesets.count
180 end
182 end
181
183
182 def test_isodatesec
184 def test_isodatesec
183 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
185 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
184 if @repository.scm.class.client_version_above?([1, 0])
186 if @repository.scm.class.client_version_above?([1, 0])
185 assert_equal 0, @repository.changesets.count
187 assert_equal 0, @repository.changesets.count
186 @repository.fetch_changesets
188 @repository.fetch_changesets
187 @project.reload
189 @project.reload
188 assert_equal NUM_REV, @repository.changesets.count
190 assert_equal NUM_REV, @repository.changesets.count
189 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
191 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
190 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
192 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
191 end
193 end
192 end
194 end
193
195
194 def test_changeset_order_by_revision
196 def test_changeset_order_by_revision
195 assert_equal 0, @repository.changesets.count
197 assert_equal 0, @repository.changesets.count
196 @repository.fetch_changesets
198 @repository.fetch_changesets
197 @project.reload
199 @project.reload
198 assert_equal NUM_REV, @repository.changesets.count
200 assert_equal NUM_REV, @repository.changesets.count
199
201
200 c0 = @repository.latest_changeset
202 c0 = @repository.latest_changeset
201 c1 = @repository.changesets.find_by_revision('0')
203 c1 = @repository.changesets.find_by_revision('0')
202 # sorted by revision (id), not by date
204 # sorted by revision (id), not by date
203 assert c0.revision.to_i > c1.revision.to_i
205 assert c0.revision.to_i > c1.revision.to_i
204 assert c0.committed_on < c1.committed_on
206 assert c0.committed_on < c1.committed_on
205 end
207 end
206
208
207 def test_latest_changesets
209 def test_latest_changesets
208 assert_equal 0, @repository.changesets.count
210 assert_equal 0, @repository.changesets.count
209 @repository.fetch_changesets
211 @repository.fetch_changesets
210 @project.reload
212 @project.reload
211 assert_equal NUM_REV, @repository.changesets.count
213 assert_equal NUM_REV, @repository.changesets.count
212
214
213 # with_limit
215 # with_limit
214 changesets = @repository.latest_changesets('', nil, 2)
216 changesets = @repository.latest_changesets('', nil, 2)
215 assert_equal %w|31 30|, changesets.collect(&:revision)
217 assert_equal %w|31 30|, changesets.collect(&:revision)
216
218
217 # with_filepath
219 # with_filepath
218 changesets = @repository.latest_changesets(
220 changesets = @repository.latest_changesets(
219 '/sql_escape/percent%dir/percent%file1.txt', nil)
221 '/sql_escape/percent%dir/percent%file1.txt', nil)
220 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
222 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
221
223
222 changesets = @repository.latest_changesets(
224 changesets = @repository.latest_changesets(
223 '/sql_escape/underscore_dir/understrike_file.txt', nil)
225 '/sql_escape/underscore_dir/understrike_file.txt', nil)
224 assert_equal %w|30 12 9|, changesets.collect(&:revision)
226 assert_equal %w|30 12 9|, changesets.collect(&:revision)
225
227
226 changesets = @repository.latest_changesets('README', nil)
228 changesets = @repository.latest_changesets('README', nil)
227 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
229 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
228
230
229 changesets = @repository.latest_changesets('README','8')
231 changesets = @repository.latest_changesets('README','8')
230 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
232 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
231
233
232 changesets = @repository.latest_changesets('README','8', 2)
234 changesets = @repository.latest_changesets('README','8', 2)
233 assert_equal %w|8 6|, changesets.collect(&:revision)
235 assert_equal %w|8 6|, changesets.collect(&:revision)
234
236
235 # with_dirpath
237 # with_dirpath
236 changesets = @repository.latest_changesets('images', nil)
238 changesets = @repository.latest_changesets('images', nil)
237 assert_equal %w|1 0|, changesets.collect(&:revision)
239 assert_equal %w|1 0|, changesets.collect(&:revision)
238
240
239 path = 'sql_escape/percent%dir'
241 path = 'sql_escape/percent%dir'
240 changesets = @repository.latest_changesets(path, nil)
242 changesets = @repository.latest_changesets(path, nil)
241 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
243 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
242
244
243 changesets = @repository.latest_changesets(path, '11')
245 changesets = @repository.latest_changesets(path, '11')
244 assert_equal %w|11 10 9|, changesets.collect(&:revision)
246 assert_equal %w|11 10 9|, changesets.collect(&:revision)
245
247
246 changesets = @repository.latest_changesets(path, '11', 2)
248 changesets = @repository.latest_changesets(path, '11', 2)
247 assert_equal %w|11 10|, changesets.collect(&:revision)
249 assert_equal %w|11 10|, changesets.collect(&:revision)
248
250
249 path = 'sql_escape/underscore_dir'
251 path = 'sql_escape/underscore_dir'
250 changesets = @repository.latest_changesets(path, nil)
252 changesets = @repository.latest_changesets(path, nil)
251 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
253 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
252
254
253 changesets = @repository.latest_changesets(path, '12')
255 changesets = @repository.latest_changesets(path, '12')
254 assert_equal %w|12 9|, changesets.collect(&:revision)
256 assert_equal %w|12 9|, changesets.collect(&:revision)
255
257
256 changesets = @repository.latest_changesets(path, '12', 1)
258 changesets = @repository.latest_changesets(path, '12', 1)
257 assert_equal %w|12|, changesets.collect(&:revision)
259 assert_equal %w|12|, changesets.collect(&:revision)
258 end
260 end
259
261
260 def assert_latest_changesets_tag
262 def assert_latest_changesets_tag
261 changesets = @repository.latest_changesets('', 'tag_test.00')
263 changesets = @repository.latest_changesets('', 'tag_test.00')
262 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
264 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
263 end
265 end
264 private :assert_latest_changesets_tag
266 private :assert_latest_changesets_tag
265
267
266 def test_latest_changesets_tag
268 def test_latest_changesets_tag
267 assert_equal 0, @repository.changesets.count
269 assert_equal 0, @repository.changesets.count
268 @repository.fetch_changesets
270 @repository.fetch_changesets
269 @project.reload
271 @project.reload
270 assert_equal NUM_REV, @repository.changesets.count
272 assert_equal NUM_REV, @repository.changesets.count
271 assert_latest_changesets_tag
273 assert_latest_changesets_tag
272 end
274 end
273
275
274 def test_latest_changesets_tag_with_path
276 def test_latest_changesets_tag_with_path
275 assert_equal 0, @repository.changesets.count
277 assert_equal 0, @repository.changesets.count
276 @repository.fetch_changesets
278 @repository.fetch_changesets
277 @project.reload
279 @project.reload
278 assert_equal NUM_REV, @repository.changesets.count
280 assert_equal NUM_REV, @repository.changesets.count
279
281
280 changesets = @repository.latest_changesets('sources', 'tag_test.00')
282 changesets = @repository.latest_changesets('sources', 'tag_test.00')
281 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
283 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
282 end
284 end
283
285
284 def test_latest_changesets_tag_with_limit
286 def test_latest_changesets_tag_with_limit
285 assert_equal 0, @repository.changesets.count
287 assert_equal 0, @repository.changesets.count
286 @repository.fetch_changesets
288 @repository.fetch_changesets
287 @project.reload
289 @project.reload
288 assert_equal NUM_REV, @repository.changesets.count
290 assert_equal NUM_REV, @repository.changesets.count
289
291
290 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
292 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
291 assert_equal %w|5 4|, changesets.collect(&:revision)
293 assert_equal %w|5 4|, changesets.collect(&:revision)
292
294
293 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
295 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
294 assert_equal %w|4 3|, changesets.collect(&:revision)
296 assert_equal %w|4 3|, changesets.collect(&:revision)
295 end
297 end
296
298
297 def test_latest_changesets_branch
299 def test_latest_changesets_branch
298 assert_equal 0, @repository.changesets.count
300 assert_equal 0, @repository.changesets.count
299 @repository.fetch_changesets
301 @repository.fetch_changesets
300 @project.reload
302 @project.reload
301 assert_equal NUM_REV, @repository.changesets.count
303 assert_equal NUM_REV, @repository.changesets.count
302
304
303 if @repository.scm.class.client_version_above?([1, 6])
305 if @repository.scm.class.client_version_above?([1, 6])
304 changesets = @repository.latest_changesets('', @branch_char_1)
306 changesets = @repository.latest_changesets('', @branch_char_1)
305 assert_equal %w|27 26|, changesets.collect(&:revision)
307 assert_equal %w|27 26|, changesets.collect(&:revision)
306 end
308 end
307
309
308 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
310 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
309 assert_equal %w|27|, changesets.collect(&:revision)
311 assert_equal %w|27|, changesets.collect(&:revision)
310 end
312 end
311
313
312 def assert_latest_changesets_default_branch
314 def assert_latest_changesets_default_branch
313 changesets = @repository.latest_changesets('', 'default')
315 changesets = @repository.latest_changesets('', 'default')
314 assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
316 assert_equal %w|31 28 24 6 4 3 2 1 0|, changesets.collect(&:revision)
315 end
317 end
316 private :assert_latest_changesets_default_branch
318 private :assert_latest_changesets_default_branch
317
319
318 def test_latest_changesets_default_branch
320 def test_latest_changesets_default_branch
319 assert_equal 0, @repository.changesets.count
321 assert_equal 0, @repository.changesets.count
320 @repository.fetch_changesets
322 @repository.fetch_changesets
321 @project.reload
323 @project.reload
322 assert_equal NUM_REV, @repository.changesets.count
324 assert_equal NUM_REV, @repository.changesets.count
323 assert_latest_changesets_default_branch
325 assert_latest_changesets_default_branch
324 end
326 end
325
327
326 def assert_copied_files(is_short_scmid=true)
328 def assert_copied_files(is_short_scmid=true)
327 cs1 = @repository.changesets.find_by_revision('13')
329 cs1 = @repository.changesets.find_by_revision('13')
328 assert_not_nil cs1
330 assert_not_nil cs1
329 c1 = cs1.filechanges.sort_by(&:path)
331 c1 = cs1.filechanges.sort_by(&:path)
330 assert_equal 2, c1.size
332 assert_equal 2, c1.size
331
333
332 hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
334 hex1 = "3a330eb329586ea2adb3f83237c23310e744ebe9"
333 scmid1 = scmid_for_assert(hex1, is_short_scmid)
335 scmid1 = scmid_for_assert(hex1, is_short_scmid)
334 assert_equal 'A', c1[0].action
336 assert_equal 'A', c1[0].action
335 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
337 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
336 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
338 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
337 assert_equal scmid1, c1[0].from_revision
339 assert_equal scmid1, c1[0].from_revision
338
340
339 assert_equal 'A', c1[1].action
341 assert_equal 'A', c1[1].action
340 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
342 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
341 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
343 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
342
344
343 cs2 = @repository.changesets.find_by_revision('15')
345 cs2 = @repository.changesets.find_by_revision('15')
344 c2 = cs2.filechanges
346 c2 = cs2.filechanges
345 assert_equal 1, c2.size
347 assert_equal 1, c2.size
346
348
347 hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
349 hex2 = "933ca60293d78f7c7979dd123cc0c02431683575"
348 scmid2 = scmid_for_assert(hex2, is_short_scmid)
350 scmid2 = scmid_for_assert(hex2, is_short_scmid)
349 assert_equal 'A', c2[0].action
351 assert_equal 'A', c2[0].action
350 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
352 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
351 assert_equal '/README', c2[0].from_path
353 assert_equal '/README', c2[0].from_path
352 assert_equal scmid2, c2[0].from_revision
354 assert_equal scmid2, c2[0].from_revision
353
355
354 cs3 = @repository.changesets.find_by_revision('19')
356 cs3 = @repository.changesets.find_by_revision('19')
355 c3 = cs3.filechanges
357 c3 = cs3.filechanges
356
358
357 hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
359 hex3 = "5d9891a1b4258ea256552aa856e388f2da28256a"
358 scmid3 = scmid_for_assert(hex3, is_short_scmid)
360 scmid3 = scmid_for_assert(hex3, is_short_scmid)
359 assert_equal 1, c3.size
361 assert_equal 1, c3.size
360 assert_equal 'A', c3[0].action
362 assert_equal 'A', c3[0].action
361 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
363 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
362 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
364 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
363 assert_equal scmid3, c3[0].from_revision
365 assert_equal scmid3, c3[0].from_revision
364 end
366 end
365 private :assert_copied_files
367 private :assert_copied_files
366
368
367 def test_copied_files_short_id
369 def test_copied_files_short_id
368 assert_equal 0, @repository.changesets.count
370 assert_equal 0, @repository.changesets.count
369 @repository.fetch_changesets
371 @repository.fetch_changesets
370 @project.reload
372 @project.reload
371 assert_equal NUM_REV, @repository.changesets.count
373 assert_equal NUM_REV, @repository.changesets.count
372 assert_copied_files(true)
374 assert_copied_files(true)
373 end
375 end
374
376
375 def test_find_changeset_by_name
377 def test_find_changeset_by_name
376 assert_equal 0, @repository.changesets.count
378 assert_equal 0, @repository.changesets.count
377 @repository.fetch_changesets
379 @repository.fetch_changesets
378 @project.reload
380 @project.reload
379 assert_equal NUM_REV, @repository.changesets.count
381 assert_equal NUM_REV, @repository.changesets.count
380 %w|2 400bb8672109 400|.each do |r|
382 %w|2 400bb8672109 400|.each do |r|
381 assert_equal '2', @repository.find_changeset_by_name(r).revision
383 assert_equal '2', @repository.find_changeset_by_name(r).revision
382 end
384 end
383 end
385 end
384
386
385 def test_find_changeset_by_invalid_name
387 def test_find_changeset_by_invalid_name
386 assert_equal 0, @repository.changesets.count
388 assert_equal 0, @repository.changesets.count
387 @repository.fetch_changesets
389 @repository.fetch_changesets
388 @project.reload
390 @project.reload
389 assert_equal NUM_REV, @repository.changesets.count
391 assert_equal NUM_REV, @repository.changesets.count
390 assert_nil @repository.find_changeset_by_name('100000')
392 assert_nil @repository.find_changeset_by_name('100000')
391 end
393 end
392
394
393 def test_identifier
395 def test_identifier
394 assert_equal 0, @repository.changesets.count
396 assert_equal 0, @repository.changesets.count
395 @repository.fetch_changesets
397 @repository.fetch_changesets
396 @project.reload
398 @project.reload
397 assert_equal NUM_REV, @repository.changesets.count
399 assert_equal NUM_REV, @repository.changesets.count
398 c = @repository.changesets.find_by_revision('2')
400 c = @repository.changesets.find_by_revision('2')
399 assert_equal c.scmid, c.identifier
401 assert_equal c.scmid, c.identifier
400 end
402 end
401
403
402 def test_format_identifier
404 def test_format_identifier
403 assert_equal 0, @repository.changesets.count
405 assert_equal 0, @repository.changesets.count
404 @repository.fetch_changesets
406 @repository.fetch_changesets
405 @project.reload
407 @project.reload
406 assert_equal NUM_REV, @repository.changesets.count
408 assert_equal NUM_REV, @repository.changesets.count
407 c = @repository.changesets.find_by_revision('2')
409 c = @repository.changesets.find_by_revision('2')
408 assert_equal '2:400bb8672109', c.format_identifier
410 assert_equal '2:400bb8672109', c.format_identifier
409 end
411 end
410
412
411 def test_format_identifier_long_id
413 def test_format_identifier_long_id
412 assert_equal 0, @repository.changesets.count
414 assert_equal 0, @repository.changesets.count
413 Changeset.create!(:repository => @repository,
415 Changeset.create!(:repository => @repository,
414 :committed_on => Time.now,
416 :committed_on => Time.now,
415 :revision => '0',
417 :revision => '0',
416 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
418 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
417 :comments => 'test')
419 :comments => 'test')
418 c = @repository.changesets.find_by_revision('0')
420 c = @repository.changesets.find_by_revision('0')
419 assert_equal '0:0885933ad4f6', c.format_identifier
421 assert_equal '0:0885933ad4f6', c.format_identifier
420 end
422 end
421
423
422 def test_find_changeset_by_empty_name
424 def test_find_changeset_by_empty_name
423 assert_equal 0, @repository.changesets.count
425 assert_equal 0, @repository.changesets.count
424 @repository.fetch_changesets
426 @repository.fetch_changesets
425 @project.reload
427 @project.reload
426 assert_equal NUM_REV, @repository.changesets.count
428 assert_equal NUM_REV, @repository.changesets.count
427 ['', ' ', nil].each do |r|
429 ['', ' ', nil].each do |r|
428 assert_nil @repository.find_changeset_by_name(r)
430 assert_nil @repository.find_changeset_by_name(r)
429 end
431 end
430 end
432 end
431
433
432 def assert_parents
434 def assert_parents
433 r1 = @repository.changesets.find_by_revision('0')
435 r1 = @repository.changesets.find_by_revision('0')
434 assert_equal [], r1.parents
436 assert_equal [], r1.parents
435 r2 = @repository.changesets.find_by_revision('1')
437 r2 = @repository.changesets.find_by_revision('1')
436 assert_equal 1, r2.parents.length
438 assert_equal 1, r2.parents.length
437 assert_equal "0885933ad4f6",
439 assert_equal "0885933ad4f6",
438 r2.parents[0].identifier
440 r2.parents[0].identifier
439 r3 = @repository.changesets.find_by_revision('30')
441 r3 = @repository.changesets.find_by_revision('30')
440 assert_equal 2, r3.parents.length
442 assert_equal 2, r3.parents.length
441 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
443 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
442 assert_equal "3a330eb32958", r4[0]
444 assert_equal "3a330eb32958", r4[0]
443 assert_equal "a94b0528f24f", r4[1]
445 assert_equal "a94b0528f24f", r4[1]
444 end
446 end
445 private :assert_parents
447 private :assert_parents
446
448
447 def test_parents_short_id
449 def test_parents_short_id
448 assert_equal 0, @repository.changesets.count
450 assert_equal 0, @repository.changesets.count
449 @repository.fetch_changesets
451 @repository.fetch_changesets
450 @project.reload
452 @project.reload
451 assert_equal NUM_REV, @repository.changesets.count
453 assert_equal NUM_REV, @repository.changesets.count
452 assert_parents
454 assert_parents
453 end
455 end
454
456
455 def test_activities
457 def test_activities
456 c = Changeset.new(:repository => @repository,
458 c = Changeset.new(:repository => @repository,
457 :committed_on => Time.now,
459 :committed_on => Time.now,
458 :revision => '123',
460 :revision => '123',
459 :scmid => 'abc400bb8672',
461 :scmid => 'abc400bb8672',
460 :comments => 'test')
462 :comments => 'test')
461 assert c.event_title.include?('123:abc400bb8672:')
463 assert c.event_title.include?('123:abc400bb8672:')
462 assert_equal 'abc400bb8672', c.event_url[:rev]
464 assert_equal 'abc400bb8672', c.event_url[:rev]
463 end
465 end
464
466
465 def test_previous
467 def test_previous
466 assert_equal 0, @repository.changesets.count
468 assert_equal 0, @repository.changesets.count
467 @repository.fetch_changesets
469 @repository.fetch_changesets
468 @project.reload
470 @project.reload
469 assert_equal NUM_REV, @repository.changesets.count
471 assert_equal NUM_REV, @repository.changesets.count
470 %w|28 3ae45e2d177d 3ae45|.each do |r1|
472 %w|28 3ae45e2d177d 3ae45|.each do |r1|
471 changeset = @repository.find_changeset_by_name(r1)
473 changeset = @repository.find_changeset_by_name(r1)
472 %w|27 7bbf4c738e71 7bbf|.each do |r2|
474 %w|27 7bbf4c738e71 7bbf|.each do |r2|
473 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
475 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
474 end
476 end
475 end
477 end
476 end
478 end
477
479
478 def test_previous_nil
480 def test_previous_nil
479 assert_equal 0, @repository.changesets.count
481 assert_equal 0, @repository.changesets.count
480 @repository.fetch_changesets
482 @repository.fetch_changesets
481 @project.reload
483 @project.reload
482 assert_equal NUM_REV, @repository.changesets.count
484 assert_equal NUM_REV, @repository.changesets.count
483 %w|0 0885933ad4f6 0885|.each do |r1|
485 %w|0 0885933ad4f6 0885|.each do |r1|
484 changeset = @repository.find_changeset_by_name(r1)
486 changeset = @repository.find_changeset_by_name(r1)
485 assert_nil changeset.previous
487 assert_nil changeset.previous
486 end
488 end
487 end
489 end
488
490
489 def test_next
491 def test_next
490 assert_equal 0, @repository.changesets.count
492 assert_equal 0, @repository.changesets.count
491 @repository.fetch_changesets
493 @repository.fetch_changesets
492 @project.reload
494 @project.reload
493 assert_equal NUM_REV, @repository.changesets.count
495 assert_equal NUM_REV, @repository.changesets.count
494 %w|27 7bbf4c738e71 7bbf|.each do |r2|
496 %w|27 7bbf4c738e71 7bbf|.each do |r2|
495 changeset = @repository.find_changeset_by_name(r2)
497 changeset = @repository.find_changeset_by_name(r2)
496 %w|28 3ae45e2d177d 3ae45|.each do |r1|
498 %w|28 3ae45e2d177d 3ae45|.each do |r1|
497 assert_equal @repository.find_changeset_by_name(r1), changeset.next
499 assert_equal @repository.find_changeset_by_name(r1), changeset.next
498 end
500 end
499 end
501 end
500 end
502 end
501
503
502 def test_next_nil
504 def test_next_nil
503 assert_equal 0, @repository.changesets.count
505 assert_equal 0, @repository.changesets.count
504 @repository.fetch_changesets
506 @repository.fetch_changesets
505 @project.reload
507 @project.reload
506 assert_equal NUM_REV, @repository.changesets.count
508 assert_equal NUM_REV, @repository.changesets.count
507 %w|31 31eeee7395c8 31eee|.each do |r1|
509 %w|31 31eeee7395c8 31eee|.each do |r1|
508 changeset = @repository.find_changeset_by_name(r1)
510 changeset = @repository.find_changeset_by_name(r1)
509 assert_nil changeset.next
511 assert_nil changeset.next
510 end
512 end
511 end
513 end
512
514
513 def test_scmid_for_assert
515 def test_scmid_for_assert
514 rev = "0123456789012345678901234567890123456789"
516 rev = "0123456789012345678901234567890123456789"
515 assert_equal rev, scmid_for_assert(rev, false)
517 assert_equal rev, scmid_for_assert(rev, false)
516 assert_equal "012345678901", scmid_for_assert(rev, true)
518 assert_equal "012345678901", scmid_for_assert(rev, true)
517 end
519 end
518
520
519 private
521 private
520
522
521 def scmid_for_assert(hex, is_short=true)
523 def scmid_for_assert(hex, is_short=true)
522 is_short ? hex[0, 12] : hex
524 is_short ? hex[0, 12] : hex
523 end
525 end
524 else
526 else
525 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
527 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
526 def test_fake; assert true end
528 def test_fake; assert true end
527 end
529 end
528 end
530 end
General Comments 0
You need to be logged in to leave comments. Login now