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