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