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