@@ -1,241 +1,255 | |||
|
1 | 1 | # redMine - project management software |
|
2 | 2 | # Copyright (C) 2006-2007 Jean-Philippe Lang |
|
3 | 3 | # |
|
4 | 4 | # This program is free software; you can redistribute it and/or |
|
5 | 5 | # modify it under the terms of the GNU General Public License |
|
6 | 6 | # as published by the Free Software Foundation; either version 2 |
|
7 | 7 | # of the License, or (at your option) any later version. |
|
8 | 8 | # |
|
9 | 9 | # This program is distributed in the hope that it will be useful, |
|
10 | 10 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
11 | 11 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
12 | 12 | # GNU General Public License for more details. |
|
13 | 13 | # |
|
14 | 14 | # You should have received a copy of the GNU General Public License |
|
15 | 15 | # along with this program; if not, write to the Free Software |
|
16 | 16 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
17 | 17 | |
|
18 | 18 | require File.expand_path('../../test_helper', __FILE__) |
|
19 | 19 | |
|
20 | 20 | class RepositoryGitTest < ActiveSupport::TestCase |
|
21 | 21 | fixtures :projects, :repositories, :enabled_modules, :users, :roles |
|
22 | 22 | |
|
23 | 23 | # No '..' in the repository path |
|
24 | 24 | REPOSITORY_PATH = RAILS_ROOT.gsub(%r{config\/\.\.}, '') + '/tmp/test/git_repository' |
|
25 | 25 | REPOSITORY_PATH.gsub!(/\//, "\\") if Redmine::Platform.mswin? |
|
26 | 26 | |
|
27 | 27 | FELIX_HEX = "Felix Sch\xC3\xA4fer" |
|
28 | 28 | CHAR_1_HEX = "\xc3\x9c" |
|
29 | 29 | |
|
30 | 30 | def setup |
|
31 | 31 | @project = Project.find(3) |
|
32 | 32 | @repository = Repository::Git.create( |
|
33 | 33 | :project => @project, |
|
34 | 34 | :url => REPOSITORY_PATH, |
|
35 | 35 | :path_encoding => 'ISO-8859-1' |
|
36 | 36 | ) |
|
37 | 37 | assert @repository |
|
38 | 38 | @char_1 = CHAR_1_HEX.dup |
|
39 | 39 | if @char_1.respond_to?(:force_encoding) |
|
40 | 40 | @char_1.force_encoding('UTF-8') |
|
41 | 41 | end |
|
42 | 42 | end |
|
43 | 43 | |
|
44 | 44 | if File.directory?(REPOSITORY_PATH) |
|
45 | 45 | def test_fetch_changesets_from_scratch |
|
46 | 46 | @repository.fetch_changesets |
|
47 | 47 | @repository.reload |
|
48 | 48 | |
|
49 | 49 | assert_equal 20, @repository.changesets.count |
|
50 | 50 | assert_equal 30, @repository.changes.count |
|
51 | 51 | |
|
52 | 52 | commit = @repository.changesets.find(:first, :order => 'committed_on ASC') |
|
53 | 53 | assert_equal "Initial import.\nThe repository contains 3 files.", commit.comments |
|
54 | 54 | assert_equal "jsmith <jsmith@foo.bar>", commit.committer |
|
55 | 55 | assert_equal User.find_by_login('jsmith'), commit.user |
|
56 | 56 | # TODO: add a commit with commit time <> author time to the test repository |
|
57 | 57 | assert_equal "2007-12-14 09:22:52".to_time, commit.committed_on |
|
58 | 58 | assert_equal "2007-12-14".to_date, commit.commit_date |
|
59 | 59 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.revision |
|
60 | 60 | assert_equal "7234cb2750b63f47bff735edc50a1c0a433c2518", commit.scmid |
|
61 | 61 | assert_equal 3, commit.changes.count |
|
62 | 62 | change = commit.changes.sort_by(&:path).first |
|
63 | 63 | assert_equal "README", change.path |
|
64 | 64 | assert_equal "A", change.action |
|
65 | 65 | end |
|
66 | 66 | |
|
67 | 67 | def test_fetch_changesets_incremental |
|
68 | 68 | @repository.fetch_changesets |
|
69 | 69 | # Remove the 3 latest changesets |
|
70 | 70 | @repository.changesets.find(:all, :order => 'committed_on DESC', :limit => 7).each(&:destroy) |
|
71 | 71 | @repository.reload |
|
72 | 72 | cs1 = @repository.changesets |
|
73 | 73 | assert_equal 13, cs1.count |
|
74 | 74 | |
|
75 | 75 | rev_a_commit = @repository.changesets.find(:first, :order => 'committed_on DESC') |
|
76 | 76 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.revision |
|
77 | 77 | # Mon Jul 5 22:34:26 2010 +0200 |
|
78 | 78 | rev_a_committed_on = Time.gm(2010, 7, 5, 20, 34, 26) |
|
79 | 79 | assert_equal '4f26664364207fa8b1af9f8722647ab2d4ac5d43', rev_a_commit.scmid |
|
80 | 80 | assert_equal rev_a_committed_on, rev_a_commit.committed_on |
|
81 | 81 | latest_rev = @repository.latest_changeset |
|
82 | 82 | assert_equal rev_a_committed_on, latest_rev.committed_on |
|
83 | 83 | |
|
84 | 84 | @repository.fetch_changesets |
|
85 | 85 | assert_equal 20, @repository.changesets.count |
|
86 | 86 | end |
|
87 | 87 | |
|
88 | 88 | def test_latest_changesets |
|
89 | 89 | @repository.fetch_changesets |
|
90 | 90 | @repository.reload |
|
91 | 91 | # with limit |
|
92 | 92 | changesets = @repository.latest_changesets('', nil, 2) |
|
93 | 93 | assert_equal 2, changesets.size |
|
94 | 94 | |
|
95 | 95 | # with path |
|
96 | 96 | changesets = @repository.latest_changesets('images', nil) |
|
97 | 97 | assert_equal [ |
|
98 | 98 | 'deff712f05a90d96edbd70facc47d944be5897e3', |
|
99 | 99 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
100 | 100 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
101 | 101 | ], changesets.collect(&:revision) |
|
102 | 102 | |
|
103 | 103 | changesets = @repository.latest_changesets('README', nil) |
|
104 | 104 | assert_equal [ |
|
105 | 105 | '32ae898b720c2f7eec2723d5bdd558b4cb2d3ddf', |
|
106 | 106 | '4a07fe31bffcf2888791f3e6cbc9c4545cefe3e8', |
|
107 | 107 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
108 | 108 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
109 | 109 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
110 | 110 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
111 | 111 | ], changesets.collect(&:revision) |
|
112 | 112 | |
|
113 | 113 | # with path, revision and limit |
|
114 | 114 | changesets = @repository.latest_changesets('images', '899a15dba') |
|
115 | 115 | assert_equal [ |
|
116 | 116 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
117 | 117 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
118 | 118 | ], changesets.collect(&:revision) |
|
119 | 119 | |
|
120 | 120 | changesets = @repository.latest_changesets('images', '899a15dba', 1) |
|
121 | 121 | assert_equal [ |
|
122 | 122 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
123 | 123 | ], changesets.collect(&:revision) |
|
124 | 124 | |
|
125 | 125 | changesets = @repository.latest_changesets('README', '899a15dba') |
|
126 | 126 | assert_equal [ |
|
127 | 127 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
128 | 128 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
129 | 129 | ], changesets.collect(&:revision) |
|
130 | 130 | |
|
131 | 131 | changesets = @repository.latest_changesets('README', '899a15dba', 1) |
|
132 | 132 | assert_equal [ |
|
133 | 133 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
134 | 134 | ], changesets.collect(&:revision) |
|
135 | 135 | |
|
136 | 136 | # with path, tag and limit |
|
137 | 137 | changesets = @repository.latest_changesets('images', 'tag01.annotated') |
|
138 | 138 | assert_equal [ |
|
139 | 139 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
140 | 140 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
141 | 141 | ], changesets.collect(&:revision) |
|
142 | 142 | |
|
143 | 143 | changesets = @repository.latest_changesets('images', 'tag01.annotated', 1) |
|
144 | 144 | assert_equal [ |
|
145 | 145 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
146 | 146 | ], changesets.collect(&:revision) |
|
147 | 147 | |
|
148 | 148 | changesets = @repository.latest_changesets('README', 'tag01.annotated') |
|
149 | 149 | assert_equal [ |
|
150 | 150 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
151 | 151 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
152 | 152 | ], changesets.collect(&:revision) |
|
153 | 153 | |
|
154 | 154 | changesets = @repository.latest_changesets('README', 'tag01.annotated', 1) |
|
155 | 155 | assert_equal [ |
|
156 | 156 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
157 | 157 | ], changesets.collect(&:revision) |
|
158 | 158 | |
|
159 | 159 | # with path, branch and limit |
|
160 | 160 | changesets = @repository.latest_changesets('images', 'test_branch') |
|
161 | 161 | assert_equal [ |
|
162 | 162 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
163 | 163 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
164 | 164 | ], changesets.collect(&:revision) |
|
165 | 165 | |
|
166 | 166 | changesets = @repository.latest_changesets('images', 'test_branch', 1) |
|
167 | 167 | assert_equal [ |
|
168 | 168 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
169 | 169 | ], changesets.collect(&:revision) |
|
170 | 170 | |
|
171 | 171 | changesets = @repository.latest_changesets('README', 'test_branch') |
|
172 | 172 | assert_equal [ |
|
173 | 173 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
174 | 174 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
175 | 175 | '899a15dba03a3b350b89c3f537e4bbe02a03cdc9', |
|
176 | 176 | '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
177 | 177 | ], changesets.collect(&:revision) |
|
178 | 178 | |
|
179 | 179 | changesets = @repository.latest_changesets('README', 'test_branch', 2) |
|
180 | 180 | assert_equal [ |
|
181 | 181 | '713f4944648826f558cf548222f813dabe7cbb04', |
|
182 | 182 | '61b685fbe55ab05b5ac68402d5720c1a6ac973d1', |
|
183 | 183 | ], changesets.collect(&:revision) |
|
184 | ||
|
185 | # latin-1 encoding path | |
|
186 | changesets = @repository.latest_changesets( | |
|
187 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89') | |
|
188 | assert_equal [ | |
|
189 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', | |
|
190 | '4fc55c43bf3d3dc2efb66145365ddc17639ce81e', | |
|
191 | ], changesets.collect(&:revision) | |
|
192 | ||
|
193 | changesets = @repository.latest_changesets( | |
|
194 | "latin-1-dir/test-#{@char_1}-2.txt", '64f1f3e89', 1) | |
|
195 | assert_equal [ | |
|
196 | '64f1f3e89ad1cb57976ff0ad99a107012ba3481d', | |
|
197 | ], changesets.collect(&:revision) | |
|
184 | 198 | end |
|
185 | 199 | |
|
186 | 200 | def test_find_changeset_by_name |
|
187 | 201 | @repository.fetch_changesets |
|
188 | 202 | @repository.reload |
|
189 | 203 | ['7234cb2750b63f47bff735edc50a1c0a433c2518', '7234cb2750b'].each do |r| |
|
190 | 204 | assert_equal '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
191 | 205 | @repository.find_changeset_by_name(r).revision |
|
192 | 206 | end |
|
193 | 207 | end |
|
194 | 208 | |
|
195 | 209 | def test_find_changeset_by_empty_name |
|
196 | 210 | @repository.fetch_changesets |
|
197 | 211 | @repository.reload |
|
198 | 212 | ['', ' ', nil].each do |r| |
|
199 | 213 | assert_nil @repository.find_changeset_by_name(r) |
|
200 | 214 | end |
|
201 | 215 | end |
|
202 | 216 | |
|
203 | 217 | def test_identifier |
|
204 | 218 | @repository.fetch_changesets |
|
205 | 219 | @repository.reload |
|
206 | 220 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
207 | 221 | assert_equal c.scmid, c.identifier |
|
208 | 222 | end |
|
209 | 223 | |
|
210 | 224 | def test_format_identifier |
|
211 | 225 | @repository.fetch_changesets |
|
212 | 226 | @repository.reload |
|
213 | 227 | c = @repository.changesets.find_by_revision('7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
214 | 228 | assert_equal '7234cb27', c.format_identifier |
|
215 | 229 | end |
|
216 | 230 | |
|
217 | 231 | def test_activities |
|
218 | 232 | c = Changeset.new(:repository => @repository, |
|
219 | 233 | :committed_on => Time.now, |
|
220 | 234 | :revision => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
221 | 235 | :scmid => 'abc7234cb2750b63f47bff735edc50a1c0a433c2', |
|
222 | 236 | :comments => 'test') |
|
223 | 237 | assert c.event_title.include?('abc7234c:') |
|
224 | 238 | assert_equal 'abc7234cb2750b63f47bff735edc50a1c0a433c2', c.event_url[:rev] |
|
225 | 239 | end |
|
226 | 240 | |
|
227 | 241 | def test_log_utf8 |
|
228 | 242 | @repository.fetch_changesets |
|
229 | 243 | @repository.reload |
|
230 | 244 | str_felix_hex = FELIX_HEX |
|
231 | 245 | if str_felix_hex.respond_to?(:force_encoding) |
|
232 | 246 | str_felix_hex.force_encoding('UTF-8') |
|
233 | 247 | end |
|
234 | 248 | c = @repository.changesets.find_by_revision('ed5bb786bbda2dee66a2d50faf51429dbc043a7b') |
|
235 | 249 | assert_equal "#{str_felix_hex} <felix@fachschaften.org>", c.committer |
|
236 | 250 | end |
|
237 | 251 | else |
|
238 | 252 | puts "Git test repository NOT FOUND. Skipping unit tests !!!" |
|
239 | 253 | def test_fake; assert true end |
|
240 | 254 | end |
|
241 | 255 | end |
General Comments 0
You need to be logged in to leave comments.
Login now