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