@@ -1,368 +1,372 | |||
|
1 | 1 | # encoding: utf-8 |
|
2 | 2 | # |
|
3 | 3 | # Redmine - project management software |
|
4 | 4 | # Copyright (C) 2006-2010 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, :issues, :issue_statuses, |
|
24 | 24 | :changesets, :changes, :issue_categories, :enumerations, |
|
25 | 25 | :custom_fields, :custom_values, :users, :members, :member_roles, :trackers |
|
26 | 26 | |
|
27 | 27 | def setup |
|
28 | 28 | end |
|
29 | 29 | |
|
30 | 30 | def test_ref_keywords_any |
|
31 | 31 | ActionMailer::Base.deliveries.clear |
|
32 | 32 | Setting.commit_fix_status_id = IssueStatus.find( |
|
33 | 33 | :first, :conditions => ["is_closed = ?", true]).id |
|
34 | 34 | Setting.commit_fix_done_ratio = '90' |
|
35 | 35 | Setting.commit_ref_keywords = '*' |
|
36 | 36 | Setting.commit_fix_keywords = 'fixes , closes' |
|
37 | 37 | |
|
38 | 38 | c = Changeset.new(:repository => Project.find(1).repository, |
|
39 | 39 | :committed_on => Time.now, |
|
40 | 40 | :comments => 'New commit (#2). Fixes #1') |
|
41 | 41 | c.scan_comment_for_issue_ids |
|
42 | 42 | |
|
43 | 43 | assert_equal [1, 2], c.issue_ids.sort |
|
44 | 44 | fixed = Issue.find(1) |
|
45 | 45 | assert fixed.closed? |
|
46 | 46 | assert_equal 90, fixed.done_ratio |
|
47 | 47 | assert_equal 1, ActionMailer::Base.deliveries.size |
|
48 | 48 | end |
|
49 | 49 | |
|
50 | 50 | def test_ref_keywords |
|
51 | 51 | Setting.commit_ref_keywords = 'refs' |
|
52 | 52 | Setting.commit_fix_keywords = '' |
|
53 | 53 | |
|
54 | 54 | c = Changeset.new(:repository => Project.find(1).repository, |
|
55 | 55 | :committed_on => Time.now, |
|
56 | 56 | :comments => 'Ignores #2. Refs #1') |
|
57 | 57 | c.scan_comment_for_issue_ids |
|
58 | 58 | |
|
59 | 59 | assert_equal [1], c.issue_ids.sort |
|
60 | 60 | end |
|
61 | 61 | |
|
62 | 62 | def test_ref_keywords_any_only |
|
63 | 63 | Setting.commit_ref_keywords = '*' |
|
64 | 64 | Setting.commit_fix_keywords = '' |
|
65 | 65 | |
|
66 | 66 | c = Changeset.new(:repository => Project.find(1).repository, |
|
67 | 67 | :committed_on => Time.now, |
|
68 | 68 | :comments => 'Ignores #2. Refs #1') |
|
69 | 69 | c.scan_comment_for_issue_ids |
|
70 | 70 | |
|
71 | 71 | assert_equal [1, 2], c.issue_ids.sort |
|
72 | 72 | end |
|
73 | 73 | |
|
74 | 74 | def test_ref_keywords_any_with_timelog |
|
75 | 75 | Setting.commit_ref_keywords = '*' |
|
76 | 76 | Setting.commit_logtime_enabled = '1' |
|
77 | 77 | |
|
78 | 78 | { |
|
79 | 79 | '2' => 2.0, |
|
80 | 80 | '2h' => 2.0, |
|
81 | 81 | '2hours' => 2.0, |
|
82 | 82 | '15m' => 0.25, |
|
83 | 83 | '15min' => 0.25, |
|
84 | 84 | '3h15' => 3.25, |
|
85 | 85 | '3h15m' => 3.25, |
|
86 | 86 | '3h15min' => 3.25, |
|
87 | 87 | '3:15' => 3.25, |
|
88 | 88 | '3.25' => 3.25, |
|
89 | 89 | '3.25h' => 3.25, |
|
90 | 90 | '3,25' => 3.25, |
|
91 | 91 | '3,25h' => 3.25, |
|
92 | 92 | }.each do |syntax, expected_hours| |
|
93 | 93 | c = Changeset.new(:repository => Project.find(1).repository, |
|
94 | 94 | :committed_on => 24.hours.ago, |
|
95 | 95 | :comments => "Worked on this issue #1 @#{syntax}", |
|
96 | 96 | :revision => '520', |
|
97 | 97 | :user => User.find(2)) |
|
98 | 98 | assert_difference 'TimeEntry.count' do |
|
99 | 99 | c.scan_comment_for_issue_ids |
|
100 | 100 | end |
|
101 | 101 | assert_equal [1], c.issue_ids.sort |
|
102 | 102 | |
|
103 | 103 | time = TimeEntry.first(:order => 'id desc') |
|
104 | 104 | assert_equal 1, time.issue_id |
|
105 | 105 | assert_equal 1, time.project_id |
|
106 | 106 | assert_equal 2, time.user_id |
|
107 | 107 | assert_equal expected_hours, time.hours, |
|
108 | 108 | "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}" |
|
109 | 109 | assert_equal Date.yesterday, time.spent_on |
|
110 | 110 | assert time.activity.is_default? |
|
111 | 111 | assert time.comments.include?('r520'), |
|
112 | 112 | "r520 was expected in time_entry comments: #{time.comments}" |
|
113 | 113 | end |
|
114 | 114 | end |
|
115 | 115 | |
|
116 | 116 | def test_ref_keywords_closing_with_timelog |
|
117 | 117 | Setting.commit_fix_status_id = IssueStatus.find( |
|
118 | 118 | :first, :conditions => ["is_closed = ?", true]).id |
|
119 | 119 | Setting.commit_ref_keywords = '*' |
|
120 | 120 | Setting.commit_fix_keywords = 'fixes , closes' |
|
121 | 121 | Setting.commit_logtime_enabled = '1' |
|
122 | 122 | |
|
123 | 123 | c = Changeset.new(:repository => Project.find(1).repository, |
|
124 | 124 | :committed_on => Time.now, |
|
125 | 125 | :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', |
|
126 | 126 | :user => User.find(2)) |
|
127 | 127 | assert_difference 'TimeEntry.count', 2 do |
|
128 | 128 | c.scan_comment_for_issue_ids |
|
129 | 129 | end |
|
130 | 130 | |
|
131 | 131 | assert_equal [1, 2], c.issue_ids.sort |
|
132 | 132 | assert Issue.find(1).closed? |
|
133 | 133 | assert Issue.find(2).closed? |
|
134 | 134 | |
|
135 | 135 | times = TimeEntry.all(:order => 'id desc', :limit => 2) |
|
136 | 136 | assert_equal [1, 2], times.collect(&:issue_id).sort |
|
137 | 137 | end |
|
138 | 138 | |
|
139 | 139 | def test_ref_keywords_any_line_start |
|
140 | 140 | Setting.commit_ref_keywords = '*' |
|
141 | 141 | |
|
142 | 142 | c = Changeset.new(:repository => Project.find(1).repository, |
|
143 | 143 | :committed_on => Time.now, |
|
144 | 144 | :comments => '#1 is the reason of this commit') |
|
145 | 145 | c.scan_comment_for_issue_ids |
|
146 | 146 | |
|
147 | 147 | assert_equal [1], c.issue_ids.sort |
|
148 | 148 | end |
|
149 | 149 | |
|
150 | 150 | def test_ref_keywords_allow_brackets_around_a_issue_number |
|
151 | 151 | Setting.commit_ref_keywords = '*' |
|
152 | 152 | |
|
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 | c.scan_comment_for_issue_ids |
|
157 | 157 | |
|
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 | |
|
164 | 164 | c = Changeset.new(:repository => Project.find(1).repository, |
|
165 | 165 | :committed_on => Time.now, |
|
166 | 166 | :comments => '[#1 #2, #3] Worked on these') |
|
167 | 167 | c.scan_comment_for_issue_ids |
|
168 | 168 | |
|
169 | 169 | assert_equal [1,2,3], c.issue_ids.sort |
|
170 | 170 | end |
|
171 | 171 | |
|
172 | 172 | def test_commit_referencing_a_subproject_issue |
|
173 | 173 | c = Changeset.new(:repository => Project.find(1).repository, |
|
174 | 174 | :committed_on => Time.now, |
|
175 | 175 | :comments => 'refs #5, a subproject issue') |
|
176 | 176 | c.scan_comment_for_issue_ids |
|
177 | 177 | |
|
178 | 178 | assert_equal [5], c.issue_ids.sort |
|
179 | 179 | assert c.issues.first.project != c.project |
|
180 | 180 | end |
|
181 | 181 | |
|
182 | 182 | def test_commit_referencing_a_parent_project_issue |
|
183 | 183 | # repository of child project |
|
184 | 184 | r = Repository::Subversion.create!( |
|
185 | 185 | :project => Project.find(3), |
|
186 | 186 | :url => 'svn://localhost/test') |
|
187 | 187 | |
|
188 | 188 | c = Changeset.new(:repository => r, |
|
189 | 189 | :committed_on => Time.now, |
|
190 | 190 | :comments => 'refs #2, an issue of a parent project') |
|
191 | 191 | c.scan_comment_for_issue_ids |
|
192 | 192 | |
|
193 | 193 | assert_equal [2], c.issue_ids.sort |
|
194 | 194 | assert c.issues.first.project != c.project |
|
195 | 195 | end |
|
196 | 196 | |
|
197 | 197 | def test_text_tag_revision |
|
198 | 198 | c = Changeset.new(:revision => '520') |
|
199 | 199 | assert_equal 'r520', c.text_tag |
|
200 | 200 | end |
|
201 | 201 | |
|
202 | 202 | def test_text_tag_hash |
|
203 | 203 | c = Changeset.new( |
|
204 | 204 | :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', |
|
205 | 205 | :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') |
|
206 | 206 | assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag |
|
207 | 207 | end |
|
208 | 208 | |
|
209 | 209 | def test_text_tag_hash_all_number |
|
210 | 210 | c = Changeset.new(:scmid => '0123456789', :revision => '0123456789') |
|
211 | 211 | assert_equal 'commit:0123456789', c.text_tag |
|
212 | 212 | end |
|
213 | 213 | |
|
214 | 214 | def test_previous |
|
215 | 215 | changeset = Changeset.find_by_revision('3') |
|
216 | 216 | assert_equal Changeset.find_by_revision('2'), changeset.previous |
|
217 | 217 | end |
|
218 | 218 | |
|
219 | 219 | def test_previous_nil |
|
220 | 220 | changeset = Changeset.find_by_revision('1') |
|
221 | 221 | assert_nil changeset.previous |
|
222 | 222 | end |
|
223 | 223 | |
|
224 | 224 | def test_next |
|
225 | 225 | changeset = Changeset.find_by_revision('2') |
|
226 | 226 | assert_equal Changeset.find_by_revision('3'), changeset.next |
|
227 | 227 | end |
|
228 | 228 | |
|
229 | 229 | def test_next_nil |
|
230 | 230 | changeset = Changeset.find_by_revision('10') |
|
231 | 231 | assert_nil changeset.next |
|
232 | 232 | end |
|
233 | 233 | |
|
234 | 234 | def test_comments_should_be_converted_to_utf8 |
|
235 | 235 |
|
|
236 | 236 |
|
|
237 | 237 |
|
|
238 | 238 |
|
|
239 | 239 |
|
|
240 |
:project => proj, |
|
|
240 | :project => proj, | |
|
241 | :url => '/tmp/test/bazaar', | |
|
241 | 242 | :log_encoding => 'ISO-8859-1' ) |
|
242 | 243 |
|
|
243 | 244 |
|
|
244 | 245 |
|
|
245 | 246 |
|
|
246 | 247 |
|
|
247 | 248 |
|
|
248 | 249 |
|
|
249 | 250 |
|
|
250 | 251 |
|
|
251 | 252 |
|
|
252 | 253 | end |
|
253 | 254 | |
|
254 | 255 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1 |
|
255 | 256 |
|
|
256 | 257 |
|
|
257 | 258 |
|
|
258 | 259 |
|
|
259 | 260 |
|
|
260 | 261 |
|
|
261 | 262 |
|
|
262 | 263 | :project => proj, |
|
263 | 264 | :url => '/tmp/test/bazaar', |
|
264 | 265 | :log_encoding => 'UTF-8' ) |
|
265 | 266 |
|
|
266 | 267 |
|
|
267 | 268 |
|
|
268 | 269 |
|
|
269 | 270 |
|
|
270 | 271 |
|
|
271 | 272 |
|
|
272 | 273 |
|
|
273 | 274 |
|
|
274 | 275 |
|
|
275 | 276 | end |
|
276 | 277 | |
|
277 | 278 | def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis |
|
278 | 279 |
|
|
279 | 280 |
|
|
280 | 281 |
|
|
281 | 282 |
|
|
282 | 283 |
|
|
283 | 284 |
|
|
284 | 285 | :project => proj, |
|
285 | 286 | :url => '/tmp/test/bazaar', |
|
286 | 287 | :log_encoding => 'ISO-2022-JP' ) |
|
287 | 288 |
|
|
288 | 289 |
|
|
289 | 290 |
|
|
290 | 291 |
|
|
291 | 292 |
|
|
292 | 293 |
|
|
293 | 294 |
|
|
294 | 295 |
|
|
295 | 296 | end |
|
296 | 297 | |
|
297 | 298 | def test_comments_should_be_converted_all_latin1_to_utf8 |
|
298 | 299 |
|
|
299 | 300 |
|
|
300 | 301 |
|
|
301 | 302 |
|
|
302 | 303 |
|
|
303 | 304 |
|
|
304 | 305 |
|
|
305 | 306 |
|
|
306 | 307 |
|
|
307 | 308 |
|
|
308 | 309 |
|
|
309 | 310 |
|
|
310 | 311 |
|
|
311 |
:project => proj, |
|
|
312 | :project => proj, | |
|
313 | :url => '/tmp/test/bazaar', | |
|
312 | 314 | :log_encoding => 'ISO-8859-1' ) |
|
313 | 315 |
|
|
314 | 316 |
|
|
315 | 317 |
|
|
316 | 318 |
|
|
317 | 319 |
|
|
318 | 320 |
|
|
319 | 321 |
|
|
320 | 322 |
|
|
321 | 323 | end |
|
322 | 324 | |
|
323 | 325 | def test_comments_nil |
|
324 | 326 |
|
|
325 | 327 |
|
|
326 |
:project => proj, |
|
|
328 | :project => proj, | |
|
329 | :url => '/tmp/test/bazaar', | |
|
327 | 330 | :log_encoding => 'ISO-8859-1' ) |
|
328 | 331 |
|
|
329 | 332 |
|
|
330 | 333 |
|
|
331 | 334 |
|
|
332 | 335 |
|
|
333 | 336 |
|
|
334 | 337 |
|
|
335 | 338 |
|
|
336 | 339 |
|
|
337 | 340 |
|
|
338 | 341 |
|
|
339 | 342 |
|
|
340 | 343 |
|
|
341 | 344 | end |
|
342 | 345 | |
|
343 | 346 | def test_comments_empty |
|
344 | 347 |
|
|
345 | 348 |
|
|
346 |
:project => proj, |
|
|
349 | :project => proj, | |
|
350 | :url => '/tmp/test/bazaar', | |
|
347 | 351 | :log_encoding => 'ISO-8859-1' ) |
|
348 | 352 |
|
|
349 | 353 |
|
|
350 | 354 |
|
|
351 | 355 |
|
|
352 | 356 |
|
|
353 | 357 |
|
|
354 | 358 |
|
|
355 | 359 |
|
|
356 | 360 |
|
|
357 | 361 |
|
|
358 | 362 |
|
|
359 | 363 |
|
|
360 | 364 |
|
|
361 | 365 |
|
|
362 | 366 | end |
|
363 | 367 | |
|
364 | 368 | def test_identifier |
|
365 | 369 | c = Changeset.find_by_revision('1') |
|
366 | 370 | assert_equal c.revision, c.identifier |
|
367 | 371 | end |
|
368 | 372 | end |
General Comments 0
You need to be logged in to leave comments.
Login now