##// END OF EJS Templates
scm: mercurial: replace RAILS_ROOT to Rails.root in unit model test....
Toshi MARUYAMA -
r5931:7e38ccab55f5
parent child
Show More
@@ -1,293 +1,290
1 1 # Redmine - project management software
2 2 # Copyright (C) 2006-2011 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 # No '..' in the repository path
24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/mercurial_repository'
25
23 REPOSITORY_PATH = Rails.root.join('tmp/test/mercurial_repository').to_s
26 24 CHAR_1_HEX = "\xc3\x9c"
27 25
28 26 if File.directory?(REPOSITORY_PATH)
29
30 27 def setup
31 28 klass = Repository::Mercurial
32 29 assert_equal "Mercurial", klass.scm_name
33 30 assert klass.scm_adapter_class
34 31 assert_not_equal "", klass.scm_command
35 32 assert_equal true, klass.scm_available
36 33
37 34 @project = Project.find(3)
38 35 @repository = Repository::Mercurial.create(
39 36 :project => @project,
40 37 :url => REPOSITORY_PATH,
41 38 :path_encoding => 'ISO-8859-1'
42 39 )
43 40 assert @repository
44 41 @char_1 = CHAR_1_HEX.dup
45 42 @tag_char_1 = "tag-#{CHAR_1_HEX}-00"
46 43 @branch_char_0 = "branch-#{CHAR_1_HEX}-00"
47 44 @branch_char_1 = "branch-#{CHAR_1_HEX}-01"
48 45 if @char_1.respond_to?(:force_encoding)
49 46 @char_1.force_encoding('UTF-8')
50 47 @tag_char_1.force_encoding('UTF-8')
51 48 @branch_char_0.force_encoding('UTF-8')
52 49 @branch_char_1.force_encoding('UTF-8')
53 50 end
54 51 end
55 52
56 53 def test_fetch_changesets_from_scratch
57 54 @repository.fetch_changesets
58 55 @repository.reload
59 56 assert_equal 29, @repository.changesets.count
60 57 assert_equal 37, @repository.changes.count
61 58 assert_equal "Initial import.\nThe repository contains 3 files.",
62 59 @repository.changesets.find_by_revision('0').comments
63 60 end
64 61
65 62 def test_fetch_changesets_incremental
66 63 @repository.fetch_changesets
67 64 # Remove changesets with revision > 2
68 65 @repository.changesets.find(:all).each {|c| c.destroy if c.revision.to_i > 2}
69 66 @repository.reload
70 67 assert_equal 3, @repository.changesets.count
71 68
72 69 @repository.fetch_changesets
73 70 assert_equal 29, @repository.changesets.count
74 71 end
75 72
76 73 def test_isodatesec
77 74 # Template keyword 'isodatesec' supported in Mercurial 1.0 and higher
78 75 if @repository.scm.class.client_version_above?([1, 0])
79 76 @repository.fetch_changesets
80 77 @repository.reload
81 78 rev0_committed_on = Time.gm(2007, 12, 14, 9, 22, 52)
82 79 assert_equal @repository.changesets.find_by_revision('0').committed_on, rev0_committed_on
83 80 end
84 81 end
85 82
86 83 def test_changeset_order_by_revision
87 84 @repository.fetch_changesets
88 85 @repository.reload
89 86
90 87 c0 = @repository.latest_changeset
91 88 c1 = @repository.changesets.find_by_revision('0')
92 89 # sorted by revision (id), not by date
93 90 assert c0.revision.to_i > c1.revision.to_i
94 91 assert c0.committed_on < c1.committed_on
95 92 end
96 93
97 94 def test_latest_changesets
98 95 @repository.fetch_changesets
99 96 @repository.reload
100 97
101 98 # with_limit
102 99 changesets = @repository.latest_changesets('', nil, 2)
103 100 assert_equal %w|28 27|, changesets.collect(&:revision)
104 101
105 102 # with_filepath
106 103 changesets = @repository.latest_changesets(
107 104 '/sql_escape/percent%dir/percent%file1.txt', nil)
108 105 assert_equal %w|11 10 9|, changesets.collect(&:revision)
109 106
110 107 changesets = @repository.latest_changesets(
111 108 '/sql_escape/underscore_dir/understrike_file.txt', nil)
112 109 assert_equal %w|12 9|, changesets.collect(&:revision)
113 110
114 111 changesets = @repository.latest_changesets('README', nil)
115 112 assert_equal %w|28 17 8 6 1 0|, changesets.collect(&:revision)
116 113
117 114 changesets = @repository.latest_changesets('README','8')
118 115 assert_equal %w|8 6 1 0|, changesets.collect(&:revision)
119 116
120 117 changesets = @repository.latest_changesets('README','8', 2)
121 118 assert_equal %w|8 6|, changesets.collect(&:revision)
122 119
123 120 # with_dirpath
124 121 changesets = @repository.latest_changesets('images', nil)
125 122 assert_equal %w|1 0|, changesets.collect(&:revision)
126 123
127 124 path = 'sql_escape/percent%dir'
128 125 changesets = @repository.latest_changesets(path, nil)
129 126 assert_equal %w|13 11 10 9|, changesets.collect(&:revision)
130 127
131 128 changesets = @repository.latest_changesets(path, '11')
132 129 assert_equal %w|11 10 9|, changesets.collect(&:revision)
133 130
134 131 changesets = @repository.latest_changesets(path, '11', 2)
135 132 assert_equal %w|11 10|, changesets.collect(&:revision)
136 133
137 134 path = 'sql_escape/underscore_dir'
138 135 changesets = @repository.latest_changesets(path, nil)
139 136 assert_equal %w|13 12 9|, changesets.collect(&:revision)
140 137
141 138 changesets = @repository.latest_changesets(path, '12')
142 139 assert_equal %w|12 9|, changesets.collect(&:revision)
143 140
144 141 changesets = @repository.latest_changesets(path, '12', 1)
145 142 assert_equal %w|12|, changesets.collect(&:revision)
146 143
147 144 # tag
148 145 changesets = @repository.latest_changesets('', 'tag_test.00')
149 146 assert_equal %w|5 4 3 2 1 0|, changesets.collect(&:revision)
150 147
151 148 changesets = @repository.latest_changesets('', 'tag_test.00', 2)
152 149 assert_equal %w|5 4|, changesets.collect(&:revision)
153 150
154 151 changesets = @repository.latest_changesets('sources', 'tag_test.00')
155 152 assert_equal %w|4 3 2 1 0|, changesets.collect(&:revision)
156 153
157 154 changesets = @repository.latest_changesets('sources', 'tag_test.00', 2)
158 155 assert_equal %w|4 3|, changesets.collect(&:revision)
159 156
160 157 # named branch
161 158 changesets = @repository.latest_changesets('', @branch_char_1)
162 159 assert_equal %w|27 26|, changesets.collect(&:revision)
163 160
164 161 changesets = @repository.latest_changesets("latin-1-dir/test-#{@char_1}-subdir", @branch_char_1)
165 162 assert_equal %w|27|, changesets.collect(&:revision)
166 163 end
167 164
168 165 def test_copied_files
169 166 @repository.fetch_changesets
170 167 @repository.reload
171 168
172 169 cs1 = @repository.changesets.find_by_revision('13')
173 170 assert_not_nil cs1
174 171 c1 = cs1.changes.sort_by(&:path)
175 172 assert_equal 2, c1.size
176 173
177 174 assert_equal 'A', c1[0].action
178 175 assert_equal '/sql_escape/percent%dir/percentfile1.txt', c1[0].path
179 176 assert_equal '/sql_escape/percent%dir/percent%file1.txt', c1[0].from_path
180 177 assert_equal '3a330eb32958', c1[0].from_revision
181 178
182 179 assert_equal 'A', c1[1].action
183 180 assert_equal '/sql_escape/underscore_dir/understrike-file.txt', c1[1].path
184 181 assert_equal '/sql_escape/underscore_dir/understrike_file.txt', c1[1].from_path
185 182
186 183 cs2 = @repository.changesets.find_by_revision('15')
187 184 c2 = cs2.changes
188 185 assert_equal 1, c2.size
189 186
190 187 assert_equal 'A', c2[0].action
191 188 assert_equal '/README (1)[2]&,%.-3_4', c2[0].path
192 189 assert_equal '/README', c2[0].from_path
193 190 assert_equal '933ca60293d7', c2[0].from_revision
194 191
195 192 cs3 = @repository.changesets.find_by_revision('19')
196 193 c3 = cs3.changes
197 194 assert_equal 1, c3.size
198 195 assert_equal 'A', c3[0].action
199 196 assert_equal "/latin-1-dir/test-#{@char_1}-1.txt", c3[0].path
200 197 assert_equal "/latin-1-dir/test-#{@char_1}.txt", c3[0].from_path
201 198 assert_equal '5d9891a1b425', c3[0].from_revision
202 199 end
203 200
204 201 def test_find_changeset_by_name
205 202 @repository.fetch_changesets
206 203 @repository.reload
207 204 %w|2 400bb8672109 400|.each do |r|
208 205 assert_equal '2', @repository.find_changeset_by_name(r).revision
209 206 end
210 207 end
211 208
212 209 def test_find_changeset_by_invalid_name
213 210 @repository.fetch_changesets
214 211 @repository.reload
215 212 assert_nil @repository.find_changeset_by_name('100000')
216 213 end
217 214
218 215 def test_identifier
219 216 @repository.fetch_changesets
220 217 @repository.reload
221 218 c = @repository.changesets.find_by_revision('2')
222 219 assert_equal c.scmid, c.identifier
223 220 end
224 221
225 222 def test_format_identifier
226 223 @repository.fetch_changesets
227 224 @repository.reload
228 225 c = @repository.changesets.find_by_revision('2')
229 226 assert_equal '2:400bb8672109', c.format_identifier
230 227 end
231 228
232 229 def test_find_changeset_by_empty_name
233 230 @repository.fetch_changesets
234 231 @repository.reload
235 232 ['', ' ', nil].each do |r|
236 233 assert_nil @repository.find_changeset_by_name(r)
237 234 end
238 235 end
239 236
240 237 def test_activities
241 238 c = Changeset.new(:repository => @repository,
242 239 :committed_on => Time.now,
243 240 :revision => '123',
244 241 :scmid => 'abc400bb8672',
245 242 :comments => 'test')
246 243 assert c.event_title.include?('123:abc400bb8672:')
247 244 assert_equal 'abc400bb8672', c.event_url[:rev]
248 245 end
249 246
250 247 def test_previous
251 248 @repository.fetch_changesets
252 249 @repository.reload
253 250 %w|28 3ae45e2d177d 3ae45|.each do |r1|
254 251 changeset = @repository.find_changeset_by_name(r1)
255 252 %w|27 7bbf4c738e71 7bbf|.each do |r2|
256 253 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
257 254 end
258 255 end
259 256 end
260 257
261 258 def test_previous_nil
262 259 @repository.fetch_changesets
263 260 @repository.reload
264 261 %w|0 0885933ad4f6 0885|.each do |r1|
265 262 changeset = @repository.find_changeset_by_name(r1)
266 263 assert_nil changeset.previous
267 264 end
268 265 end
269 266
270 267 def test_next
271 268 @repository.fetch_changesets
272 269 @repository.reload
273 270 %w|27 7bbf4c738e71 7bbf|.each do |r2|
274 271 changeset = @repository.find_changeset_by_name(r2)
275 272 %w|28 3ae45e2d177d 3ae45|.each do |r1|
276 273 assert_equal @repository.find_changeset_by_name(r1), changeset.next
277 274 end
278 275 end
279 276 end
280 277
281 278 def test_next_nil
282 279 @repository.fetch_changesets
283 280 @repository.reload
284 281 %w|28 3ae45e2d177d 3ae45|.each do |r1|
285 282 changeset = @repository.find_changeset_by_name(r1)
286 283 assert_nil changeset.next
287 284 end
288 285 end
289 286 else
290 287 puts "Mercurial test repository NOT FOUND. Skipping unit tests !!!"
291 288 def test_fake; assert true end
292 289 end
293 290 end
General Comments 0
You need to be logged in to leave comments. Login now