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