Skip to content

Commit 16fd483

Browse files
committed
Support for a non UTF-8 file when zip uploading
1 parent d0efd09 commit 16fd483

File tree

2 files changed

+15
-1
lines changed

2 files changed

+15
-1
lines changed

lib/active_admin_import/model.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ def encode_file
110110

111111
def unzip_file
112112
Zip::File.open(file_path) do |zip_file|
113-
self.file = Tempfile.new(CONST::TMP_FILE)
113+
self.file = Tempfile.new(CONST::TMP_FILE, binmode: true)
114114
data = zip_file.entries.select(&:file?).first.get_input_stream.read
115115
file << data
116116
file.close

spec/import_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,20 @@ def upload_file!(name, ext = 'csv')
371371
end
372372
end
373373
end
374+
375+
context 'when zipped with Win1251 file' do
376+
let(:options) do
377+
attributes = { force_encoding: :auto }
378+
{ template_object: ActiveAdminImport::Model.new(attributes) }
379+
end
380+
it 'should import file' do
381+
with_zipped_csv(:authors_win1251_win_endline) do
382+
upload_file!(:authors_win1251_win_endline, :zip)
383+
expect(page).to have_content 'Successfully imported 2 authors'
384+
expect(Author.count).to eq(2)
385+
end
386+
end
387+
end
374388
end
375389

376390
context 'with different header attribute names' do

0 commit comments

Comments
 (0)