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