comparison test/unit/.svn/text-base/changeset_test.rb.svn-base @ 245:051f544170fe

* Update to SVN trunk revision 4993
author Chris Cannam
date Thu, 03 Mar 2011 11:42:28 +0000
parents 8661b858af72
children cbce1fd3b1b7
comparison
equal deleted inserted replaced
244:8972b600f4fb 245:051f544170fe
70 70
71 def test_ref_keywords_any_with_timelog 71 def test_ref_keywords_any_with_timelog
72 Setting.commit_ref_keywords = '*' 72 Setting.commit_ref_keywords = '*'
73 Setting.commit_logtime_enabled = '1' 73 Setting.commit_logtime_enabled = '1'
74 74
75 c = Changeset.new(:repository => Project.find(1).repository, 75 {
76 :committed_on => 24.hours.ago, 76 '2' => 2.0,
77 :comments => 'Worked on this issue #1 @2h', 77 '2h' => 2.0,
78 :revision => '520', 78 '2hours' => 2.0,
79 :user => User.find(2)) 79 '15m' => 0.25,
80 assert_difference 'TimeEntry.count' do 80 '15min' => 0.25,
81 c.scan_comment_for_issue_ids 81 '3h15' => 3.25,
82 '3h15m' => 3.25,
83 '3h15min' => 3.25,
84 '3:15' => 3.25,
85 '3.25' => 3.25,
86 '3.25h' => 3.25,
87 '3,25' => 3.25,
88 '3,25h' => 3.25,
89 }.each do |syntax, expected_hours|
90 c = Changeset.new(:repository => Project.find(1).repository,
91 :committed_on => 24.hours.ago,
92 :comments => "Worked on this issue #1 @#{syntax}",
93 :revision => '520',
94 :user => User.find(2))
95 assert_difference 'TimeEntry.count' do
96 c.scan_comment_for_issue_ids
97 end
98 assert_equal [1], c.issue_ids.sort
99
100 time = TimeEntry.first(:order => 'id desc')
101 assert_equal 1, time.issue_id
102 assert_equal 1, time.project_id
103 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}"
105 assert_equal Date.yesterday, time.spent_on
106 assert time.activity.is_default?
107 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
82 end 108 end
83 assert_equal [1], c.issue_ids.sort
84
85 time = TimeEntry.first(:order => 'id desc')
86 assert_equal 1, time.issue_id
87 assert_equal 1, time.project_id
88 assert_equal 2, time.user_id
89 assert_equal 2.0, time.hours
90 assert_equal Date.yesterday, time.spent_on
91 assert time.activity.is_default?
92 assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}"
93 end 109 end
94 110
95 def test_ref_keywords_closing_with_timelog 111 def test_ref_keywords_closing_with_timelog
96 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id 112 Setting.commit_fix_status_id = IssueStatus.find(:first, :conditions => ["is_closed = ?", true]).id
97 Setting.commit_ref_keywords = '*' 113 Setting.commit_ref_keywords = '*'
98 Setting.commit_fix_keywords = 'fixes , closes' 114 Setting.commit_fix_keywords = 'fixes , closes'
99 Setting.commit_logtime_enabled = '1' 115 Setting.commit_logtime_enabled = '1'
100 116
101 c = Changeset.new(:repository => Project.find(1).repository, 117 c = Changeset.new(:repository => Project.find(1).repository,
102 :committed_on => Time.now, 118 :committed_on => Time.now,
103 :comments => 'This is a comment. Fixes #1 @2.5, #2 @1', 119 :comments => 'This is a comment. Fixes #1 @4.5, #2 @1',
104 :user => User.find(2)) 120 :user => User.find(2))
105 assert_difference 'TimeEntry.count', 2 do 121 assert_difference 'TimeEntry.count', 2 do
106 c.scan_comment_for_issue_ids 122 c.scan_comment_for_issue_ids
107 end 123 end
108 124
167 c.scan_comment_for_issue_ids 183 c.scan_comment_for_issue_ids
168 184
169 assert_equal [2], c.issue_ids.sort 185 assert_equal [2], c.issue_ids.sort
170 assert c.issues.first.project != c.project 186 assert c.issues.first.project != c.project
171 end 187 end
172 188
173 def test_text_tag_revision 189 def test_text_tag_revision
174 c = Changeset.new(:revision => '520') 190 c = Changeset.new(:revision => '520')
175 assert_equal 'r520', c.text_tag 191 assert_equal 'r520', c.text_tag
176 end 192 end
177 193
178 def test_text_tag_hash 194 def test_text_tag_hash
179 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') 195 c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518')
180 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag 196 assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag
181 end 197 end
182 198
202 218
203 def test_next_nil 219 def test_next_nil
204 changeset = Changeset.find_by_revision('10') 220 changeset = Changeset.find_by_revision('10')
205 assert_nil changeset.next 221 assert_nil changeset.next
206 end 222 end
207 223
208 def test_comments_should_be_converted_to_utf8 224 def test_comments_should_be_converted_to_utf8
209 with_settings :commit_logs_encoding => 'ISO-8859-1' do 225 proj = Project.find(3)
210 c = Changeset.new 226 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
211 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 227 r = Repository::Bazaar.create!(
228 :project => proj, :url => '/tmp/test/bazaar',
229 :log_encoding => 'ISO-8859-1' )
230 assert r
231 c = Changeset.new(:repository => r,
232 :committed_on => Time.now,
233 :revision => '123',
234 :scmid => '12345',
235 :comments => str)
236 assert( c.save )
212 assert_equal "Texte encodé en ISO-8859-1.", c.comments 237 assert_equal "Texte encodé en ISO-8859-1.", c.comments
213 end 238 end
214 end 239
215
216 def test_invalid_utf8_sequences_in_comments_should_be_stripped 240 def test_invalid_utf8_sequences_in_comments_should_be_stripped
217 c = Changeset.new 241 proj = Project.find(3)
218 c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") 242 str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt")
219 assert_equal "Texte encod en ISO-8859-1.", c.comments 243 r = Repository::Bazaar.create!(
244 :project => proj, :url => '/tmp/test/bazaar',
245 :log_encoding => 'UTF-8' )
246 assert r
247 c = Changeset.new(:repository => r,
248 :committed_on => Time.now,
249 :revision => '123',
250 :scmid => '12345',
251 :comments => str)
252 assert( c.save )
253 if str.respond_to?(:force_encoding)
254 assert_equal "Texte encod? en ISO-8859-1.", c.comments
255 else
256 assert_equal "Texte encod en ISO-8859-1.", c.comments
257 end
258 end
259
260 def test_comments_should_be_converted_all_latin1_to_utf8
261 s1 = "\xC2\x80"
262 s2 = "\xc3\x82\xc2\x80"
263 if s1.respond_to?(:force_encoding)
264 s3 = s1
265 s4 = s2
266 s1.force_encoding('ASCII-8BIT')
267 s2.force_encoding('ASCII-8BIT')
268 s3.force_encoding('ISO-8859-1')
269 s4.force_encoding('UTF-8')
270 assert_equal s3.encode('UTF-8'), s4
271 end
272 proj = Project.find(3)
273 r = Repository::Bazaar.create!(
274 :project => proj, :url => '/tmp/test/bazaar',
275 :log_encoding => 'ISO-8859-1' )
276 assert r
277 c = Changeset.new(:repository => r,
278 :committed_on => Time.now,
279 :revision => '123',
280 :scmid => '12345',
281 :comments => s1)
282 assert( c.save )
283 assert_equal s2, c.comments
220 end 284 end
221 285
222 def test_identifier 286 def test_identifier
223 c = Changeset.find_by_revision('1') 287 c = Changeset.find_by_revision('1')
224 assert_equal c.revision, c.identifier 288 assert_equal c.revision, c.identifier