Skip to content

Commit

Permalink
Support for a non UTF-8 file when zip uploading (#185)
Browse files Browse the repository at this point in the history
  • Loading branch information
naokirin committed Aug 10, 2020
1 parent d0efd09 commit 1c7601f
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/active_admin_import/model.rb
Expand Up @@ -110,7 +110,7 @@ def encode_file

def unzip_file
Zip::File.open(file_path) do |zip_file|
self.file = Tempfile.new(CONST::TMP_FILE)
self.file = Tempfile.new(CONST::TMP_FILE, binmode: true)
data = zip_file.entries.select(&:file?).first.get_input_stream.read
file << data
file.close
Expand Down
14 changes: 14 additions & 0 deletions spec/import_spec.rb
Expand Up @@ -371,6 +371,20 @@ def upload_file!(name, ext = 'csv')
end
end
end

context 'when zipped with Win1251 file' do
let(:options) do
attributes = { force_encoding: :auto }
{ template_object: ActiveAdminImport::Model.new(attributes) }
end
it 'should import file' do
with_zipped_csv(:authors_win1251_win_endline) do
upload_file!(:authors_win1251_win_endline, :zip)
expect(page).to have_content 'Successfully imported 2 authors'
expect(Author.count).to eq(2)
end
end
end
end

context 'with different header attribute names' do
Expand Down

0 comments on commit 1c7601f

Please sign in to comment.