##// END OF EJS Templates
scm: mercurial: add model entry test (#14361)...
Toshi MARUYAMA -
r12483:07d7b47ddcfa
parent child
Show More
@@ -1,420 +1,458
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 test_entries_short_id
88 def test_entries_short_id
89 assert_equal 0, @repository.changesets.count
89 assert_equal 0, @repository.changesets.count
90 @repository.fetch_changesets
90 @repository.fetch_changesets
91 @project.reload
91 @project.reload
92 assert_equal NUM_REV, @repository.changesets.count
92 assert_equal NUM_REV, @repository.changesets.count
93 [2, '400bb8672109', '400', 400].each do |r|
93 [2, '400bb8672109', '400', 400].each do |r|
94 entries1 = @repository.entries(nil, r)
94 entries1 = @repository.entries(nil, r)
95 assert entries1
95 assert entries1
96 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
96 assert_kind_of Redmine::Scm::Adapters::Entries, entries1
97 assert_equal 3, entries1.size
97 assert_equal 3, entries1.size
98 readme = entries1[2]
98 readme = entries1[2]
99 assert_equal '1', readme.lastrev.revision
99 assert_equal '1', readme.lastrev.revision
100 assert_equal '9d5b5b004199', readme.lastrev.identifier
100 assert_equal '9d5b5b004199', readme.lastrev.identifier
101 assert_equal '1', readme.changeset.revision
101 assert_equal '1', readme.changeset.revision
102 assert_equal '9d5b5b004199', readme.changeset.scmid
102 assert_equal '9d5b5b004199', readme.changeset.scmid
103 end
103 end
104 end
104 end
105
105
106 def test_entry_on_tip
107 entry = @repository.entry
108 assert_kind_of Redmine::Scm::Adapters::Entry, entry
109 assert_equal "", entry.path
110 assert_equal 'dir', entry.kind
111 end
112
113 def test_entry_short_id
114 ["README", "/README"].each do |path|
115 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
116 entry = @repository.entry(path, rev)
117 assert_kind_of Redmine::Scm::Adapters::Entry, entry
118 assert_equal "README", entry.path
119 assert_equal "file", entry.kind
120 assert_equal '0', entry.lastrev.revision
121 assert_equal '0885933ad4f6', entry.lastrev.identifier
122 end
123 end
124 ["sources", "/sources", "/sources/"].each do |path|
125 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
126 entry = @repository.entry(path, rev)
127 assert_kind_of Redmine::Scm::Adapters::Entry, entry
128 assert_equal "sources", entry.path
129 assert_equal "dir", entry.kind
130 end
131 end
132 ["sources/watchers_controller.rb", "/sources/watchers_controller.rb"].each do |path|
133 ["0", "0885933ad4f6", "0885933ad4f68d77c2649cd11f8311276e7ef7ce"].each do |rev|
134 entry = @repository.entry(path, rev)
135 assert_kind_of Redmine::Scm::Adapters::Entry, entry
136 assert_equal "sources/watchers_controller.rb", entry.path
137 assert_equal "file", entry.kind
138 assert_equal '0', entry.lastrev.revision
139 assert_equal '0885933ad4f6', entry.lastrev.identifier
140 end
141 end
142 end
143
106 def test_fetch_changesets_from_scratch
144 def test_fetch_changesets_from_scratch
107 assert_equal 0, @repository.changesets.count
145 assert_equal 0, @repository.changesets.count
108 @repository.fetch_changesets
146 @repository.fetch_changesets
109 @project.reload
147 @project.reload
110 assert_equal NUM_REV, @repository.changesets.count
148 assert_equal NUM_REV, @repository.changesets.count
111 assert_equal 46, @repository.filechanges.count
149 assert_equal 46, @repository.filechanges.count
112 rev0 = @repository.changesets.find_by_revision('0')
150 rev0 = @repository.changesets.find_by_revision('0')
113 assert_equal "Initial import.\nThe repository contains 3 files.",
151 assert_equal "Initial import.\nThe repository contains 3 files.",
114 rev0.comments
152 rev0.comments
115 assert_equal "0885933ad4f6", rev0.scmid
153 assert_equal "0885933ad4f6", rev0.scmid
116 end
154 end
117
155
118 def test_fetch_changesets_incremental
156 def test_fetch_changesets_incremental
119 assert_equal 0, @repository.changesets.count
157 assert_equal 0, @repository.changesets.count
120 @repository.fetch_changesets
158 @repository.fetch_changesets
121 @project.reload
159 @project.reload
122 assert_equal NUM_REV, @repository.changesets.count
160 assert_equal NUM_REV, @repository.changesets.count
123 # Remove changesets with revision > 2
161 # Remove changesets with revision > 2
124 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
162 @repository.changesets.each {|c| c.destroy if c.revision.to_i > 2}
125 @project.reload
163 @project.reload
126 @repository.reload
164 @repository.reload
127 assert_equal 3, @repository.changesets.count
165 assert_equal 3, @repository.changesets.count
128
166
129 @repository.fetch_changesets
167 @repository.fetch_changesets
130 @project.reload
168 @project.reload
131 assert_equal NUM_REV, @repository.changesets.count
169 assert_equal NUM_REV, @repository.changesets.count
132 end
170 end
133
171
134 def test_isodatesec
172 def test_isodatesec
135 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
173 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
136 if @repository.scm.class.client_version_above?([1, 0])
174 if @repository.scm.class.client_version_above?([1, 0])
137 assert_equal 0, @repository.changesets.count
175 assert_equal 0, @repository.changesets.count
138 @repository.fetch_changesets
176 @repository.fetch_changesets
139 @project.reload
177 @project.reload
140 assert_equal NUM_REV, @repository.changesets.count
178 assert_equal NUM_REV, @repository.changesets.count
141 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
179 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
142 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
180 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
143 end
181 end
144 end
182 end
145
183
146 def test_changeset_order_by_revision
184 def test_changeset_order_by_revision
147 assert_equal 0, @repository.changesets.count
185 assert_equal 0, @repository.changesets.count
148 @repository.fetch_changesets
186 @repository.fetch_changesets
149 @project.reload
187 @project.reload
150 assert_equal NUM_REV, @repository.changesets.count
188 assert_equal NUM_REV, @repository.changesets.count
151
189
152 c0 = @repository.latest_changeset
190 c0 = @repository.latest_changeset
153 c1 = @repository.changesets.find_by_revision('0')
191 c1 = @repository.changesets.find_by_revision('0')
154 # sorted by revision (id), not by date
192 # sorted by revision (id), not by date
155 assert c0.revision.to_i > c1.revision.to_i
193 assert c0.revision.to_i > c1.revision.to_i
156 assert c0.committed_on < c1.committed_on
194 assert c0.committed_on < c1.committed_on
157 end
195 end
158
196
159 def test_latest_changesets
197 def test_latest_changesets
160 assert_equal 0, @repository.changesets.count
198 assert_equal 0, @repository.changesets.count
161 @repository.fetch_changesets
199 @repository.fetch_changesets
162 @project.reload
200 @project.reload
163 assert_equal NUM_REV, @repository.changesets.count
201 assert_equal NUM_REV, @repository.changesets.count
164
202
165 # with_limit
203 # with_limit
166 changesets = @repository.latest_changesets('', nil, 2)
204 changesets = @repository.latest_changesets('', nil, 2)
167 assert_equal %w|31 30|, changesets.collect(&:revision)
205 assert_equal %w|31 30|, changesets.collect(&:revision)
168
206
169 # with_filepath
207 # with_filepath
170 changesets = @repository.latest_changesets(
208 changesets = @repository.latest_changesets(
171 '/sql_escape/percent%dir/percent%file1.txt', nil)
209 '/sql_escape/percent%dir/percent%file1.txt', nil)
172 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
210 assert_equal %w|30 11 10 9|, changesets.collect(&:revision)
173
211
174 changesets = @repository.latest_changesets(
212 changesets = @repository.latest_changesets(
175 '/sql_escape/underscore_dir/understrike_file.txt', nil)
213 '/sql_escape/underscore_dir/understrike_file.txt', nil)
176 assert_equal %w|30 12 9|, changesets.collect(&:revision)
214 assert_equal %w|30 12 9|, changesets.collect(&:revision)
177
215
178 changesets = @repository.latest_changesets('README', nil)
216 changesets = @repository.latest_changesets('README', nil)
179 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
217 assert_equal %w|31 30 28 17 8 6 1 0|, changesets.collect(&:revision)
180
218
181 changesets = @repository.latest_changesets('README','8')
219 changesets = @repository.latest_changesets('README','8')
182 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
220 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
183
221
184 changesets = @repository.latest_changesets('README','8', 2)
222 changesets = @repository.latest_changesets('README','8', 2)
185 assert_equal %w|8 6|, changesets.collect(&:revision)
223 assert_equal %w|8 6|, changesets.collect(&:revision)
186
224
187 # with_dirpath
225 # with_dirpath
188 changesets = @repository.latest_changesets('images', nil)
226 changesets = @repository.latest_changesets('images', nil)
189 assert_equal %w|1 0|, changesets.collect(&:revision)
227 assert_equal %w|1 0|, changesets.collect(&:revision)
190
228
191 path = 'sql_escape/percent%dir'
229 path = 'sql_escape/percent%dir'
192 changesets = @repository.latest_changesets(path, nil)
230 changesets = @repository.latest_changesets(path, nil)
193 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
231 assert_equal %w|30 13 11 10 9|, changesets.collect(&:revision)
194
232
195 changesets = @repository.latest_changesets(path, '11')
233 changesets = @repository.latest_changesets(path, '11')
196 assert_equal %w|11 10 9|, changesets.collect(&:revision)
234 assert_equal %w|11 10 9|, changesets.collect(&:revision)
197
235
198 changesets = @repository.latest_changesets(path, '11', 2)
236 changesets = @repository.latest_changesets(path, '11', 2)
199 assert_equal %w|11 10|, changesets.collect(&:revision)
237 assert_equal %w|11 10|, changesets.collect(&:revision)
200
238
201 path = 'sql_escape/underscore_dir'
239 path = 'sql_escape/underscore_dir'
202 changesets = @repository.latest_changesets(path, nil)
240 changesets = @repository.latest_changesets(path, nil)
203 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
241 assert_equal %w|30 13 12 9|, changesets.collect(&:revision)
204
242
205 changesets = @repository.latest_changesets(path, '12')
243 changesets = @repository.latest_changesets(path, '12')
206 assert_equal %w|12 9|, changesets.collect(&:revision)
244 assert_equal %w|12 9|, changesets.collect(&:revision)
207
245
208 changesets = @repository.latest_changesets(path, '12', 1)
246 changesets = @repository.latest_changesets(path, '12', 1)
209 assert_equal %w|12|, changesets.collect(&:revision)
247 assert_equal %w|12|, changesets.collect(&:revision)
210 end
248 end
211
249
212 def test_latest_changesets_tag
250 def test_latest_changesets_tag
213 assert_equal 0, @repository.changesets.count
251 assert_equal 0, @repository.changesets.count
214 @repository.fetch_changesets
252 @repository.fetch_changesets
215 @project.reload
253 @project.reload
216 assert_equal NUM_REV, @repository.changesets.count
254 assert_equal NUM_REV, @repository.changesets.count
217
255
218 changesets = @repository.latest_changesets('', 'tag_test.00')
256 changesets = @repository.latest_changesets('', 'tag_test.00')
219 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
257 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
220
258
221 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
259 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
222 assert_equal %w|5 4|, changesets.collect(&:revision)
260 assert_equal %w|5 4|, changesets.collect(&:revision)
223
261
224 changesets = @repository.latest_changesets('sources', 'tag_test.00')
262 changesets = @repository.latest_changesets('sources', 'tag_test.00')
225 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
263 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
226
264
227 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
265 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
228 assert_equal %w|4 3|, changesets.collect(&:revision)
266 assert_equal %w|4 3|, changesets.collect(&:revision)
229 end
267 end
230
268
231 def test_latest_changesets_branch
269 def test_latest_changesets_branch
232 assert_equal 0, @repository.changesets.count
270 assert_equal 0, @repository.changesets.count
233 @repository.fetch_changesets
271 @repository.fetch_changesets
234 @project.reload
272 @project.reload
235 assert_equal NUM_REV, @repository.changesets.count
273 assert_equal NUM_REV, @repository.changesets.count
236
274
237 if @repository.scm.class.client_version_above?([1, 6])
275 if @repository.scm.class.client_version_above?([1, 6])
238 changesets = @repository.latest_changesets('', @branch_char_1)
276 changesets = @repository.latest_changesets('', @branch_char_1)
239 assert_equal %w|27 26|, changesets.collect(&:revision)
277 assert_equal %w|27 26|, changesets.collect(&:revision)
240 end
278 end
241
279
242 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
280 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
243 assert_equal %w|27|, changesets.collect(&:revision)
281 assert_equal %w|27|, changesets.collect(&:revision)
244 end
282 end
245
283
246 def test_copied_files
284 def test_copied_files
247 assert_equal 0, @repository.changesets.count
285 assert_equal 0, @repository.changesets.count
248 @repository.fetch_changesets
286 @repository.fetch_changesets
249 @project.reload
287 @project.reload
250 assert_equal NUM_REV, @repository.changesets.count
288 assert_equal NUM_REV, @repository.changesets.count
251
289
252 cs1 = @repository.changesets.find_by_revision('13')
290 cs1 = @repository.changesets.find_by_revision('13')
253 assert_not_nil cs1
291 assert_not_nil cs1
254 c1 = cs1.filechanges.sort_by(&:path)
292 c1 = cs1.filechanges.sort_by(&:path)
255 assert_equal 2, c1.size
293 assert_equal 2, c1.size
256
294
257 assert_equal 'A', c1[0].action
295 assert_equal 'A', c1[0].action
258 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
296 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
259 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
297 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
260 assert_equal '3a330eb32958', c1[0].from_revision
298 assert_equal '3a330eb32958', c1[0].from_revision
261
299
262 assert_equal 'A', c1[1].action
300 assert_equal 'A', c1[1].action
263 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
301 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
264 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
302 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
265
303
266 cs2 = @repository.changesets.find_by_revision('15')
304 cs2 = @repository.changesets.find_by_revision('15')
267 c2 = cs2.filechanges
305 c2 = cs2.filechanges
268 assert_equal 1, c2.size
306 assert_equal 1, c2.size
269
307
270 assert_equal 'A', c2[0].action
308 assert_equal 'A', c2[0].action
271 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
309 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
272 assert_equal '/README', c2[0].from_path
310 assert_equal '/README', c2[0].from_path
273 assert_equal '933ca60293d7', c2[0].from_revision
311 assert_equal '933ca60293d7', c2[0].from_revision
274
312
275 cs3 = @repository.changesets.find_by_revision('19')
313 cs3 = @repository.changesets.find_by_revision('19')
276 c3 = cs3.filechanges
314 c3 = cs3.filechanges
277 assert_equal 1, c3.size
315 assert_equal 1, c3.size
278 assert_equal 'A', c3[0].action
316 assert_equal 'A', c3[0].action
279 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
317 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
280 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
318 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
281 assert_equal '5d9891a1b425', c3[0].from_revision
319 assert_equal '5d9891a1b425', c3[0].from_revision
282 end
320 end
283
321
284 def test_find_changeset_by_name
322 def test_find_changeset_by_name
285 assert_equal 0, @repository.changesets.count
323 assert_equal 0, @repository.changesets.count
286 @repository.fetch_changesets
324 @repository.fetch_changesets
287 @project.reload
325 @project.reload
288 assert_equal NUM_REV, @repository.changesets.count
326 assert_equal NUM_REV, @repository.changesets.count
289 %w|2 400bb8672109 400|.each do |r|
327 %w|2 400bb8672109 400|.each do |r|
290 assert_equal '2', @repository.find_changeset_by_name(r).revision
328 assert_equal '2', @repository.find_changeset_by_name(r).revision
291 end
329 end
292 end
330 end
293
331
294 def test_find_changeset_by_invalid_name
332 def test_find_changeset_by_invalid_name
295 assert_equal 0, @repository.changesets.count
333 assert_equal 0, @repository.changesets.count
296 @repository.fetch_changesets
334 @repository.fetch_changesets
297 @project.reload
335 @project.reload
298 assert_equal NUM_REV, @repository.changesets.count
336 assert_equal NUM_REV, @repository.changesets.count
299 assert_nil @repository.find_changeset_by_name('100000')
337 assert_nil @repository.find_changeset_by_name('100000')
300 end
338 end
301
339
302 def test_identifier
340 def test_identifier
303 assert_equal 0, @repository.changesets.count
341 assert_equal 0, @repository.changesets.count
304 @repository.fetch_changesets
342 @repository.fetch_changesets
305 @project.reload
343 @project.reload
306 assert_equal NUM_REV, @repository.changesets.count
344 assert_equal NUM_REV, @repository.changesets.count
307 c = @repository.changesets.find_by_revision('2')
345 c = @repository.changesets.find_by_revision('2')
308 assert_equal c.scmid, c.identifier
346 assert_equal c.scmid, c.identifier
309 end
347 end
310
348
311 def test_format_identifier
349 def test_format_identifier
312 assert_equal 0, @repository.changesets.count
350 assert_equal 0, @repository.changesets.count
313 @repository.fetch_changesets
351 @repository.fetch_changesets
314 @project.reload
352 @project.reload
315 assert_equal NUM_REV, @repository.changesets.count
353 assert_equal NUM_REV, @repository.changesets.count
316 c = @repository.changesets.find_by_revision('2')
354 c = @repository.changesets.find_by_revision('2')
317 assert_equal '2:400bb8672109', c.format_identifier
355 assert_equal '2:400bb8672109', c.format_identifier
318 end
356 end
319
357
320 def test_format_identifier_long_id
358 def test_format_identifier_long_id
321 assert_equal 0, @repository.changesets.count
359 assert_equal 0, @repository.changesets.count
322 Changeset.create!(:repository => @repository,
360 Changeset.create!(:repository => @repository,
323 :committed_on => Time.now,
361 :committed_on => Time.now,
324 :revision => '0',
362 :revision => '0',
325 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
363 :scmid => '0885933ad4f68d77c2649cd11f8311276e7ef7ce',
326 :comments => 'test')
364 :comments => 'test')
327 c = @repository.changesets.find_by_revision('0')
365 c = @repository.changesets.find_by_revision('0')
328 assert_equal '0:0885933ad4f6', c.format_identifier
366 assert_equal '0:0885933ad4f6', c.format_identifier
329 end
367 end
330
368
331 def test_find_changeset_by_empty_name
369 def test_find_changeset_by_empty_name
332 assert_equal 0, @repository.changesets.count
370 assert_equal 0, @repository.changesets.count
333 @repository.fetch_changesets
371 @repository.fetch_changesets
334 @project.reload
372 @project.reload
335 assert_equal NUM_REV, @repository.changesets.count
373 assert_equal NUM_REV, @repository.changesets.count
336 ['', ' ', nil].each do |r|
374 ['', ' ', nil].each do |r|
337 assert_nil @repository.find_changeset_by_name(r)
375 assert_nil @repository.find_changeset_by_name(r)
338 end
376 end
339 end
377 end
340
378
341 def test_parents
379 def test_parents
342 assert_equal 0, @repository.changesets.count
380 assert_equal 0, @repository.changesets.count
343 @repository.fetch_changesets
381 @repository.fetch_changesets
344 @project.reload
382 @project.reload
345 assert_equal NUM_REV, @repository.changesets.count
383 assert_equal NUM_REV, @repository.changesets.count
346 r1 = @repository.changesets.find_by_revision('0')
384 r1 = @repository.changesets.find_by_revision('0')
347 assert_equal [], r1.parents
385 assert_equal [], r1.parents
348 r2 = @repository.changesets.find_by_revision('1')
386 r2 = @repository.changesets.find_by_revision('1')
349 assert_equal 1, r2.parents.length
387 assert_equal 1, r2.parents.length
350 assert_equal "0885933ad4f6",
388 assert_equal "0885933ad4f6",
351 r2.parents[0].identifier
389 r2.parents[0].identifier
352 r3 = @repository.changesets.find_by_revision('30')
390 r3 = @repository.changesets.find_by_revision('30')
353 assert_equal 2, r3.parents.length
391 assert_equal 2, r3.parents.length
354 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
392 r4 = [r3.parents[0].identifier, r3.parents[1].identifier].sort
355 assert_equal "3a330eb32958", r4[0]
393 assert_equal "3a330eb32958", r4[0]
356 assert_equal "a94b0528f24f", r4[1]
394 assert_equal "a94b0528f24f", r4[1]
357 end
395 end
358
396
359 def test_activities
397 def test_activities
360 c = Changeset.new(:repository => @repository,
398 c = Changeset.new(:repository => @repository,
361 :committed_on => Time.now,
399 :committed_on => Time.now,
362 :revision => '123',
400 :revision => '123',
363 :scmid => 'abc400bb8672',
401 :scmid => 'abc400bb8672',
364 :comments => 'test')
402 :comments => 'test')
365 assert c.event_title.include?('123:abc400bb8672:')
403 assert c.event_title.include?('123:abc400bb8672:')
366 assert_equal 'abc400bb8672', c.event_url[:rev]
404 assert_equal 'abc400bb8672', c.event_url[:rev]
367 end
405 end
368
406
369 def test_previous
407 def test_previous
370 assert_equal 0, @repository.changesets.count
408 assert_equal 0, @repository.changesets.count
371 @repository.fetch_changesets
409 @repository.fetch_changesets
372 @project.reload
410 @project.reload
373 assert_equal NUM_REV, @repository.changesets.count
411 assert_equal NUM_REV, @repository.changesets.count
374 %w|28 3ae45e2d177d 3ae45|.each do |r1|
412 %w|28 3ae45e2d177d 3ae45|.each do |r1|
375 changeset = @repository.find_changeset_by_name(r1)
413 changeset = @repository.find_changeset_by_name(r1)
376 %w|27 7bbf4c738e71 7bbf|.each do |r2|
414 %w|27 7bbf4c738e71 7bbf|.each do |r2|
377 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
415 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
378 end
416 end
379 end
417 end
380 end
418 end
381
419
382 def test_previous_nil
420 def test_previous_nil
383 assert_equal 0, @repository.changesets.count
421 assert_equal 0, @repository.changesets.count
384 @repository.fetch_changesets
422 @repository.fetch_changesets
385 @project.reload
423 @project.reload
386 assert_equal NUM_REV, @repository.changesets.count
424 assert_equal NUM_REV, @repository.changesets.count
387 %w|0 0885933ad4f6 0885|.each do |r1|
425 %w|0 0885933ad4f6 0885|.each do |r1|
388 changeset = @repository.find_changeset_by_name(r1)
426 changeset = @repository.find_changeset_by_name(r1)
389 assert_nil changeset.previous
427 assert_nil changeset.previous
390 end
428 end
391 end
429 end
392
430
393 def test_next
431 def test_next
394 assert_equal 0, @repository.changesets.count
432 assert_equal 0, @repository.changesets.count
395 @repository.fetch_changesets
433 @repository.fetch_changesets
396 @project.reload
434 @project.reload
397 assert_equal NUM_REV, @repository.changesets.count
435 assert_equal NUM_REV, @repository.changesets.count
398 %w|27 7bbf4c738e71 7bbf|.each do |r2|
436 %w|27 7bbf4c738e71 7bbf|.each do |r2|
399 changeset = @repository.find_changeset_by_name(r2)
437 changeset = @repository.find_changeset_by_name(r2)
400 %w|28 3ae45e2d177d 3ae45|.each do |r1|
438 %w|28 3ae45e2d177d 3ae45|.each do |r1|
401 assert_equal @repository.find_changeset_by_name(r1), changeset.next
439 assert_equal @repository.find_changeset_by_name(r1), changeset.next
402 end
440 end
403 end
441 end
404 end
442 end
405
443
406 def test_next_nil
444 def test_next_nil
407 assert_equal 0, @repository.changesets.count
445 assert_equal 0, @repository.changesets.count
408 @repository.fetch_changesets
446 @repository.fetch_changesets
409 @project.reload
447 @project.reload
410 assert_equal NUM_REV, @repository.changesets.count
448 assert_equal NUM_REV, @repository.changesets.count
411 %w|31 31eeee7395c8 31eee|.each do |r1|
449 %w|31 31eeee7395c8 31eee|.each do |r1|
412 changeset = @repository.find_changeset_by_name(r1)
450 changeset = @repository.find_changeset_by_name(r1)
413 assert_nil changeset.next
451 assert_nil changeset.next
414 end
452 end
415 end
453 end
416 else
454 else
417 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
455 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
418 def test_fake; assert true end
456 def test_fake; assert true end
419 end
457 end
420 end
458 end
General Comments 0
You need to be logged in to leave comments. Login now