##// END OF EJS Templates
scm: git: add latin-1 encoding directory test in unit model test (#5251)....
Toshi MARUYAMA -
r4943:084bdd7559b4
parent child
Show More
@@ -1,255 +1,269
1 # redMine - project management software
1 # redMine - project management software
2 # Copyright (C) 2006-2007 Jean-Philippe Lang
2 # Copyright (C) 2006-2007 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 def setup
30 def setup
31 @project = Project.find(3)
31 @project = Project.find(3)
32 @repository = Repository::Git.create(
32 @repository = Repository::Git.create(
33 :project => @project,
33 :project => @project,
34 :url => REPOSITORY_PATH,
34 :url => REPOSITORY_PATH,
35 :path_encoding => 'ISO-8859-1'
35 :path_encoding => 'ISO-8859-1'
36 )
36 )
37 assert @repository
37 assert @repository
38 @char_1 = CHAR_1_HEX.dup
38 @char_1 = CHAR_1_HEX.dup
39 if @char_1.respond_to?(:force_encoding)
39 if @char_1.respond_to?(:force_encoding)
40 @char_1.force_encoding('UTF-8')
40 @char_1.force_encoding('UTF-8')
41 end
41 end
42 end
42 end
43
43
44 if File.directory?(REPOSITORY_PATH)
44 if File.directory?(REPOSITORY_PATH)
45 def test_fetch_changesets_from_scratch
45 def test_fetch_changesets_from_scratch
46 @repository.fetch_changesets
46 @repository.fetch_changesets
47 @repository.reload
47 @repository.reload
48
48
49 assert_equal 21, @repository.changesets.count
49 assert_equal 21, @repository.changesets.count
50 assert_equal 33, @repository.changes.count
50 assert_equal 33, @repository.changes.count
51
51
52 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
52 commit = @repository.changesets.find(:first, :order => 'committed_on ASC')
53 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
53 assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments
54 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
54 assert_equal "jsmith <jsmith@foo.bar>", commit.committer
55 assert_equal User.find_by_login('jsmith'), commit.user
55 assert_equal User.find_by_login('jsmith'), commit.user
56 # TODO: add a commit with commit time <> author time to the test repository
56 # TODO: add a commit with commit time <> author time to the test repository
57 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
57 assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on
58 assert_equal "2007-12-14".to_date, commit.commit_date
58 assert_equal "2007-12-14".to_date, commit.commit_date
59 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
59 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision
60 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
60 assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid
61 assert_equal 3, commit.changes.count
61 assert_equal 3, commit.changes.count
62 change = commit.changes.sort_by(&:path).first
62 change = commit.changes.sort_by(&:path).first
63 assert_equal "README", change.path
63 assert_equal "README", change.path
64 assert_equal "A", change.action
64 assert_equal "A", change.action
65 end
65 end
66
66
67 def test_fetch_changesets_incremental
67 def test_fetch_changesets_incremental
68 @repository.fetch_changesets
68 @repository.fetch_changesets
69 # Remove the 3 latest changesets
69 # Remove the 3 latest changesets
70 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 8).each(&:destroy)
70 @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 8).each(&:destroy)
71 @repository.reload
71 @repository.reload
72 cs1 = @repository.changesets
72 cs1 = @repository.changesets
73 assert_equal 13, cs1.count
73 assert_equal 13, cs1.count
74
74
75 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
75 rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC')
76 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
76 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision
77 # Mon Jul 5 22:34:26 2010 +0200
77 # Mon Jul 5 22:34:26 2010 +0200
78 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
78 rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26)
79 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
79 assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid
80 assert_equal rev_a_committed_on, rev_a_commit.committed_on
80 assert_equal rev_a_committed_on, rev_a_commit.committed_on
81 latest_rev = @repository.latest_changeset
81 latest_rev = @repository.latest_changeset
82 assert_equal rev_a_committed_on, latest_rev.committed_on
82 assert_equal rev_a_committed_on, latest_rev.committed_on
83
83
84 @repository.fetch_changesets
84 @repository.fetch_changesets
85 assert_equal 21, @repository.changesets.count
85 assert_equal 21, @repository.changesets.count
86 end
86 end
87
87
88 def test_latest_changesets
88 def test_latest_changesets
89 @repository.fetch_changesets
89 @repository.fetch_changesets
90 @repository.reload
90 @repository.reload
91 # with limit
91 # with limit
92 changesets = @repository.latest_changesets('', nil, 2)
92 changesets = @repository.latest_changesets('', nil, 2)
93 assert_equal 2, changesets.size
93 assert_equal 2, changesets.size
94
94
95 # with path
95 # with path
96 changesets = @repository.latest_changesets('images', nil)
96 changesets = @repository.latest_changesets('images', nil)
97 assert_equal [
97 assert_equal [
98 'deff712f05a90d96edbd70facc47d944be5897e3',
98 'deff712f05a90d96edbd70facc47d944be5897e3',
99 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
99 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
100 '7234cb2750b63f47bff735edc50a1c0a433c2518',
100 '7234cb2750b63f47bff735edc50a1c0a433c2518',
101 ], changesets.collect(&:revision)
101 ], changesets.collect(&:revision)
102
102
103 changesets = @repository.latest_changesets('README', nil)
103 changesets = @repository.latest_changesets('README', nil)
104 assert_equal [
104 assert_equal [
105 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
105 '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf',
106 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
106 '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8',
107 '713f4944648826f558cf548222f813dabe7cbb04',
107 '713f4944648826f558cf548222f813dabe7cbb04',
108 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
108 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
109 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
109 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
110 '7234cb2750b63f47bff735edc50a1c0a433c2518',
110 '7234cb2750b63f47bff735edc50a1c0a433c2518',
111 ], changesets.collect(&:revision)
111 ], changesets.collect(&:revision)
112
112
113 # with path, revision and limit
113 # with path, revision and limit
114 changesets = @repository.latest_changesets('images', '899a15dba')
114 changesets = @repository.latest_changesets('images', '899a15dba')
115 assert_equal [
115 assert_equal [
116 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
116 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
117 '7234cb2750b63f47bff735edc50a1c0a433c2518',
117 '7234cb2750b63f47bff735edc50a1c0a433c2518',
118 ], changesets.collect(&:revision)
118 ], changesets.collect(&:revision)
119
119
120 changesets = @repository.latest_changesets('images', '899a15dba', 1)
120 changesets = @repository.latest_changesets('images', '899a15dba', 1)
121 assert_equal [
121 assert_equal [
122 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
122 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
123 ], changesets.collect(&:revision)
123 ], changesets.collect(&:revision)
124
124
125 changesets = @repository.latest_changesets('README', '899a15dba')
125 changesets = @repository.latest_changesets('README', '899a15dba')
126 assert_equal [
126 assert_equal [
127 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
127 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
128 '7234cb2750b63f47bff735edc50a1c0a433c2518',
128 '7234cb2750b63f47bff735edc50a1c0a433c2518',
129 ], changesets.collect(&:revision)
129 ], changesets.collect(&:revision)
130
130
131 changesets = @repository.latest_changesets('README', '899a15dba', 1)
131 changesets = @repository.latest_changesets('README', '899a15dba', 1)
132 assert_equal [
132 assert_equal [
133 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
133 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
134 ], changesets.collect(&:revision)
134 ], changesets.collect(&:revision)
135
135
136 # with path, tag and limit
136 # with path, tag and limit
137 changesets = @repository.latest_changesets('images', 'tag01.annotated')
137 changesets = @repository.latest_changesets('images', 'tag01.annotated')
138 assert_equal [
138 assert_equal [
139 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
139 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
140 '7234cb2750b63f47bff735edc50a1c0a433c2518',
140 '7234cb2750b63f47bff735edc50a1c0a433c2518',
141 ], changesets.collect(&:revision)
141 ], changesets.collect(&:revision)
142
142
143 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
143 changesets = @repository.latest_changesets('images', 'tag01.annotated', 1)
144 assert_equal [
144 assert_equal [
145 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
145 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
146 ], changesets.collect(&:revision)
146 ], changesets.collect(&:revision)
147
147
148 changesets = @repository.latest_changesets('README', 'tag01.annotated')
148 changesets = @repository.latest_changesets('README', 'tag01.annotated')
149 assert_equal [
149 assert_equal [
150 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
150 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
151 '7234cb2750b63f47bff735edc50a1c0a433c2518',
151 '7234cb2750b63f47bff735edc50a1c0a433c2518',
152 ], changesets.collect(&:revision)
152 ], changesets.collect(&:revision)
153
153
154 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
154 changesets = @repository.latest_changesets('README', 'tag01.annotated', 1)
155 assert_equal [
155 assert_equal [
156 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
156 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
157 ], changesets.collect(&:revision)
157 ], changesets.collect(&:revision)
158
158
159 # with path, branch and limit
159 # with path, branch and limit
160 changesets = @repository.latest_changesets('images', 'test_branch')
160 changesets = @repository.latest_changesets('images', 'test_branch')
161 assert_equal [
161 assert_equal [
162 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
162 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
163 '7234cb2750b63f47bff735edc50a1c0a433c2518',
163 '7234cb2750b63f47bff735edc50a1c0a433c2518',
164 ], changesets.collect(&:revision)
164 ], changesets.collect(&:revision)
165
165
166 changesets = @repository.latest_changesets('images', 'test_branch', 1)
166 changesets = @repository.latest_changesets('images', 'test_branch', 1)
167 assert_equal [
167 assert_equal [
168 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
168 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
169 ], changesets.collect(&:revision)
169 ], changesets.collect(&:revision)
170
170
171 changesets = @repository.latest_changesets('README', 'test_branch')
171 changesets = @repository.latest_changesets('README', 'test_branch')
172 assert_equal [
172 assert_equal [
173 '713f4944648826f558cf548222f813dabe7cbb04',
173 '713f4944648826f558cf548222f813dabe7cbb04',
174 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
174 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
175 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
175 '899a15dba03a3b350b89c3f537e4bbe02a03cdc9',
176 '7234cb2750b63f47bff735edc50a1c0a433c2518',
176 '7234cb2750b63f47bff735edc50a1c0a433c2518',
177 ], changesets.collect(&:revision)
177 ], changesets.collect(&:revision)
178
178
179 changesets = @repository.latest_changesets('README', 'test_branch', 2)
179 changesets = @repository.latest_changesets('README', 'test_branch', 2)
180 assert_equal [
180 assert_equal [
181 '713f4944648826f558cf548222f813dabe7cbb04',
181 '713f4944648826f558cf548222f813dabe7cbb04',
182 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
182 '61b685fbe55ab05b5ac68402d5720c1a6ac973d1',
183 ], changesets.collect(&:revision)
183 ], changesets.collect(&:revision)
184
184
185 # latin-1 encoding path
185 # latin-1 encoding path
186 changesets = @repository.latest_changesets(
186 changesets = @repository.latest_changesets(
187 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
187 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89')
188 assert_equal [
188 assert_equal [
189 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
189 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
190 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
190 '4fc55c43bf3d3dc2efb66145365ddc17639ce81e',
191 ], changesets.collect(&:revision)
191 ], changesets.collect(&:revision)
192
192
193 changesets = @repository.latest_changesets(
193 changesets = @repository.latest_changesets(
194 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
194 "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1)
195 assert_equal [
195 assert_equal [
196 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
196 '64f1f3e89ad1cb57976ff0ad99a107012ba3481d',
197 ], changesets.collect(&:revision)
197 ], changesets.collect(&:revision)
198 end
198 end
199
199
200 def test_latest_changesets_latin_1_dir
201 if Redmine::Platform.mswin?
202 # TODO
203 else
204 @repository.fetch_changesets
205 @repository.reload
206 changesets = @repository.latest_changesets(
207 "latin-1-dir/test-#{@char_1}-subdir", '1ca7f5ed')
208 assert_equal [
209 '1ca7f5ed374f3cb31a93ae5215c2e25cc6ec5127',
210 ], changesets.collect(&:revision)
211 end
212 end
213
200 def test_find_changeset_by_name
214 def test_find_changeset_by_name
201 @repository.fetch_changesets
215 @repository.fetch_changesets
202 @repository.reload
216 @repository.reload
203 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
217 ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r|
204 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
218 assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518',
205 @repository.find_changeset_by_name(r).revision
219 @repository.find_changeset_by_name(r).revision
206 end
220 end
207 end
221 end
208
222
209 def test_find_changeset_by_empty_name
223 def test_find_changeset_by_empty_name
210 @repository.fetch_changesets
224 @repository.fetch_changesets
211 @repository.reload
225 @repository.reload
212 ['', ' ', nil].each do |r|
226 ['', ' ', nil].each do |r|
213 assert_nil @repository.find_changeset_by_name(r)
227 assert_nil @repository.find_changeset_by_name(r)
214 end
228 end
215 end
229 end
216
230
217 def test_identifier
231 def test_identifier
218 @repository.fetch_changesets
232 @repository.fetch_changesets
219 @repository.reload
233 @repository.reload
220 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
234 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
221 assert_equal c.scmid, c.identifier
235 assert_equal c.scmid, c.identifier
222 end
236 end
223
237
224 def test_format_identifier
238 def test_format_identifier
225 @repository.fetch_changesets
239 @repository.fetch_changesets
226 @repository.reload
240 @repository.reload
227 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
241 c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518')
228 assert_equal '7234cb27', c.format_identifier
242 assert_equal '7234cb27', c.format_identifier
229 end
243 end
230
244
231 def test_activities
245 def test_activities
232 c = Changeset.new(:repository => @repository,
246 c = Changeset.new(:repository => @repository,
233 :committed_on => Time.now,
247 :committed_on => Time.now,
234 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
248 :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
235 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
249 :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2',
236 :comments => 'test')
250 :comments => 'test')
237 assert c.event_title.include?('abc7234c:')
251 assert c.event_title.include?('abc7234c:')
238 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
252 assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev]
239 end
253 end
240
254
241 def test_log_utf8
255 def test_log_utf8
242 @repository.fetch_changesets
256 @repository.fetch_changesets
243 @repository.reload
257 @repository.reload
244 str_felix_hex = FELIX_HEX
258 str_felix_hex = FELIX_HEX
245 if str_felix_hex.respond_to?(:force_encoding)
259 if str_felix_hex.respond_to?(:force_encoding)
246 str_felix_hex.force_encoding('UTF-8')
260 str_felix_hex.force_encoding('UTF-8')
247 end
261 end
248 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
262 c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b')
249 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
263 assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer
250 end
264 end
251 else
265 else
252 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
266 puts "Git test repository NOT FOUND. Skipping unit tests !!!"
253 def test_fake; assert true end
267 def test_fake; assert true end
254 end
268 end
255 end
269 end
General Comments 0
You need to be logged in to leave comments. Login now