##// END OF EJS Templates
scm: use save instead of scan_comment_for_issue_ids at test_ref_keywords_any_line_start of unit changeset test....
Toshi MARUYAMA -
r6611:df294c505db1
parent child
Show More
@@ -1,403 +1,402
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 c.scan_comment_for_issue_ids
148
147 assert c.save
149 148 assert_equal [1], c.issue_ids.sort
150 149 end
151 150
152 151 def test_ref_keywords_allow_brackets_around_a_issue_number
153 152 Setting.commit_ref_keywords = '*'
154 153
155 154 c = Changeset.new(:repository => Project.find(1).repository,
156 155 :committed_on => Time.now,
157 156 :comments => '[#1] Worked on this issue')
158 157 c.scan_comment_for_issue_ids
159 158
160 159 assert_equal [1], c.issue_ids.sort
161 160 end
162 161
163 162 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
164 163 Setting.commit_ref_keywords = '*'
165 164
166 165 c = Changeset.new(:repository => Project.find(1).repository,
167 166 :committed_on => Time.now,
168 167 :comments => '[#1 #2, #3] Worked on these')
169 168 c.scan_comment_for_issue_ids
170 169
171 170 assert_equal [1,2,3], c.issue_ids.sort
172 171 end
173 172
174 173 def test_commit_referencing_a_subproject_issue
175 174 c = Changeset.new(:repository => Project.find(1).repository,
176 175 :committed_on => Time.now,
177 176 :comments => 'refs #5, a subproject issue')
178 177 c.scan_comment_for_issue_ids
179 178
180 179 assert_equal [5], c.issue_ids.sort
181 180 assert c.issues.first.project != c.project
182 181 end
183 182
184 183 def test_commit_referencing_a_parent_project_issue
185 184 # repository of child project
186 185 r = Repository::Subversion.create!(
187 186 :project => Project.find(3),
188 187 :url => 'svn://localhost/test')
189 188
190 189 c = Changeset.new(:repository => r,
191 190 :committed_on => Time.now,
192 191 :comments => 'refs #2, an issue of a parent project')
193 192 c.scan_comment_for_issue_ids
194 193
195 194 assert_equal [2], c.issue_ids.sort
196 195 assert c.issues.first.project != c.project
197 196 end
198 197
199 198 def test_text_tag_revision
200 199 c = Changeset.new(:revision => '520')
201 200 assert_equal 'r520', c.text_tag
202 201 end
203 202
204 203 def test_text_tag_hash
205 204 c = Changeset.new(
206 205 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
207 206 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
208 207 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
209 208 end
210 209
211 210 def test_text_tag_hash_all_number
212 211 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
213 212 assert_equal 'commit:0123456789', c.text_tag
214 213 end
215 214
216 215 def test_previous
217 216 changeset = Changeset.find_by_revision('3')
218 217 assert_equal Changeset.find_by_revision('2'), changeset.previous
219 218 end
220 219
221 220 def test_previous_nil
222 221 changeset = Changeset.find_by_revision('1')
223 222 assert_nil changeset.previous
224 223 end
225 224
226 225 def test_next
227 226 changeset = Changeset.find_by_revision('2')
228 227 assert_equal Changeset.find_by_revision('3'), changeset.next
229 228 end
230 229
231 230 def test_next_nil
232 231 changeset = Changeset.find_by_revision('10')
233 232 assert_nil changeset.next
234 233 end
235 234
236 235 def test_comments_should_be_converted_to_utf8
237 236 proj = Project.find(3)
238 237 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
239 238 str = "Texte encod\xe9 en ISO-8859-1."
240 239 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
241 240 r = Repository::Bazaar.create!(
242 241 :project => proj,
243 242 :url => '/tmp/test/bazaar',
244 243 :log_encoding => 'ISO-8859-1' )
245 244 assert r
246 245 c = Changeset.new(:repository => r,
247 246 :committed_on => Time.now,
248 247 :revision => '123',
249 248 :scmid => '12345',
250 249 :comments => str)
251 250 assert( c.save )
252 251 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
253 252 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
254 253 assert_equal str_utf8, c.comments
255 254 end
256 255
257 256 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
258 257 proj = Project.find(3)
259 258 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
260 259 str1 = "Texte encod\xe9 en ISO-8859-1."
261 260 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
262 261 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
263 262 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
264 263 r = Repository::Bazaar.create!(
265 264 :project => proj,
266 265 :url => '/tmp/test/bazaar',
267 266 :log_encoding => 'UTF-8' )
268 267 assert r
269 268 c = Changeset.new(:repository => r,
270 269 :committed_on => Time.now,
271 270 :revision => '123',
272 271 :scmid => '12345',
273 272 :comments => str1,
274 273 :committer => str2)
275 274 assert( c.save )
276 275 assert_equal "Texte encod? en ISO-8859-1.", c.comments
277 276 assert_equal "?a?b?c?d?e test", c.committer
278 277 end
279 278
280 279 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
281 280 proj = Project.find(3)
282 281 str = "test\xb5\xfetest\xb5\xfe"
283 282 if str.respond_to?(:force_encoding)
284 283 str.force_encoding('ASCII-8BIT')
285 284 end
286 285 r = Repository::Bazaar.create!(
287 286 :project => proj,
288 287 :url => '/tmp/test/bazaar',
289 288 :log_encoding => 'ISO-2022-JP' )
290 289 assert r
291 290 c = Changeset.new(:repository => r,
292 291 :committed_on => Time.now,
293 292 :revision => '123',
294 293 :scmid => '12345',
295 294 :comments => str)
296 295 assert( c.save )
297 296 assert_equal "test??test??", c.comments
298 297 end
299 298
300 299 def test_comments_should_be_converted_all_latin1_to_utf8
301 300 s1 = "\xC2\x80"
302 301 s2 = "\xc3\x82\xc2\x80"
303 302 s4 = s2.dup
304 303 if s1.respond_to?(:force_encoding)
305 304 s3 = s1.dup
306 305 s1.force_encoding('ASCII-8BIT')
307 306 s2.force_encoding('ASCII-8BIT')
308 307 s3.force_encoding('ISO-8859-1')
309 308 s4.force_encoding('UTF-8')
310 309 assert_equal s3.encode('UTF-8'), s4
311 310 end
312 311 proj = Project.find(3)
313 312 r = Repository::Bazaar.create!(
314 313 :project => proj,
315 314 :url => '/tmp/test/bazaar',
316 315 :log_encoding => 'ISO-8859-1' )
317 316 assert r
318 317 c = Changeset.new(:repository => r,
319 318 :committed_on => Time.now,
320 319 :revision => '123',
321 320 :scmid => '12345',
322 321 :comments => s1)
323 322 assert( c.save )
324 323 assert_equal s4, c.comments
325 324 end
326 325
327 326 def test_invalid_utf8_sequences_in_paths_should_be_replaced
328 327 proj = Project.find(3)
329 328 str1 = "Texte encod\xe9 en ISO-8859-1"
330 329 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
331 330 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
332 331 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
333 332 r = Repository::Bazaar.create!(
334 333 :project => proj,
335 334 :url => '/tmp/test/bazaar',
336 335 :log_encoding => 'UTF-8' )
337 336 assert r
338 337 cs = Changeset.new(
339 338 :repository => r,
340 339 :committed_on => Time.now,
341 340 :revision => '123',
342 341 :scmid => '12345',
343 342 :comments => "test")
344 343 assert(cs.save)
345 344 ch = Change.new(
346 345 :changeset => cs,
347 346 :action => "A",
348 347 :path => str1,
349 348 :from_path => str2,
350 349 :from_revision => "345")
351 350 assert(ch.save)
352 351 assert_equal "Texte encod? en ISO-8859-1", ch.path
353 352 assert_equal "?a?b?c?d?e test", ch.from_path
354 353 end
355 354
356 355 def test_comments_nil
357 356 proj = Project.find(3)
358 357 r = Repository::Bazaar.create!(
359 358 :project => proj,
360 359 :url => '/tmp/test/bazaar',
361 360 :log_encoding => 'ISO-8859-1' )
362 361 assert r
363 362 c = Changeset.new(:repository => r,
364 363 :committed_on => Time.now,
365 364 :revision => '123',
366 365 :scmid => '12345',
367 366 :comments => nil,
368 367 :committer => nil)
369 368 assert( c.save )
370 369 assert_equal "", c.comments
371 370 assert_equal nil, c.committer
372 371 if c.comments.respond_to?(:force_encoding)
373 372 assert_equal "UTF-8", c.comments.encoding.to_s
374 373 end
375 374 end
376 375
377 376 def test_comments_empty
378 377 proj = Project.find(3)
379 378 r = Repository::Bazaar.create!(
380 379 :project => proj,
381 380 :url => '/tmp/test/bazaar',
382 381 :log_encoding => 'ISO-8859-1' )
383 382 assert r
384 383 c = Changeset.new(:repository => r,
385 384 :committed_on => Time.now,
386 385 :revision => '123',
387 386 :scmid => '12345',
388 387 :comments => "",
389 388 :committer => "")
390 389 assert( c.save )
391 390 assert_equal "", c.comments
392 391 assert_equal "", c.committer
393 392 if c.comments.respond_to?(:force_encoding)
394 393 assert_equal "UTF-8", c.comments.encoding.to_s
395 394 assert_equal "UTF-8", c.committer.encoding.to_s
396 395 end
397 396 end
398 397
399 398 def test_identifier
400 399 c = Changeset.find_by_revision('1')
401 400 assert_equal c.revision, c.identifier
402 401 end
403 402 end
General Comments 0
You need to be logged in to leave comments. Login now