##// END OF EJS Templates
scm: use save instead of scan_comment_for_issue_ids at test_ref_keywords of unit changeset test....
Toshi MARUYAMA -
r6607:1afcc4cd5b1e
parent child
Show More
@@ -1,405 +1,404
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 c.scan_comment_for_issue_ids
62
61 assert c.save
63 62 assert_equal [1], c.issue_ids.sort
64 63 end
65 64
66 65 def test_ref_keywords_any_only
67 66 Setting.commit_ref_keywords = '*'
68 67 Setting.commit_fix_keywords = ''
69 68
70 69 c = Changeset.new(:repository => Project.find(1).repository,
71 70 :committed_on => Time.now,
72 71 :comments => 'Ignores #2. Refs #1')
73 72 c.scan_comment_for_issue_ids
74 73
75 74 assert_equal [1, 2], c.issue_ids.sort
76 75 end
77 76
78 77 def test_ref_keywords_any_with_timelog
79 78 Setting.commit_ref_keywords = '*'
80 79 Setting.commit_logtime_enabled = '1'
81 80
82 81 {
83 82 '2' => 2.0,
84 83 '2h' => 2.0,
85 84 '2hours' => 2.0,
86 85 '15m' => 0.25,
87 86 '15min' => 0.25,
88 87 '3h15' => 3.25,
89 88 '3h15m' => 3.25,
90 89 '3h15min' => 3.25,
91 90 '3:15' => 3.25,
92 91 '3.25' => 3.25,
93 92 '3.25h' => 3.25,
94 93 '3,25' => 3.25,
95 94 '3,25h' => 3.25,
96 95 }.each do |syntax, expected_hours|
97 96 c = Changeset.new(:repository => Project.find(1).repository,
98 97 :committed_on => 24.hours.ago,
99 98 :comments => "Worked on this issue #1 @#{syntax}",
100 99 :revision => '520',
101 100 :user => User.find(2))
102 101 assert_difference 'TimeEntry.count' do
103 102 c.scan_comment_for_issue_ids
104 103 end
105 104 assert_equal [1], c.issue_ids.sort
106 105
107 106 time = TimeEntry.first(:order => 'id desc')
108 107 assert_equal 1, time.issue_id
109 108 assert_equal 1, time.project_id
110 109 assert_equal 2, time.user_id
111 110 assert_equal expected_hours, time.hours,
112 111 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
113 112 assert_equal Date.yesterday, time.spent_on
114 113 assert time.activity.is_default?
115 114 assert time.comments.include?('r520'),
116 115 "r520 was expected in time_entry comments: #{time.comments}"
117 116 end
118 117 end
119 118
120 119 def test_ref_keywords_closing_with_timelog
121 120 Setting.commit_fix_status_id = IssueStatus.find(
122 121 :first, :conditions => ["is_closed = ?", true]).id
123 122 Setting.commit_ref_keywords = '*'
124 123 Setting.commit_fix_keywords = 'fixes , closes'
125 124 Setting.commit_logtime_enabled = '1'
126 125
127 126 c = Changeset.new(:repository => Project.find(1).repository,
128 127 :committed_on => Time.now,
129 128 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
130 129 :user => User.find(2))
131 130 assert_difference 'TimeEntry.count', 2 do
132 131 c.scan_comment_for_issue_ids
133 132 end
134 133
135 134 assert_equal [1, 2], c.issue_ids.sort
136 135 assert Issue.find(1).closed?
137 136 assert Issue.find(2).closed?
138 137
139 138 times = TimeEntry.all(:order => 'id desc', :limit => 2)
140 139 assert_equal [1, 2], times.collect(&:issue_id).sort
141 140 end
142 141
143 142 def test_ref_keywords_any_line_start
144 143 Setting.commit_ref_keywords = '*'
145 144
146 145 c = Changeset.new(:repository => Project.find(1).repository,
147 146 :committed_on => Time.now,
148 147 :comments => '#1 is the reason of this commit')
149 148 c.scan_comment_for_issue_ids
150 149
151 150 assert_equal [1], c.issue_ids.sort
152 151 end
153 152
154 153 def test_ref_keywords_allow_brackets_around_a_issue_number
155 154 Setting.commit_ref_keywords = '*'
156 155
157 156 c = Changeset.new(:repository => Project.find(1).repository,
158 157 :committed_on => Time.now,
159 158 :comments => '[#1] Worked on this issue')
160 159 c.scan_comment_for_issue_ids
161 160
162 161 assert_equal [1], c.issue_ids.sort
163 162 end
164 163
165 164 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
166 165 Setting.commit_ref_keywords = '*'
167 166
168 167 c = Changeset.new(:repository => Project.find(1).repository,
169 168 :committed_on => Time.now,
170 169 :comments => '[#1 #2, #3] Worked on these')
171 170 c.scan_comment_for_issue_ids
172 171
173 172 assert_equal [1,2,3], c.issue_ids.sort
174 173 end
175 174
176 175 def test_commit_referencing_a_subproject_issue
177 176 c = Changeset.new(:repository => Project.find(1).repository,
178 177 :committed_on => Time.now,
179 178 :comments => 'refs #5, a subproject issue')
180 179 c.scan_comment_for_issue_ids
181 180
182 181 assert_equal [5], c.issue_ids.sort
183 182 assert c.issues.first.project != c.project
184 183 end
185 184
186 185 def test_commit_referencing_a_parent_project_issue
187 186 # repository of child project
188 187 r = Repository::Subversion.create!(
189 188 :project => Project.find(3),
190 189 :url => 'svn://localhost/test')
191 190
192 191 c = Changeset.new(:repository => r,
193 192 :committed_on => Time.now,
194 193 :comments => 'refs #2, an issue of a parent project')
195 194 c.scan_comment_for_issue_ids
196 195
197 196 assert_equal [2], c.issue_ids.sort
198 197 assert c.issues.first.project != c.project
199 198 end
200 199
201 200 def test_text_tag_revision
202 201 c = Changeset.new(:revision => '520')
203 202 assert_equal 'r520', c.text_tag
204 203 end
205 204
206 205 def test_text_tag_hash
207 206 c = Changeset.new(
208 207 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
209 208 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
210 209 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
211 210 end
212 211
213 212 def test_text_tag_hash_all_number
214 213 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
215 214 assert_equal 'commit:0123456789', c.text_tag
216 215 end
217 216
218 217 def test_previous
219 218 changeset = Changeset.find_by_revision('3')
220 219 assert_equal Changeset.find_by_revision('2'), changeset.previous
221 220 end
222 221
223 222 def test_previous_nil
224 223 changeset = Changeset.find_by_revision('1')
225 224 assert_nil changeset.previous
226 225 end
227 226
228 227 def test_next
229 228 changeset = Changeset.find_by_revision('2')
230 229 assert_equal Changeset.find_by_revision('3'), changeset.next
231 230 end
232 231
233 232 def test_next_nil
234 233 changeset = Changeset.find_by_revision('10')
235 234 assert_nil changeset.next
236 235 end
237 236
238 237 def test_comments_should_be_converted_to_utf8
239 238 proj = Project.find(3)
240 239 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
241 240 str = "Texte encod\xe9 en ISO-8859-1."
242 241 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
243 242 r = Repository::Bazaar.create!(
244 243 :project => proj,
245 244 :url => '/tmp/test/bazaar',
246 245 :log_encoding => 'ISO-8859-1' )
247 246 assert r
248 247 c = Changeset.new(:repository => r,
249 248 :committed_on => Time.now,
250 249 :revision => '123',
251 250 :scmid => '12345',
252 251 :comments => str)
253 252 assert( c.save )
254 253 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
255 254 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
256 255 assert_equal str_utf8, c.comments
257 256 end
258 257
259 258 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
260 259 proj = Project.find(3)
261 260 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
262 261 str1 = "Texte encod\xe9 en ISO-8859-1."
263 262 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
264 263 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
265 264 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
266 265 r = Repository::Bazaar.create!(
267 266 :project => proj,
268 267 :url => '/tmp/test/bazaar',
269 268 :log_encoding => 'UTF-8' )
270 269 assert r
271 270 c = Changeset.new(:repository => r,
272 271 :committed_on => Time.now,
273 272 :revision => '123',
274 273 :scmid => '12345',
275 274 :comments => str1,
276 275 :committer => str2)
277 276 assert( c.save )
278 277 assert_equal "Texte encod? en ISO-8859-1.", c.comments
279 278 assert_equal "?a?b?c?d?e test", c.committer
280 279 end
281 280
282 281 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
283 282 proj = Project.find(3)
284 283 str = "test\xb5\xfetest\xb5\xfe"
285 284 if str.respond_to?(:force_encoding)
286 285 str.force_encoding('ASCII-8BIT')
287 286 end
288 287 r = Repository::Bazaar.create!(
289 288 :project => proj,
290 289 :url => '/tmp/test/bazaar',
291 290 :log_encoding => 'ISO-2022-JP' )
292 291 assert r
293 292 c = Changeset.new(:repository => r,
294 293 :committed_on => Time.now,
295 294 :revision => '123',
296 295 :scmid => '12345',
297 296 :comments => str)
298 297 assert( c.save )
299 298 assert_equal "test??test??", c.comments
300 299 end
301 300
302 301 def test_comments_should_be_converted_all_latin1_to_utf8
303 302 s1 = "\xC2\x80"
304 303 s2 = "\xc3\x82\xc2\x80"
305 304 s4 = s2.dup
306 305 if s1.respond_to?(:force_encoding)
307 306 s3 = s1.dup
308 307 s1.force_encoding('ASCII-8BIT')
309 308 s2.force_encoding('ASCII-8BIT')
310 309 s3.force_encoding('ISO-8859-1')
311 310 s4.force_encoding('UTF-8')
312 311 assert_equal s3.encode('UTF-8'), s4
313 312 end
314 313 proj = Project.find(3)
315 314 r = Repository::Bazaar.create!(
316 315 :project => proj,
317 316 :url => '/tmp/test/bazaar',
318 317 :log_encoding => 'ISO-8859-1' )
319 318 assert r
320 319 c = Changeset.new(:repository => r,
321 320 :committed_on => Time.now,
322 321 :revision => '123',
323 322 :scmid => '12345',
324 323 :comments => s1)
325 324 assert( c.save )
326 325 assert_equal s4, c.comments
327 326 end
328 327
329 328 def test_invalid_utf8_sequences_in_paths_should_be_replaced
330 329 proj = Project.find(3)
331 330 str1 = "Texte encod\xe9 en ISO-8859-1"
332 331 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
333 332 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
334 333 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
335 334 r = Repository::Bazaar.create!(
336 335 :project => proj,
337 336 :url => '/tmp/test/bazaar',
338 337 :log_encoding => 'UTF-8' )
339 338 assert r
340 339 cs = Changeset.new(
341 340 :repository => r,
342 341 :committed_on => Time.now,
343 342 :revision => '123',
344 343 :scmid => '12345',
345 344 :comments => "test")
346 345 assert(cs.save)
347 346 ch = Change.new(
348 347 :changeset => cs,
349 348 :action => "A",
350 349 :path => str1,
351 350 :from_path => str2,
352 351 :from_revision => "345")
353 352 assert(ch.save)
354 353 assert_equal "Texte encod? en ISO-8859-1", ch.path
355 354 assert_equal "?a?b?c?d?e test", ch.from_path
356 355 end
357 356
358 357 def test_comments_nil
359 358 proj = Project.find(3)
360 359 r = Repository::Bazaar.create!(
361 360 :project => proj,
362 361 :url => '/tmp/test/bazaar',
363 362 :log_encoding => 'ISO-8859-1' )
364 363 assert r
365 364 c = Changeset.new(:repository => r,
366 365 :committed_on => Time.now,
367 366 :revision => '123',
368 367 :scmid => '12345',
369 368 :comments => nil,
370 369 :committer => nil)
371 370 assert( c.save )
372 371 assert_equal "", c.comments
373 372 assert_equal nil, c.committer
374 373 if c.comments.respond_to?(:force_encoding)
375 374 assert_equal "UTF-8", c.comments.encoding.to_s
376 375 end
377 376 end
378 377
379 378 def test_comments_empty
380 379 proj = Project.find(3)
381 380 r = Repository::Bazaar.create!(
382 381 :project => proj,
383 382 :url => '/tmp/test/bazaar',
384 383 :log_encoding => 'ISO-8859-1' )
385 384 assert r
386 385 c = Changeset.new(:repository => r,
387 386 :committed_on => Time.now,
388 387 :revision => '123',
389 388 :scmid => '12345',
390 389 :comments => "",
391 390 :committer => "")
392 391 assert( c.save )
393 392 assert_equal "", c.comments
394 393 assert_equal "", c.committer
395 394 if c.comments.respond_to?(:force_encoding)
396 395 assert_equal "UTF-8", c.comments.encoding.to_s
397 396 assert_equal "UTF-8", c.committer.encoding.to_s
398 397 end
399 398 end
400 399
401 400 def test_identifier
402 401 c = Changeset.find_by_revision('1')
403 402 assert_equal c.revision, c.identifier
404 403 end
405 404 end
General Comments 0
You need to be logged in to leave comments. Login now