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