scm: set empty log encoding UTF-8 in Ruby 1.9 and add tests.
git-svn-id: svn+ssh://rubyforge.org/var/svn/redmine/trunk@5368 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
parent
e297c1c244
commit
1b0473c38e
|
@ -247,7 +247,10 @@ class Changeset < ActiveRecord::Base
|
||||||
def self.to_utf8(str, encoding)
|
def self.to_utf8(str, encoding)
|
||||||
return str if str.nil?
|
return str if str.nil?
|
||||||
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
str.force_encoding("ASCII-8BIT") if str.respond_to?(:force_encoding)
|
||||||
return str if str.empty?
|
if str.empty?
|
||||||
|
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||||
|
return str
|
||||||
|
end
|
||||||
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
str.force_encoding("UTF-8") if str.respond_to?(:force_encoding)
|
||||||
if str.respond_to?(:force_encoding)
|
if str.respond_to?(:force_encoding)
|
||||||
enc = encoding.blank? ? "UTF-8" : encoding
|
enc = encoding.blank? ? "UTF-8" : encoding
|
||||||
|
|
|
@ -292,6 +292,42 @@ class ChangesetTest < ActiveSupport::TestCase
|
||||||
assert_equal s4, c.comments
|
assert_equal s4, c.comments
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_comments_nil
|
||||||
|
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 => nil)
|
||||||
|
assert( c.save )
|
||||||
|
assert_equal "", c.comments
|
||||||
|
if c.comments.respond_to?(:force_encoding)
|
||||||
|
assert_equal "UTF-8", c.comments.encoding.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_comments_empty
|
||||||
|
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 => "")
|
||||||
|
assert( c.save )
|
||||||
|
assert_equal "", c.comments
|
||||||
|
if c.comments.respond_to?(:force_encoding)
|
||||||
|
assert_equal "UTF-8", c.comments.encoding.to_s
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_identifier
|
def test_identifier
|
||||||
c = Changeset.find_by_revision('1')
|
c = Changeset.find_by_revision('1')
|
||||||
assert_equal c.revision, c.identifier
|
assert_equal c.revision, c.identifier
|
||||||
|
|
Loading…
Reference in New Issue