Skip to content

Commit 4e83191

Browse files
author
artemlutsenko
committed
Fix error when active_model_import raise ArgumentError Number of values (n) exceeds number of columns (m)
1 parent 5232574 commit 4e83191

File tree

3 files changed

+18
-0
lines changed

3 files changed

+18
-0
lines changed

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,
9696
NoMethodError,
97+
ArgumentError,
9798
ActiveRecord::StatementInvalid,
9899
CSV::MalformedCSVError,
99100
ActiveAdminImport::Exception => e
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Birthday,Name,Last name
2+
1986-05-01,John,Doe
3+
1988-11-16,Jane,Roe, exceeded value

spec/import_spec.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,20 @@ def upload_file!(name, ext = 'csv')
440440
expect(Author.count).to eq(0)
441441
end
442442
end
443+
444+
context 'with csv which has exceeded values' do
445+
before do
446+
upload_file!(:authors_values_exceeded_headers)
447+
end
448+
449+
it 'should render warning' do
450+
# 5 columns: 'birthday, name, last_name, created_at, updated_at'
451+
# 6 values: '"1988-11-16", "Jane", "Roe", " exceeded value", datetime, datetime'
452+
msg = 'Number of values (6) exceeds number of columns (5)'
453+
expect(page).to have_content I18n.t('active_admin_import.file_error', message: msg)
454+
expect(Author.count).to eq(0)
455+
end
456+
end
443457
end
444458

445459
context 'with callback procs options' do

0 commit comments

Comments
 (0)