@@ -1,401 +1,400 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2011 Jean-Philippe Lang |
|
5 | 5 | # |
|
6 | 6 | # This program is free software; you can redistribute it and/or |
|
7 | 7 | # modify it under the terms of the GNU General Public License |
|
8 | 8 | # as published by the Free Software Foundation; either version 2 |
|
9 | 9 | # of the License, or (at your option) any later version. |
|
10 | 10 | # |
|
11 | 11 | # This program is distributed in the hope that it will be useful, |
|
12 | 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 | 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 | 14 | # GNU General Public License for more details. |
|
15 | 15 | # |
|
16 | 16 | # You should have received a copy of the GNU General Public License |
|
17 | 17 | # along with this program; if not, write to the Free Software |
|
18 | 18 | # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
|
19 | 19 | |
|
20 | 20 | require File.expand_path('../../test_helper', __FILE__) |
|
21 | 21 | |
|
22 | 22 | class ChangesetTest < ActiveSupport::TestCase |
|
23 | 23 | fixtures :projects, :repositories, |
|
24 | 24 | :issues, :issue_statuses, :issue_categories, |
|
25 | 25 | :changesets, :changes, |
|
26 | 26 | :enumerations, |
|
27 | 27 | :custom_fields, :custom_values, |
|
28 | 28 | :users, :members, :member_roles, :trackers, |
|
29 | 29 | :enabled_modules, :roles |
|
30 | 30 | |
|
31 | 31 | def setup |
|
32 | 32 | end |
|
33 | 33 | |
|
34 | 34 | def test_ref_keywords_any |
|
35 | 35 | ActionMailer::Base.deliveries.clear |
|
36 | 36 | Setting.commit_fix_status_id = IssueStatus.find( |
|
37 | 37 | :first, :conditions => ["is_closed = ?", true]).id |
|
38 | 38 | Setting.commit_fix_done_ratio = '90' |
|
39 | 39 | Setting.commit_ref_keywords = '*' |
|
40 | 40 | Setting.commit_fix_keywords = 'fixes , closes' |
|
41 | 41 | |
|
42 | 42 | c = Changeset.new(:repository => Project.find(1).repository, |
|
43 | 43 | :committed_on => Time.now, |
|
44 | 44 | :comments => 'New commit (#2). Fixes #1', |
|
45 | 45 | :revision => '12345') |
|
46 | 46 | assert c.save |
|
47 | 47 | assert_equal [1, 2], c.issue_ids.sort |
|
48 | 48 | fixed = Issue.find(1) |
|
49 | 49 | assert fixed.closed? |
|
50 | 50 | assert_equal 90, fixed.done_ratio |
|
51 | 51 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
52 | 52 | end |
|
53 | 53 | |
|
54 | 54 | def test_ref_keywords |
|
55 | 55 | Setting.commit_ref_keywords = 'refs' |
|
56 | 56 | Setting.commit_fix_keywords = '' |
|
57 | 57 | c = Changeset.new(:repository => Project.find(1).repository, |
|
58 | 58 | :committed_on => Time.now, |
|
59 | 59 | :comments => 'Ignores #2. Refs #1', |
|
60 | 60 | :revision => '12345') |
|
61 | 61 | assert c.save |
|
62 | 62 | assert_equal [1], c.issue_ids.sort |
|
63 | 63 | end |
|
64 | 64 | |
|
65 | 65 | def test_ref_keywords_any_only |
|
66 | 66 | Setting.commit_ref_keywords = '*' |
|
67 | 67 | Setting.commit_fix_keywords = '' |
|
68 | 68 | c = Changeset.new(:repository => Project.find(1).repository, |
|
69 | 69 | :committed_on => Time.now, |
|
70 | 70 | :comments => 'Ignores #2. Refs #1', |
|
71 | 71 | :revision => '12345') |
|
72 | 72 | assert c.save |
|
73 | 73 | assert_equal [1, 2], c.issue_ids.sort |
|
74 | 74 | end |
|
75 | 75 | |
|
76 | 76 | def test_ref_keywords_any_with_timelog |
|
77 | 77 | Setting.commit_ref_keywords = '*' |
|
78 | 78 | Setting.commit_logtime_enabled = '1' |
|
79 | 79 | |
|
80 | 80 | { |
|
81 | 81 | '2' => 2.0, |
|
82 | 82 | '2h' => 2.0, |
|
83 | 83 | '2hours' => 2.0, |
|
84 | 84 | '15m' => 0.25, |
|
85 | 85 | '15min' => 0.25, |
|
86 | 86 | '3h15' => 3.25, |
|
87 | 87 | '3h15m' => 3.25, |
|
88 | 88 | '3h15min' => 3.25, |
|
89 | 89 | '3:15' => 3.25, |
|
90 | 90 | '3.25' => 3.25, |
|
91 | 91 | '3.25h' => 3.25, |
|
92 | 92 | '3,25' => 3.25, |
|
93 | 93 | '3,25h' => 3.25, |
|
94 | 94 | }.each do |syntax, expected_hours| |
|
95 | 95 | c = Changeset.new(:repository => Project.find(1).repository, |
|
96 | 96 | :committed_on => 24.hours.ago, |
|
97 | 97 | :comments => "Worked on this issue #1 @#{syntax}", |
|
98 | 98 | :revision => '520', |
|
99 | 99 | :user => User.find(2)) |
|
100 | 100 | assert_difference 'TimeEntry.count' do |
|
101 | 101 | c.scan_comment_for_issue_ids |
|
102 | 102 | end |
|
103 | 103 | assert_equal [1], c.issue_ids.sort |
|
104 | 104 | |
|
105 | 105 | time = TimeEntry.first(:order => 'id desc') |
|
106 | 106 | assert_equal 1, time.issue_id |
|
107 | 107 | assert_equal 1, time.project_id |
|
108 | 108 | assert_equal 2, time.user_id |
|
109 | 109 | assert_equal expected_hours, time.hours, |
|
110 | 110 | "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}" |
|
111 | 111 | assert_equal Date.yesterday, time.spent_on |
|
112 | 112 | assert time.activity.is_default? |
|
113 | 113 | assert time.comments.include?('r520'), |
|
114 | 114 | "r520 was expected in time_entry comments: #{time.comments}" |
|
115 | 115 | end |
|
116 | 116 | end |
|
117 | 117 | |
|
118 | 118 | def test_ref_keywords_closing_with_timelog |
|
119 | 119 | Setting.commit_fix_status_id = IssueStatus.find( |
|
120 | 120 | :first, :conditions => ["is_closed = ?", true]).id |
|
121 | 121 | Setting.commit_ref_keywords = '*' |
|
122 | 122 | Setting.commit_fix_keywords = 'fixes , closes' |
|
123 | 123 | Setting.commit_logtime_enabled = '1' |
|
124 | 124 | |
|
125 | 125 | c = Changeset.new(:repository => Project.find(1).repository, |
|
126 | 126 | :committed_on => Time.now, |
|
127 | 127 | :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', |
|
128 | 128 | :user => User.find(2)) |
|
129 | 129 | assert_difference 'TimeEntry.count', 2 do |
|
130 | 130 | c.scan_comment_for_issue_ids |
|
131 | 131 | end |
|
132 | 132 | |
|
133 | 133 | assert_equal [1, 2], c.issue_ids.sort |
|
134 | 134 | assert Issue.find(1).closed? |
|
135 | 135 | assert Issue.find(2).closed? |
|
136 | 136 | |
|
137 | 137 | times = TimeEntry.all(:order => 'id desc', :limit => 2) |
|
138 | 138 | assert_equal [1, 2], times.collect(&:issue_id).sort |
|
139 | 139 | end |
|
140 | 140 | |
|
141 | 141 | def test_ref_keywords_any_line_start |
|
142 | 142 | Setting.commit_ref_keywords = '*' |
|
143 | 143 | c = Changeset.new(:repository => Project.find(1).repository, |
|
144 | 144 | :committed_on => Time.now, |
|
145 | 145 | :comments => '#1 is the reason of this commit', |
|
146 | 146 | :revision => '12345') |
|
147 | 147 | assert c.save |
|
148 | 148 | assert_equal [1], c.issue_ids.sort |
|
149 | 149 | end |
|
150 | 150 | |
|
151 | 151 | def test_ref_keywords_allow_brackets_around_a_issue_number |
|
152 | 152 | Setting.commit_ref_keywords = '*' |
|
153 | 153 | c = Changeset.new(:repository => Project.find(1).repository, |
|
154 | 154 | :committed_on => Time.now, |
|
155 | 155 | :comments => '[#1] Worked on this issue', |
|
156 | 156 | :revision => '12345') |
|
157 | 157 | assert c.save |
|
158 | 158 | assert_equal [1], c.issue_ids.sort |
|
159 | 159 | end |
|
160 | 160 | |
|
161 | 161 | def test_ref_keywords_allow_brackets_around_multiple_issue_numbers |
|
162 | 162 | Setting.commit_ref_keywords = '*' |
|
163 | 163 | c = Changeset.new(:repository => Project.find(1).repository, |
|
164 | 164 | :committed_on => Time.now, |
|
165 | 165 | :comments => '[#1 #2, #3] Worked on these', |
|
166 | 166 | :revision => '12345') |
|
167 | c.scan_comment_for_issue_ids | |
|
168 | ||
|
167 | assert c.save | |
|
169 | 168 | assert_equal [1,2,3], c.issue_ids.sort |
|
170 | 169 | end |
|
171 | 170 | |
|
172 | 171 | def test_commit_referencing_a_subproject_issue |
|
173 | 172 | c = Changeset.new(:repository => Project.find(1).repository, |
|
174 | 173 | :committed_on => Time.now, |
|
175 | 174 | :comments => 'refs #5, a subproject issue') |
|
176 | 175 | c.scan_comment_for_issue_ids |
|
177 | 176 | |
|
178 | 177 | assert_equal [5], c.issue_ids.sort |
|
179 | 178 | assert c.issues.first.project != c.project |
|
180 | 179 | end |
|
181 | 180 | |
|
182 | 181 | def test_commit_referencing_a_parent_project_issue |
|
183 | 182 | # repository of child project |
|
184 | 183 | r = Repository::Subversion.create!( |
|
185 | 184 | :project => Project.find(3), |
|
186 | 185 | :url => 'svn://localhost/test') |
|
187 | 186 | |
|
188 | 187 | c = Changeset.new(:repository => r, |
|
189 | 188 | :committed_on => Time.now, |
|
190 | 189 | :comments => 'refs #2, an issue of a parent project') |
|
191 | 190 | c.scan_comment_for_issue_ids |
|
192 | 191 | |
|
193 | 192 | assert_equal [2], c.issue_ids.sort |
|
194 | 193 | assert c.issues.first.project != c.project |
|
195 | 194 | end |
|
196 | 195 | |
|
197 | 196 | def test_text_tag_revision |
|
198 | 197 | c = Changeset.new(:revision => '520') |
|
199 | 198 | assert_equal 'r520', c.text_tag |
|
200 | 199 | end |
|
201 | 200 | |
|
202 | 201 | def test_text_tag_hash |
|
203 | 202 | c = Changeset.new( |
|
204 | 203 | :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
205 | 204 | :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
206 | 205 | assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag |
|
207 | 206 | end |
|
208 | 207 | |
|
209 | 208 | def test_text_tag_hash_all_number |
|
210 | 209 | c = Changeset.new(:scmid => '0123456789', :revision => '0123456789') |
|
211 | 210 | assert_equal 'commit:0123456789', c.text_tag |
|
212 | 211 | end |
|
213 | 212 | |
|
214 | 213 | def test_previous |
|
215 | 214 | changeset = Changeset.find_by_revision('3') |
|
216 | 215 | assert_equal Changeset.find_by_revision('2'), changeset.previous |
|
217 | 216 | end |
|
218 | 217 | |
|
219 | 218 | def test_previous_nil |
|
220 | 219 | changeset = Changeset.find_by_revision('1') |
|
221 | 220 | assert_nil changeset.previous |
|
222 | 221 | end |
|
223 | 222 | |
|
224 | 223 | def test_next |
|
225 | 224 | changeset = Changeset.find_by_revision('2') |
|
226 | 225 | assert_equal Changeset.find_by_revision('3'), changeset.next |
|
227 | 226 | end |
|
228 | 227 | |
|
229 | 228 | def test_next_nil |
|
230 | 229 | changeset = Changeset.find_by_revision('10') |
|
231 | 230 | assert_nil changeset.next |
|
232 | 231 | end |
|
233 | 232 | |
|
234 | 233 | def test_comments_should_be_converted_to_utf8 |
|
235 | 234 | proj = Project.find(3) |
|
236 | 235 | # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") |
|
237 | 236 | str = "Texte encod\xe9 en ISO-8859-1." |
|
238 | 237 | str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding) |
|
239 | 238 | r = Repository::Bazaar.create!( |
|
240 | 239 | :project => proj, |
|
241 | 240 | :url => '/tmp/test/bazaar', |
|
242 | 241 | :log_encoding => 'ISO-8859-1' ) |
|
243 | 242 | assert r |
|
244 | 243 | c = Changeset.new(:repository => r, |
|
245 | 244 | :committed_on => Time.now, |
|
246 | 245 | :revision => '123', |
|
247 | 246 | :scmid => '12345', |
|
248 | 247 | :comments => str) |
|
249 | 248 | assert( c.save ) |
|
250 | 249 | str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1." |
|
251 | 250 | str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding) |
|
252 | 251 | assert_equal str_utf8, c.comments |
|
253 | 252 | end |
|
254 | 253 | |
|
255 | 254 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1 |
|
256 | 255 | proj = Project.find(3) |
|
257 | 256 | # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") |
|
258 | 257 | str1 = "Texte encod\xe9 en ISO-8859-1." |
|
259 | 258 | str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
260 | 259 | str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding) |
|
261 | 260 | str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding) |
|
262 | 261 | r = Repository::Bazaar.create!( |
|
263 | 262 | :project => proj, |
|
264 | 263 | :url => '/tmp/test/bazaar', |
|
265 | 264 | :log_encoding => 'UTF-8' ) |
|
266 | 265 | assert r |
|
267 | 266 | c = Changeset.new(:repository => r, |
|
268 | 267 | :committed_on => Time.now, |
|
269 | 268 | :revision => '123', |
|
270 | 269 | :scmid => '12345', |
|
271 | 270 | :comments => str1, |
|
272 | 271 | :committer => str2) |
|
273 | 272 | assert( c.save ) |
|
274 | 273 | assert_equal "Texte encod? en ISO-8859-1.", c.comments |
|
275 | 274 | assert_equal "?a?b?c?d?e test", c.committer |
|
276 | 275 | end |
|
277 | 276 | |
|
278 | 277 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis |
|
279 | 278 | proj = Project.find(3) |
|
280 | 279 | str = "test\xb5\xfetest\xb5\xfe" |
|
281 | 280 | if str.respond_to?(:force_encoding) |
|
282 | 281 | str.force_encoding('ASCII-8BIT') |
|
283 | 282 | end |
|
284 | 283 | r = Repository::Bazaar.create!( |
|
285 | 284 | :project => proj, |
|
286 | 285 | :url => '/tmp/test/bazaar', |
|
287 | 286 | :log_encoding => 'ISO-2022-JP' ) |
|
288 | 287 | assert r |
|
289 | 288 | c = Changeset.new(:repository => r, |
|
290 | 289 | :committed_on => Time.now, |
|
291 | 290 | :revision => '123', |
|
292 | 291 | :scmid => '12345', |
|
293 | 292 | :comments => str) |
|
294 | 293 | assert( c.save ) |
|
295 | 294 | assert_equal "test??test??", c.comments |
|
296 | 295 | end |
|
297 | 296 | |
|
298 | 297 | def test_comments_should_be_converted_all_latin1_to_utf8 |
|
299 | 298 | s1 = "\xC2\x80" |
|
300 | 299 | s2 = "\xc3\x82\xc2\x80" |
|
301 | 300 | s4 = s2.dup |
|
302 | 301 | if s1.respond_to?(:force_encoding) |
|
303 | 302 | s3 = s1.dup |
|
304 | 303 | s1.force_encoding('ASCII-8BIT') |
|
305 | 304 | s2.force_encoding('ASCII-8BIT') |
|
306 | 305 | s3.force_encoding('ISO-8859-1') |
|
307 | 306 | s4.force_encoding('UTF-8') |
|
308 | 307 | assert_equal s3.encode('UTF-8'), s4 |
|
309 | 308 | end |
|
310 | 309 | proj = Project.find(3) |
|
311 | 310 | r = Repository::Bazaar.create!( |
|
312 | 311 | :project => proj, |
|
313 | 312 | :url => '/tmp/test/bazaar', |
|
314 | 313 | :log_encoding => 'ISO-8859-1' ) |
|
315 | 314 | assert r |
|
316 | 315 | c = Changeset.new(:repository => r, |
|
317 | 316 | :committed_on => Time.now, |
|
318 | 317 | :revision => '123', |
|
319 | 318 | :scmid => '12345', |
|
320 | 319 | :comments => s1) |
|
321 | 320 | assert( c.save ) |
|
322 | 321 | assert_equal s4, c.comments |
|
323 | 322 | end |
|
324 | 323 | |
|
325 | 324 | def test_invalid_utf8_sequences_in_paths_should_be_replaced |
|
326 | 325 | proj = Project.find(3) |
|
327 | 326 | str1 = "Texte encod\xe9 en ISO-8859-1" |
|
328 | 327 | str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test" |
|
329 | 328 | str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding) |
|
330 | 329 | str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding) |
|
331 | 330 | r = Repository::Bazaar.create!( |
|
332 | 331 | :project => proj, |
|
333 | 332 | :url => '/tmp/test/bazaar', |
|
334 | 333 | :log_encoding => 'UTF-8' ) |
|
335 | 334 | assert r |
|
336 | 335 | cs = Changeset.new( |
|
337 | 336 | :repository => r, |
|
338 | 337 | :committed_on => Time.now, |
|
339 | 338 | :revision => '123', |
|
340 | 339 | :scmid => '12345', |
|
341 | 340 | :comments => "test") |
|
342 | 341 | assert(cs.save) |
|
343 | 342 | ch = Change.new( |
|
344 | 343 | :changeset => cs, |
|
345 | 344 | :action => "A", |
|
346 | 345 | :path => str1, |
|
347 | 346 | :from_path => str2, |
|
348 | 347 | :from_revision => "345") |
|
349 | 348 | assert(ch.save) |
|
350 | 349 | assert_equal "Texte encod? en ISO-8859-1", ch.path |
|
351 | 350 | assert_equal "?a?b?c?d?e test", ch.from_path |
|
352 | 351 | end |
|
353 | 352 | |
|
354 | 353 | def test_comments_nil |
|
355 | 354 | proj = Project.find(3) |
|
356 | 355 | r = Repository::Bazaar.create!( |
|
357 | 356 | :project => proj, |
|
358 | 357 | :url => '/tmp/test/bazaar', |
|
359 | 358 | :log_encoding => 'ISO-8859-1' ) |
|
360 | 359 | assert r |
|
361 | 360 | c = Changeset.new(:repository => r, |
|
362 | 361 | :committed_on => Time.now, |
|
363 | 362 | :revision => '123', |
|
364 | 363 | :scmid => '12345', |
|
365 | 364 | :comments => nil, |
|
366 | 365 | :committer => nil) |
|
367 | 366 | assert( c.save ) |
|
368 | 367 | assert_equal "", c.comments |
|
369 | 368 | assert_equal nil, c.committer |
|
370 | 369 | if c.comments.respond_to?(:force_encoding) |
|
371 | 370 | assert_equal "UTF-8", c.comments.encoding.to_s |
|
372 | 371 | end |
|
373 | 372 | end |
|
374 | 373 | |
|
375 | 374 | def test_comments_empty |
|
376 | 375 | proj = Project.find(3) |
|
377 | 376 | r = Repository::Bazaar.create!( |
|
378 | 377 | :project => proj, |
|
379 | 378 | :url => '/tmp/test/bazaar', |
|
380 | 379 | :log_encoding => 'ISO-8859-1' ) |
|
381 | 380 | assert r |
|
382 | 381 | c = Changeset.new(:repository => r, |
|
383 | 382 | :committed_on => Time.now, |
|
384 | 383 | :revision => '123', |
|
385 | 384 | :scmid => '12345', |
|
386 | 385 | :comments => "", |
|
387 | 386 | :committer => "") |
|
388 | 387 | assert( c.save ) |
|
389 | 388 | assert_equal "", c.comments |
|
390 | 389 | assert_equal "", c.committer |
|
391 | 390 | if c.comments.respond_to?(:force_encoding) |
|
392 | 391 | assert_equal "UTF-8", c.comments.encoding.to_s |
|
393 | 392 | assert_equal "UTF-8", c.committer.encoding.to_s |
|
394 | 393 | end |
|
395 | 394 | end |
|
396 | 395 | |
|
397 | 396 | def test_identifier |
|
398 | 397 | c = Changeset.find_by_revision('1') |
|
399 | 398 | assert_equal c.revision, c.identifier |
|
400 | 399 | end |
|
401 | 400 | end |
General Comments 0
You need to be logged in to leave comments.
Login now