Allow switching the encoding to UTF-8 when exporting to CSV (#26279).

Patch by Mizuki ISHIKAWA.


git-svn-id: http://svn.redmine.org/redmine/trunk@17328 e93f8b46-1217-0410-a6f0-8f06a7374b81
This commit is contained in:
Go MAEDA
2018-05-07 01:13:12 +00:00
parent 43d9bea7c5
commit ca2875fab2
9 changed files with 75 additions and 9 deletions

View File

@@ -18,7 +18,7 @@
require File.expand_path('../../../../../test_helper', __FILE__)
class CsvTest < ActiveSupport::TestCase
include Redmine::I18n
BOM = "\xEF\xBB\xBF".force_encoding('UTF-8')
def test_should_include_bom_when_utf8_encoded
@@ -28,4 +28,19 @@ class CsvTest < ActiveSupport::TestCase
assert string.starts_with?(BOM)
end
end
def test_generate_should_return_strings_with_given_encoding
with_locale 'en' do
string = Redmine::Export::CSV.generate({encoding: 'ISO-8859-3'}) {|csv| csv << %w(Foo Bar)}
assert_equal 'ISO-8859-3', string.encoding.name
assert_not_equal l(:general_csv_encoding), string.encoding.name
end
end
def test_generate_should_return_strings_with_general_csv_encoding_if_invalid_encoding_is_given
with_locale 'en' do
string = Redmine::Export::CSV.generate({encoding: 'invalid-encoding-name'}) {|csv| csv << %w(Foo Bar)}
assert_equal l(:general_csv_encoding), string.encoding.name
end
end
end