Skip to content

Commit e0aa6bd

Browse files
authored
Merge pull request #133 from activeadmin-plugins/feature-tab-separator
support for tsv files
2 parents 206d7e9 + bf12994 commit e0aa6bd

File tree

6 files changed

+26
-11
lines changed

6 files changed

+26
-11
lines changed

.travis.yml

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,14 @@ env:
44
- RAILS=4.2.6
55
- RAILS=5.0.0
66
rvm:
7-
- 1.9.3
8-
- 2.0.0
97
- 2.1.9
108
- 2.2.5
119
- 2.3.1
1210
matrix:
1311
exclude:
14-
- rvm: 1.9.3
15-
env: RAILS=5.0.0
16-
- rvm: 2.0.0
17-
env: RAILS=5.0.0
1812
- rvm: 2.1.9
19-
env: RAILS=5.0.0
13+
env: RAILS=5.0.0 # Rails 5.0 requires Ruby 2.2.2 or newer
2014
before_install:
21-
- gem install bundler -v '= 1.9.3'
22-
- gem update --system
23-
- gem --version
15+
- gem update --system # use the very latest Rubygems
16+
- rvm @global do gem uninstall bundler -a -x
17+
- rvm @global do gem install bundler -v 1.14.6 # latest version known to work

lib/active_admin_import/dsl.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ def active_admin_import(options = {}, &block)
9494
end
9595
rescue ActiveRecord::Import::MissingColumnError, NoMethodError, ActiveRecord::StatementInvalid, CSV::MalformedCSVError => e
9696
Rails.logger.error(I18n.t('active_admin_import.file_error', message: e.message))
97+
Rails.logger.error(e.backtrace.join("\n"))
9798
flash[:error] = I18n.t('active_admin_import.file_error', message: e.message[0..200])
9899
end
99100
redirect_to options[:back]

lib/active_admin_import/importer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ def detect_csv_options
119119
model.csv_options
120120
else
121121
options[:csv_options] || {}
122-
end.reject { |_, value| value.blank? }
122+
end.reject { |_, value| value.nil? || value == "" }
123123
end
124124
end
125125
end

lib/active_admin_import/model.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ module CONST
2121
application/csv
2222
application/vnd.ms-excel
2323
application/vnd.msexcel
24+
text/tsv
25+
text/x-tsv
26+
text/tab-separated-values
27+
text/x-tab-separated-values
2428
).freeze
2529
end
2630

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Name Last name Birthday
2+
John Doe 1986-05-01
3+
Jane Roe 1988-11-16

spec/import_spec.rb

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,19 @@ def upload_file!(name, ext = 'csv')
397397
expect(Author.count).to eq(2)
398398
end
399399
end
400+
401+
context 'with tab separator' do
402+
let(:options) do
403+
attributes = { csv_options: { col_sep: "\t" } }
404+
{ template_object: ActiveAdminImport::Model.new(attributes) }
405+
end
406+
407+
it 'should import file' do
408+
upload_file!(:authors_with_tabs, 'tsv')
409+
expect(page).to have_content 'Successfully imported 2 authors'
410+
expect(Author.count).to eq(2)
411+
end
412+
end
400413
end
401414

402415
context 'with callback procs options' do

0 commit comments

Comments
 (0)