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