comparison test/unit/.svn/text-base/changeset_test.rb.svn-base @ 441:cbce1fd3b1b7 redmine-1.2

Update to Redmine 1.2-stable branch (Redmine SVN rev 6000)
author Chris Cannam
date Mon, 06 Jun 2011 14:24:13 +0100
parents 051f544170fe
children
comparison
equal deleted inserted replaced
245:051f544170fe 441:cbce1fd3b1b7
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 19
20 require File.expand_path('../../test_helper', __FILE__) 20 require File.expand_path('../../test_helper', __FILE__)
21 21
22 class ChangesetTest < ActiveSupport::TestCase 22 class ChangesetTest < ActiveSupport::TestCase
23 fixtures :projects, :repositories, :issues, :issue_statuses, :changesets, :changes, :issue_categories, :enumerations, :custom_fields, :custom_values, :users, :members, :member_roles, :trackers 23 fixtures :projects, :repositories,
24 :issues, :issue_statuses, :issue_categories,
25 :changesets, :changes,
26 :enumerations,
27 :custom_fields, :custom_values,
28 :users, :members, :member_roles, :trackers,
29 :enabled_modules, :roles
24 30
25 def setup 31 def setup
26 end 32 end
27 33
28 def test_ref_keywords_any 34 def test_ref_keywords_any
29 ActionMailer::Base.deliveries.clear 35 ActionMailer::Base.deliveries.clear
30 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id 36 Setting.commit_fix_status_id = IssueStatus.find(
37 :first, :conditions => ["is_closed = ?", true]).id
31 Setting.commit_fix_done_ratio = '90' 38 Setting.commit_fix_done_ratio = '90'
32 Setting.commit_ref_keywords = '*' 39 Setting.commit_ref_keywords = '*'
33 Setting.commit_fix_keywords = 'fixes , closes' 40 Setting.commit_fix_keywords = 'fixes , closes'
34 41
35 c = Changeset.new(:repository => Project.find(1).repository, 42 c = Changeset.new(:repository => Project.find(1).repository,
36 :committed_on => Time.now, 43 :committed_on => Time.now,
37 :comments => 'New commit (#2). Fixes #1') 44 :comments => 'New commit (#2). Fixes #1')
38 c.scan_comment_for_issue_ids 45 c.scan_comment_for_issue_ids
39 46
40 assert_equal [1, 2], c.issue_ids.sort 47 assert_equal [1, 2], c.issue_ids.sort
41 fixed = Issue.find(1) 48 fixed = Issue.find(1)
42 assert fixed.closed? 49 assert fixed.closed?
43 assert_equal 90, fixed.done_ratio 50 assert_equal 90, fixed.done_ratio
44 assert_equal 1, ActionMailer::Base.deliveries.size 51 assert_equal 1, ActionMailer::Base.deliveries.size
45 end 52 end
46 53
47 def test_ref_keywords 54 def test_ref_keywords
48 Setting.commit_ref_keywords = 'refs' 55 Setting.commit_ref_keywords = 'refs'
49 Setting.commit_fix_keywords = '' 56 Setting.commit_fix_keywords = ''
50 57
51 c = Changeset.new(:repository => Project.find(1).repository, 58 c = Changeset.new(:repository => Project.find(1).repository,
52 :committed_on => Time.now, 59 :committed_on => Time.now,
53 :comments => 'Ignores #2. Refs #1') 60 :comments => 'Ignores #2. Refs #1')
54 c.scan_comment_for_issue_ids 61 c.scan_comment_for_issue_ids
55 62
56 assert_equal [1], c.issue_ids.sort 63 assert_equal [1], c.issue_ids.sort
57 end 64 end
58 65
59 def test_ref_keywords_any_only 66 def test_ref_keywords_any_only
60 Setting.commit_ref_keywords = '*' 67 Setting.commit_ref_keywords = '*'
61 Setting.commit_fix_keywords = '' 68 Setting.commit_fix_keywords = ''
62 69
63 c = Changeset.new(:repository => Project.find(1).repository, 70 c = Changeset.new(:repository => Project.find(1).repository,
64 :committed_on => Time.now, 71 :committed_on => Time.now,
65 :comments => 'Ignores #2. Refs #1') 72 :comments => 'Ignores #2. Refs #1')
66 c.scan_comment_for_issue_ids 73 c.scan_comment_for_issue_ids
67 74
68 assert_equal [1, 2], c.issue_ids.sort 75 assert_equal [1, 2], c.issue_ids.sort
69 end 76 end
70 77
71 def test_ref_keywords_any_with_timelog 78 def test_ref_keywords_any_with_timelog
72 Setting.commit_ref_keywords = '*' 79 Setting.commit_ref_keywords = '*'
73 Setting.commit_logtime_enabled = '1' 80 Setting.commit_logtime_enabled = '1'
74 81
75 { 82 {
85 '3.25' => 3.25, 92 '3.25' => 3.25,
86 '3.25h' => 3.25, 93 '3.25h' => 3.25,
87 '3,25' => 3.25, 94 '3,25' => 3.25,
88 '3,25h' => 3.25, 95 '3,25h' => 3.25,
89 }.each do |syntax, expected_hours| 96 }.each do |syntax, expected_hours|
90 c = Changeset.new(:repository => Project.find(1).repository, 97 c = Changeset.new(:repository => Project.find(1).repository,
91 :committed_on => 24.hours.ago, 98 :committed_on => 24.hours.ago,
92 :comments => "Worked on this issue #1 @#{syntax}", 99 :comments => "Worked on this issue #1 @#{syntax}",
93 :revision => '520', 100 :revision => '520',
94 :user => User.find(2)) 101 :user => User.find(2))
95 assert_difference 'TimeEntry.count' do 102 assert_difference 'TimeEntry.count' do
96 c.scan_comment_for_issue_ids 103 c.scan_comment_for_issue_ids
97 end 104 end
98 assert_equal [1], c.issue_ids.sort 105 assert_equal [1], c.issue_ids.sort
99 106
100 time = TimeEntry.first(:order => 'id desc') 107 time = TimeEntry.first(:order => 'id desc')
101 assert_equal 1, time.issue_id 108 assert_equal 1, time.issue_id
102 assert_equal 1, time.project_id 109 assert_equal 1, time.project_id
103 assert_equal 2, time.user_id 110 assert_equal 2, time.user_id
104 assert_equal expected_hours, time.hours, "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}" 111 assert_equal expected_hours, time.hours,
112 "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}"
105 assert_equal Date.yesterday, time.spent_on 113 assert_equal Date.yesterday, time.spent_on
106 assert time.activity.is_default? 114 assert time.activity.is_default?
107 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}" 115 assert time.comments.include?('r520'),
108 end 116 "r520 was expected in time_entry comments: #{time.comments}"
109 end 117 end
110 118 end
119
111 def test_ref_keywords_closing_with_timelog 120 def test_ref_keywords_closing_with_timelog
112 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id 121 Setting.commit_fix_status_id = IssueStatus.find(
122 :first, :conditions => ["is_closed = ?", true]).id
113 Setting.commit_ref_keywords = '*' 123 Setting.commit_ref_keywords = '*'
114 Setting.commit_fix_keywords = 'fixes , closes' 124 Setting.commit_fix_keywords = 'fixes , closes'
115 Setting.commit_logtime_enabled = '1' 125 Setting.commit_logtime_enabled = '1'
116 126
117 c = Changeset.new(:repository => Project.find(1).repository, 127 c = Changeset.new(:repository => Project.find(1).repository,
118 :committed_on => Time.now, 128 :committed_on => Time.now,
119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', 129 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
120 :user => User.find(2)) 130 :user => User.find(2))
121 assert_difference 'TimeEntry.count', 2 do 131 assert_difference 'TimeEntry.count', 2 do
122 c.scan_comment_for_issue_ids 132 c.scan_comment_for_issue_ids
123 end 133 end
124 134
125 assert_equal [1, 2], c.issue_ids.sort 135 assert_equal [1, 2], c.issue_ids.sort
126 assert Issue.find(1).closed? 136 assert Issue.find(1).closed?
127 assert Issue.find(2).closed? 137 assert Issue.find(2).closed?
128 138
129 times = TimeEntry.all(:order => 'id desc', :limit => 2) 139 times = TimeEntry.all(:order => 'id desc', :limit => 2)
130 assert_equal [1, 2], times.collect(&:issue_id).sort 140 assert_equal [1, 2], times.collect(&:issue_id).sort
131 end 141 end
132 142
133 def test_ref_keywords_any_line_start 143 def test_ref_keywords_any_line_start
134 Setting.commit_ref_keywords = '*' 144 Setting.commit_ref_keywords = '*'
135 145
136 c = Changeset.new(:repository => Project.find(1).repository, 146 c = Changeset.new(:repository => Project.find(1).repository,
137 :committed_on => Time.now, 147 :committed_on => Time.now,
138 :comments => '#1 is the reason of this commit') 148 :comments => '#1 is the reason of this commit')
139 c.scan_comment_for_issue_ids 149 c.scan_comment_for_issue_ids
140 150
141 assert_equal [1], c.issue_ids.sort 151 assert_equal [1], c.issue_ids.sort
142 end 152 end
143 153
144 def test_ref_keywords_allow_brackets_around_a_issue_number 154 def test_ref_keywords_allow_brackets_around_a_issue_number
145 Setting.commit_ref_keywords = '*' 155 Setting.commit_ref_keywords = '*'
146 156
147 c = Changeset.new(:repository => Project.find(1).repository, 157 c = Changeset.new(:repository => Project.find(1).repository,
148 :committed_on => Time.now, 158 :committed_on => Time.now,
149 :comments => '[#1] Worked on this issue') 159 :comments => '[#1] Worked on this issue')
150 c.scan_comment_for_issue_ids 160 c.scan_comment_for_issue_ids
151 161
152 assert_equal [1], c.issue_ids.sort 162 assert_equal [1], c.issue_ids.sort
153 end 163 end
154 164
155 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers 165 def test_ref_keywords_allow_brackets_around_multiple_issue_numbers
156 Setting.commit_ref_keywords = '*' 166 Setting.commit_ref_keywords = '*'
157 167
158 c = Changeset.new(:repository => Project.find(1).repository, 168 c = Changeset.new(:repository => Project.find(1).repository,
159 :committed_on => Time.now, 169 :committed_on => Time.now,
160 :comments => '[#1 #2, #3] Worked on these') 170 :comments => '[#1 #2, #3] Worked on these')
161 c.scan_comment_for_issue_ids 171 c.scan_comment_for_issue_ids
162 172
163 assert_equal [1,2,3], c.issue_ids.sort 173 assert_equal [1,2,3], c.issue_ids.sort
164 end 174 end
165 175
166 def test_commit_referencing_a_subproject_issue 176 def test_commit_referencing_a_subproject_issue
167 c = Changeset.new(:repository => Project.find(1).repository, 177 c = Changeset.new(:repository => Project.find(1).repository,
168 :committed_on => Time.now, 178 :committed_on => Time.now,
169 :comments => 'refs #5, a subproject issue') 179 :comments => 'refs #5, a subproject issue')
170 c.scan_comment_for_issue_ids 180 c.scan_comment_for_issue_ids
171 181
172 assert_equal [5], c.issue_ids.sort 182 assert_equal [5], c.issue_ids.sort
173 assert c.issues.first.project != c.project 183 assert c.issues.first.project != c.project
174 end 184 end
175 185
176 def test_commit_referencing_a_parent_project_issue 186 def test_commit_referencing_a_parent_project_issue
177 # repository of child project 187 # repository of child project
178 r = Repository::Subversion.create!(:project => Project.find(3), :url => 'svn://localhost/test') 188 r = Repository::Subversion.create!(
179 189 :project => Project.find(3),
180 c = Changeset.new(:repository => r, 190 :url => 'svn://localhost/test')
181 :committed_on => Time.now, 191
182 :comments => 'refs #2, an issue of a parent project') 192 c = Changeset.new(:repository => r,
183 c.scan_comment_for_issue_ids 193 :committed_on => Time.now,
184 194 :comments => 'refs #2, an issue of a parent project')
195 c.scan_comment_for_issue_ids
196
185 assert_equal [2], c.issue_ids.sort 197 assert_equal [2], c.issue_ids.sort
186 assert c.issues.first.project != c.project 198 assert c.issues.first.project != c.project
187 end 199 end
188 200
189 def test_text_tag_revision 201 def test_text_tag_revision
190 c = Changeset.new(:revision => '520') 202 c = Changeset.new(:revision => '520')
191 assert_equal 'r520', c.text_tag 203 assert_equal 'r520', c.text_tag
192 end 204 end
193 205
194 def test_text_tag_hash 206 def test_text_tag_hash
195 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') 207 c = Changeset.new(
208 :scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518',
209 :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
196 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag 210 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
197 end 211 end
198 212
199 def test_text_tag_hash_all_number 213 def test_text_tag_hash_all_number
200 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789') 214 c = Changeset.new(:scmid => '0123456789', :revision => '0123456789')
220 changeset = Changeset.find_by_revision('10') 234 changeset = Changeset.find_by_revision('10')
221 assert_nil changeset.next 235 assert_nil changeset.next
222 end 236 end
223 237
224 def test_comments_should_be_converted_to_utf8 238 def test_comments_should_be_converted_to_utf8
225 proj = Project.find(3) 239 proj = Project.find(3)
226 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 240 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
227 r = Repository::Bazaar.create!( 241 str = "Texte encod\xe9 en ISO-8859-1."
228 :project => proj, :url => '/tmp/test/bazaar', 242 str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
243 r = Repository::Bazaar.create!(
244 :project => proj,
245 :url => '/tmp/test/bazaar',
229 :log_encoding => 'ISO-8859-1' ) 246 :log_encoding => 'ISO-8859-1' )
230 assert r 247 assert r
231 c = Changeset.new(:repository => r, 248 c = Changeset.new(:repository => r,
232 :committed_on => Time.now, 249 :committed_on => Time.now,
233 :revision => '123', 250 :revision => '123',
234 :scmid => '12345', 251 :scmid => '12345',
235 :comments => str) 252 :comments => str)
236 assert( c.save ) 253 assert( c.save )
237 assert_equal "Texte encodé en ISO-8859-1.", c.comments 254 str_utf8 = "Texte encod\xc3\xa9 en ISO-8859-1."
238 end 255 str_utf8.force_encoding("UTF-8") if str_utf8.respond_to?(:force_encoding)
239 256 assert_equal str_utf8, c.comments
240 def test_invalid_utf8_sequences_in_comments_should_be_stripped 257 end
241 proj = Project.find(3) 258
242 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 259 def test_invalid_utf8_sequences_in_comments_should_be_replaced_latin1
243 r = Repository::Bazaar.create!( 260 proj = Project.find(3)
244 :project => proj, :url => '/tmp/test/bazaar', 261 # str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
262 str1 = "Texte encod\xe9 en ISO-8859-1."
263 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
264 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
265 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
266 r = Repository::Bazaar.create!(
267 :project => proj,
268 :url => '/tmp/test/bazaar',
245 :log_encoding => 'UTF-8' ) 269 :log_encoding => 'UTF-8' )
246 assert r 270 assert r
247 c = Changeset.new(:repository => r, 271 c = Changeset.new(:repository => r,
248 :committed_on => Time.now, 272 :committed_on => Time.now,
249 :revision => '123', 273 :revision => '123',
250 :scmid => '12345', 274 :scmid => '12345',
251 :comments => str) 275 :comments => str1,
252 assert( c.save ) 276 :committer => str2)
253 if str.respond_to?(:force_encoding) 277 assert( c.save )
254 assert_equal "Texte encod? en ISO-8859-1.", c.comments 278 assert_equal "Texte encod? en ISO-8859-1.", c.comments
255 else 279 assert_equal "?a?b?c?d?e test", c.committer
256 assert_equal "Texte encod en ISO-8859-1.", c.comments 280 end
257 end 281
282 def test_invalid_utf8_sequences_in_comments_should_be_replaced_ja_jis
283 proj = Project.find(3)
284 str = "test\xb5\xfetest\xb5\xfe"
285 if str.respond_to?(:force_encoding)
286 str.force_encoding('ASCII-8BIT')
287 end
288 r = Repository::Bazaar.create!(
289 :project => proj,
290 :url => '/tmp/test/bazaar',
291 :log_encoding => 'ISO-2022-JP' )
292 assert r
293 c = Changeset.new(:repository => r,
294 :committed_on => Time.now,
295 :revision => '123',
296 :scmid => '12345',
297 :comments => str)
298 assert( c.save )
299 assert_equal "test??test??", c.comments
258 end 300 end
259 301
260 def test_comments_should_be_converted_all_latin1_to_utf8 302 def test_comments_should_be_converted_all_latin1_to_utf8
261 s1 = "\xC2\x80" 303 s1 = "\xC2\x80"
262 s2 = "\xc3\x82\xc2\x80" 304 s2 = "\xc3\x82\xc2\x80"
263 if s1.respond_to?(:force_encoding) 305 s4 = s2.dup
264 s3 = s1 306 if s1.respond_to?(:force_encoding)
265 s4 = s2 307 s3 = s1.dup
266 s1.force_encoding('ASCII-8BIT') 308 s1.force_encoding('ASCII-8BIT')
267 s2.force_encoding('ASCII-8BIT') 309 s2.force_encoding('ASCII-8BIT')
268 s3.force_encoding('ISO-8859-1') 310 s3.force_encoding('ISO-8859-1')
269 s4.force_encoding('UTF-8') 311 s4.force_encoding('UTF-8')
270 assert_equal s3.encode('UTF-8'), s4 312 assert_equal s3.encode('UTF-8'), s4
271 end 313 end
272 proj = Project.find(3) 314 proj = Project.find(3)
273 r = Repository::Bazaar.create!( 315 r = Repository::Bazaar.create!(
274 :project => proj, :url => '/tmp/test/bazaar', 316 :project => proj,
317 :url => '/tmp/test/bazaar',
275 :log_encoding => 'ISO-8859-1' ) 318 :log_encoding => 'ISO-8859-1' )
276 assert r 319 assert r
277 c = Changeset.new(:repository => r, 320 c = Changeset.new(:repository => r,
278 :committed_on => Time.now, 321 :committed_on => Time.now,
279 :revision => '123', 322 :revision => '123',
280 :scmid => '12345', 323 :scmid => '12345',
281 :comments => s1) 324 :comments => s1)
282 assert( c.save ) 325 assert( c.save )
283 assert_equal s2, c.comments 326 assert_equal s4, c.comments
327 end
328
329 def test_invalid_utf8_sequences_in_paths_should_be_replaced
330 proj = Project.find(3)
331 str1 = "Texte encod\xe9 en ISO-8859-1"
332 str2 = "\xe9a\xe9b\xe9c\xe9d\xe9e test"
333 str1.force_encoding("UTF-8") if str1.respond_to?(:force_encoding)
334 str2.force_encoding("ASCII-8BIT") if str2.respond_to?(:force_encoding)
335 r = Repository::Bazaar.create!(
336 :project => proj,
337 :url => '/tmp/test/bazaar',
338 :log_encoding => 'UTF-8' )
339 assert r
340 cs = Changeset.new(
341 :repository => r,
342 :committed_on => Time.now,
343 :revision => '123',
344 :scmid => '12345',
345 :comments => "test")
346 assert(cs.save)
347 ch = Change.new(
348 :changeset => cs,
349 :action => "A",
350 :path => str1,
351 :from_path => str2,
352 :from_revision => "345")
353 assert(ch.save)
354 assert_equal "Texte encod? en ISO-8859-1", ch.path
355 assert_equal "?a?b?c?d?e test", ch.from_path
356 end
357
358 def test_comments_nil
359 proj = Project.find(3)
360 r = Repository::Bazaar.create!(
361 :project => proj,
362 :url => '/tmp/test/bazaar',
363 :log_encoding => 'ISO-8859-1' )
364 assert r
365 c = Changeset.new(:repository => r,
366 :committed_on => Time.now,
367 :revision => '123',
368 :scmid => '12345',
369 :comments => nil,
370 :committer => nil)
371 assert( c.save )
372 assert_equal "", c.comments
373 assert_equal nil, c.committer
374 if c.comments.respond_to?(:force_encoding)
375 assert_equal "UTF-8", c.comments.encoding.to_s
376 end
377 end
378
379 def test_comments_empty
380 proj = Project.find(3)
381 r = Repository::Bazaar.create!(
382 :project => proj,
383 :url => '/tmp/test/bazaar',
384 :log_encoding => 'ISO-8859-1' )
385 assert r
386 c = Changeset.new(:repository => r,
387 :committed_on => Time.now,
388 :revision => '123',
389 :scmid => '12345',
390 :comments => "",
391 :committer => "")
392 assert( c.save )
393 assert_equal "", c.comments
394 assert_equal "", c.committer
395 if c.comments.respond_to?(:force_encoding)
396 assert_equal "UTF-8", c.comments.encoding.to_s
397 assert_equal "UTF-8", c.committer.encoding.to_s
398 end
284 end 399 end
285 400
286 def test_identifier 401 def test_identifier
287 c = Changeset.find_by_revision('1') 402 c = Changeset.find_by_revision('1')
288 assert_equal c.revision, c.identifier 403 assert_equal c.revision, c.identifier