##// END OF EJS Templates
scm: git: fix incorrect comment in unit model test and code clean up unit model test....
Toshi MARUYAMA -
r5602:f3a069281ec9
parent child
Show More
@@ -1,321 +1,330
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 RepositoryGitTest < ActiveSupport::TestCase
21 21 fixtures :projects, :repositories, :enabled_modules, :users, :roles
22 22
23 23 # No '..' in the repository path
24 24 REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository'
25 25 REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin?
26 26
27 27 FELIX_HEX = "Felix Sch\xC3\xA4fer"
28 28 CHAR_1_HEX = "\xc3\x9c"
29 29
30 30 ## Ruby uses ANSI api to fork a process on Windows.
31 31 ## Japanese Shift_JIS and Traditional Chinese Big5 have 0x5c(backslash) problem
32 32 ## and these are incompatible with ASCII.
33 33 # WINDOWS_PASS = Redmine::Platform.mswin?
34 34 WINDOWS_PASS = false
35 35
36 36 if File.directory?(REPOSITORY_PATH)
37 37 def setup
38 38 klass = Repository::Git
39 39 assert_equal "Git", klass.scm_name
40 40 assert klass.scm_adapter_class
41 41 assert_not_equal "", klass.scm_command
42 42 assert_equal true, klass.scm_available
43 43
44 44 @project = Project.find(3)
45 45 @repository = Repository::Git.create(
46 46 :project => @project,
47 47 :url => REPOSITORY_PATH,
48 48 :path_encoding => 'ISO-8859-1'
49 49 )
50 50 assert @repository
51 51 @char_1 = CHAR_1_HEX.dup
52 52 if @char_1.respond_to?(:force_encoding)
53 53 @char_1.force_encoding('UTF-8')
54 54 end
55 55 end
56 56
57 57 def test_fetch_changesets_from_scratch
58 58 @repository.fetch_changesets
59 59 @repository.reload
60 60
61 61 assert_equal 21, @repository.changesets.count
62 62 assert_equal 33, @repository.changes.count
63 63
64 64 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
65 65 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
66 66 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
67 67 assert_equal User.find_by_login('jsmith'), commit.user
68 68 # TODO: add a commit with commit time <> author time to the test repository
69 69 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
70 70 assert_equal "2007-12-14".to_date, commit.commit_date
71 71 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
72 72 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
73 73 assert_equal 3, commit.changes.count
74 74 change = commit.changes.sort_by(&:path).first
75 75 assert_equal "README", change.path
76 76 assert_equal "A", change.action
77 77 end
78 78
79 79 def test_fetch_changesets_incremental
80 80 @repository.fetch_changesets
81 # Remove the 3 latest changesets
82 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 8).each(&:destroy)
81
82 # Remove the latest changesets
83 @repository.changesets.find(
84 :all,
85 :order => 'committed_on DESC',
86 :limit => 8).each(&:destroy)
83 87 @repository.reload
84 88 cs1 = @repository.changesets
85 89 assert_equal 13, cs1.count
86 90
87 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
91 rev_a_commit = @repository.changesets.find(
92 :first,
93 :order => 'committed_on DESC')
88 94 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
89 95 # Mon Jul 5 22:34:26 2010 +0200
90 96 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
91 97 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
92 98 assert_equal rev_a_committed_on, rev_a_commit.committed_on
93 99 latest_rev = @repository.latest_changeset
94 100 assert_equal rev_a_committed_on, latest_rev.committed_on
95 101
96 102 @repository.fetch_changesets
97 103 assert_equal 21, @repository.changesets.count
98 104 end
99 105
100 106 def test_latest_changesets
101 107 @repository.fetch_changesets
102 108 @repository.reload
103 109 # with limit
104 110 changesets = @repository.latest_changesets('', nil, 2)
105 111 assert_equal 2, changesets.size
106 112
107 113 # with path
108 114 changesets = @repository.latest_changesets('images', nil)
109 115 assert_equal [
110 116 'deff712f05a90d96edbd70facc47d944be5897e3',
111 117 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
112 118 '7234cb2750b63f47bff735edc50a1c0a433c2518',
113 119 ], changesets.collect(&:revision)
114 120
115 121 changesets = @repository.latest_changesets('README', nil)
116 122 assert_equal [
117 123 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
118 124 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
119 125 '713f4944648826f558cf548222f813dabe7cbb04',
120 126 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
121 127 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
122 128 '7234cb2750b63f47bff735edc50a1c0a433c2518',
123 129 ], changesets.collect(&:revision)
124 130
125 131 # with path, revision and limit
126 132 changesets = @repository.latest_changesets('images', '899a15dba')
127 133 assert_equal [
128 134 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
129 135 '7234cb2750b63f47bff735edc50a1c0a433c2518',
130 136 ], changesets.collect(&:revision)
131 137
132 138 changesets = @repository.latest_changesets('images', '899a15dba', 1)
133 139 assert_equal [
134 140 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
135 141 ], changesets.collect(&:revision)
136 142
137 143 changesets = @repository.latest_changesets('README', '899a15dba')
138 144 assert_equal [
139 145 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
140 146 '7234cb2750b63f47bff735edc50a1c0a433c2518',
141 147 ], changesets.collect(&:revision)
142 148
143 149 changesets = @repository.latest_changesets('README', '899a15dba', 1)
144 150 assert_equal [
145 151 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
146 152 ], changesets.collect(&:revision)
147 153
148 154 # with path, tag and limit
149 155 changesets = @repository.latest_changesets('images', 'tag01.annotated')
150 156 assert_equal [
151 157 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
152 158 '7234cb2750b63f47bff735edc50a1c0a433c2518',
153 159 ], changesets.collect(&:revision)
154 160
155 161 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
156 162 assert_equal [
157 163 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
158 164 ], changesets.collect(&:revision)
159 165
160 166 changesets = @repository.latest_changesets('README', 'tag01.annotated')
161 167 assert_equal [
162 168 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
163 169 '7234cb2750b63f47bff735edc50a1c0a433c2518',
164 170 ], changesets.collect(&:revision)
165 171
166 172 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
167 173 assert_equal [
168 174 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
169 175 ], changesets.collect(&:revision)
170 176
171 177 # with path, branch and limit
172 178 changesets = @repository.latest_changesets('images', 'test_branch')
173 179 assert_equal [
174 180 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
175 181 '7234cb2750b63f47bff735edc50a1c0a433c2518',
176 182 ], changesets.collect(&:revision)
177 183
178 184 changesets = @repository.latest_changesets('images', 'test_branch', 1)
179 185 assert_equal [
180 186 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
181 187 ], changesets.collect(&:revision)
182 188
183 189 changesets = @repository.latest_changesets('README', 'test_branch')
184 190 assert_equal [
185 191 '713f4944648826f558cf548222f813dabe7cbb04',
186 192 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
187 193 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
188 194 '7234cb2750b63f47bff735edc50a1c0a433c2518',
189 195 ], changesets.collect(&:revision)
190 196
191 197 changesets = @repository.latest_changesets('README', 'test_branch', 2)
192 198 assert_equal [
193 199 '713f4944648826f558cf548222f813dabe7cbb04',
194 200 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
195 201 ], changesets.collect(&:revision)
196 202
197 203 # latin-1 encoding path
198 204 changesets = @repository.latest_changesets(
199 205 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
200 206 assert_equal [
201 207 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
202 208 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
203 209 ], changesets.collect(&:revision)
204 210
205 211 changesets = @repository.latest_changesets(
206 212 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
207 213 assert_equal [
208 214 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
209 215 ], changesets.collect(&:revision)
210 216 end
211 217
212 218 def test_latest_changesets_latin_1_dir
213 219 if WINDOWS_PASS
214 220 #
215 221 else
216 222 @repository.fetch_changesets
217 223 @repository.reload
218 224 changesets = @repository.latest_changesets(
219 225 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
220 226 assert_equal [
221 227 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
222 228 ], changesets.collect(&:revision)
223 229 end
224 230 end
225 231
226 232 def test_find_changeset_by_name
227 233 @repository.fetch_changesets
228 234 @repository.reload
229 235 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
230 236 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
231 237 @repository.find_changeset_by_name(r).revision
232 238 end
233 239 end
234 240
235 241 def test_find_changeset_by_empty_name
236 242 @repository.fetch_changesets
237 243 @repository.reload
238 244 ['', ' ', nil].each do |r|
239 245 assert_nil @repository.find_changeset_by_name(r)
240 246 end
241 247 end
242 248
243 249 def test_identifier
244 250 @repository.fetch_changesets
245 251 @repository.reload
246 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
252 c = @repository.changesets.find_by_revision(
253 '7234cb2750b63f47bff735edc50a1c0a433c2518')
247 254 assert_equal c.scmid, c.identifier
248 255 end
249 256
250 257 def test_format_identifier
251 258 @repository.fetch_changesets
252 259 @repository.reload
253 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
260 c = @repository.changesets.find_by_revision(
261 '7234cb2750b63f47bff735edc50a1c0a433c2518')
254 262 assert_equal '7234cb27', c.format_identifier
255 263 end
256 264
257 265 def test_activities
258 266 c = Changeset.new(:repository => @repository,
259 267 :committed_on => Time.now,
260 268 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
261 269 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
262 270 :comments => 'test')
263 271 assert c.event_title.include?('abc7234c:')
264 272 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
265 273 end
266 274
267 275 def test_log_utf8
268 276 @repository.fetch_changesets
269 277 @repository.reload
270 278 str_felix_hex = FELIX_HEX.dup
271 279 if str_felix_hex.respond_to?(:force_encoding)
272 280 str_felix_hex.force_encoding('UTF-8')
273 281 end
274 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
282 c = @repository.changesets.find_by_revision(
283 'ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
275 284 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
276 285 end
277 286
278 287 def test_previous
279 288 @repository.fetch_changesets
280 289 @repository.reload
281 290 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
282 291 changeset = @repository.find_changeset_by_name(r1)
283 292 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
284 293 assert_equal @repository.find_changeset_by_name(r2), changeset.previous
285 294 end
286 295 end
287 296 end
288 297
289 298 def test_previous_nil
290 299 @repository.fetch_changesets
291 300 @repository.reload
292 301 %w|7234cb2750b63f47bff735edc50a1c0a433c2518 7234cb2|.each do |r1|
293 302 changeset = @repository.find_changeset_by_name(r1)
294 303 assert_nil changeset.previous
295 304 end
296 305 end
297 306
298 307 def test_next
299 308 @repository.fetch_changesets
300 309 @repository.reload
301 310 %w|64f1f3e89ad1cb57976ff0ad99a107012ba3481d 64f1f3e89ad1|.each do |r2|
302 311 changeset = @repository.find_changeset_by_name(r2)
303 312 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
304 313 assert_equal @repository.find_changeset_by_name(r1), changeset.next
305 314 end
306 315 end
307 316 end
308 317
309 318 def test_next_nil
310 319 @repository.fetch_changesets
311 320 @repository.reload
312 321 %w|1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127 1ca7f5ed|.each do |r1|
313 322 changeset = @repository.find_changeset_by_name(r1)
314 323 assert_nil changeset.next
315 324 end
316 325 end
317 326 else
318 327 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
319 328 def test_fake; assert true end
320 329 end
321 330 end
General Comments 0
You need to be logged in to leave comments. Login now