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