Skip to content

Commit

Permalink
Merge 990acb6 into 4d866cd
Browse files Browse the repository at this point in the history
  • Loading branch information
dburt committed Apr 24, 2015
2 parents 4d866cd + 990acb6 commit 6d2c911
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rails_admin/support/csv_converter.rb
Expand Up @@ -3,7 +3,7 @@

module RailsAdmin
class CSVConverter
UTF8_ENCODINGS = [nil, '', 'utf8', 'utf-8', 'unicode', 'UTF8', 'UTF-8', 'UNICODE']
UTF8_ENCODINGS = [nil, '', 'utf8', 'utf-8', 'unicode', 'UTF8', 'UTF-8', 'UNICODE', 'utf8mb4']
TARGET_ENCODINGS = %w(UTF-8 UTF-16LE UTF-16BE UTF-32LE UTF-32BE UTF-7 ISO-8859-1 ISO-8859-15 IBM850 MacRoman Windows-1252 ISO-8859-3 IBM852 ISO-8859-2 Windows-1250 IBM855 ISO-8859-5 KOI8-R MacCyrillic Windows-1251 IBM866 GB2312 GBK GB18030 Big5 Big5-HKSCS EUC-TW EUC-JP ISO-2022-JP Shift_JIS EUC-KR)
def initialize(objects = [], schema = {})
return self if (@objects = objects).blank?
Expand Down
15 changes: 14 additions & 1 deletion spec/rails_admin/support/csv_converter_spec.rb
Expand Up @@ -32,10 +32,23 @@

subject { RailsAdmin::CSVConverter.new(objects, schema).to_csv(encoding_to: encoding) }

context 'when encoding FROM MySQL utf8mb4' do
let(:encoding) { 'UTF-8' } # default

it 'exports to UTF-8 with BOM' do
# MySQL connection may report its encoding as 'utf8mb4'
expect(::ActiveRecord::Base.connection).to receive(:encoding) { 'utf8mb4' }
expect(subject[1]).to eq 'UTF-8'
expect(subject[2].encoding).to eq Encoding::UTF_8
expect(subject[2].unpack('H*').first).
to eq 'efbbbf4e756d6265722c4e616d650a312ce381aae381bee381880a' # have BOM
end
end

context 'when encoding to UTF-8' do
let(:encoding) { 'UTF-8' }

it 'exports to UTR-8 with BOM' do
it 'exports to UTF-8 with BOM' do
expect(subject[1]).to eq 'UTF-8'
expect(subject[2].encoding).to eq Encoding::UTF_8
expect(subject[2].unpack('H*').first).
Expand Down

0 comments on commit 6d2c911

Please sign in to comment.