Mercurial > hg > soundsoftware-site
diff test/unit/changeset_test.rb @ 245:051f544170fe
* Update to SVN trunk revision 4993
author | Chris Cannam |
---|---|
date | Thu, 03 Mar 2011 11:42:28 +0000 |
parents | 8661b858af72 |
children | cbce1fd3b1b7 |
line wrap: on
line diff
--- a/test/unit/changeset_test.rb Thu Mar 03 11:40:10 2011 +0000 +++ b/test/unit/changeset_test.rb Thu Mar 03 11:42:28 2011 +0000 @@ -72,24 +72,40 @@ Setting.commit_ref_keywords = '*' Setting.commit_logtime_enabled = '1' - c = Changeset.new(:repository => Project.find(1).repository, - :committed_on => 24.hours.ago, - :comments => 'Worked on this issue #1 @2h', - :revision => '520', - :user => User.find(2)) - assert_difference 'TimeEntry.count' do - c.scan_comment_for_issue_ids + { + '2' => 2.0, + '2h' => 2.0, + '2hours' => 2.0, + '15m' => 0.25, + '15min' => 0.25, + '3h15' => 3.25, + '3h15m' => 3.25, + '3h15min' => 3.25, + '3:15' => 3.25, + '3.25' => 3.25, + '3.25h' => 3.25, + '3,25' => 3.25, + '3,25h' => 3.25, + }.each do |syntax, expected_hours| + c = Changeset.new(:repository => Project.find(1).repository, + :committed_on => 24.hours.ago, + :comments => "Worked on this issue #1 @#{syntax}", + :revision => '520', + :user => User.find(2)) + assert_difference 'TimeEntry.count' do + c.scan_comment_for_issue_ids + end + assert_equal [1], c.issue_ids.sort + + time = TimeEntry.first(:order => 'id desc') + assert_equal 1, time.issue_id + assert_equal 1, time.project_id + assert_equal 2, time.user_id + assert_equal expected_hours, time.hours, "@#{syntax} should be logged as #{expected_hours} hours but was #{time.hours}" + assert_equal Date.yesterday, time.spent_on + assert time.activity.is_default? + assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}" end - assert_equal [1], c.issue_ids.sort - - time = TimeEntry.first(:order => 'id desc') - assert_equal 1, time.issue_id - assert_equal 1, time.project_id - assert_equal 2, time.user_id - assert_equal 2.0, time.hours - assert_equal Date.yesterday, time.spent_on - assert time.activity.is_default? - assert time.comments.include?('r520'), "r520 was expected in time_entry comments: #{time.comments}" end def test_ref_keywords_closing_with_timelog @@ -100,7 +116,7 @@ c = Changeset.new(:repository => Project.find(1).repository, :committed_on => Time.now, - :comments => 'This is a comment. Fixes #1 @2.5, #2 @1', + :comments => 'This is a comment. Fixes #1 @4.5, #2 @1', :user => User.find(2)) assert_difference 'TimeEntry.count', 2 do c.scan_comment_for_issue_ids @@ -169,12 +185,12 @@ assert_equal [2], c.issue_ids.sort assert c.issues.first.project != c.project end - + def test_text_tag_revision c = Changeset.new(:revision => '520') assert_equal 'r520', c.text_tag end - + def test_text_tag_hash c = Changeset.new(:scmid => '7234cb2750b63f47bff735edc50a1c0a433c2518', :revision => '7234cb2750b63f47bff735edc50a1c0a433c2518') assert_equal 'commit:7234cb2750b63f47bff735edc50a1c0a433c2518', c.text_tag @@ -204,19 +220,67 @@ changeset = Changeset.find_by_revision('10') assert_nil changeset.next end - + def test_comments_should_be_converted_to_utf8 - with_settings :commit_logs_encoding => 'ISO-8859-1' do - c = Changeset.new - c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") + proj = Project.find(3) + str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'ISO-8859-1' ) + assert r + c = Changeset.new(:repository => r, + :committed_on => Time.now, + :revision => '123', + :scmid => '12345', + :comments => str) + assert( c.save ) assert_equal "Texte encodé en ISO-8859-1.", c.comments - end end - + def test_invalid_utf8_sequences_in_comments_should_be_stripped - c = Changeset.new - c.comments = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") - assert_equal "Texte encod en ISO-8859-1.", c.comments + proj = Project.find(3) + str = File.read("#{RAILS_ROOT}/test/fixtures/encoding/iso-8859-1.txt") + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'UTF-8' ) + assert r + c = Changeset.new(:repository => r, + :committed_on => Time.now, + :revision => '123', + :scmid => '12345', + :comments => str) + assert( c.save ) + if str.respond_to?(:force_encoding) + assert_equal "Texte encod? en ISO-8859-1.", c.comments + else + assert_equal "Texte encod en ISO-8859-1.", c.comments + end + end + + def test_comments_should_be_converted_all_latin1_to_utf8 + s1 = "\xC2\x80" + s2 = "\xc3\x82\xc2\x80" + if s1.respond_to?(:force_encoding) + s3 = s1 + s4 = s2 + s1.force_encoding('ASCII-8BIT') + s2.force_encoding('ASCII-8BIT') + s3.force_encoding('ISO-8859-1') + s4.force_encoding('UTF-8') + assert_equal s3.encode('UTF-8'), s4 + end + proj = Project.find(3) + r = Repository::Bazaar.create!( + :project => proj, :url => '/tmp/test/bazaar', + :log_encoding => 'ISO-8859-1' ) + assert r + c = Changeset.new(:repository => r, + :committed_on => Time.now, + :revision => '123', + :scmid => '12345', + :comments => s1) + assert( c.save ) + assert_equal s2, c.comments end def test_identifier