Skip to content

Commit 1d12945

Browse files
committed
Fix file caching issue when form is resubmitted without file
1 parent 160a796 commit 1d12945

2 files changed

Lines changed: 23 additions & 0 deletions

File tree

lib/active_admin_import/model.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def initialize(args = {})
4848
end
4949

5050
def assign_attributes(args = {}, new_record = false)
51+
args[:file] = nil unless args.key?(:file)
5152
@attributes.merge!(args)
5253
@new_record = new_record
5354
args.keys.each do |key|

spec/import_spec.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -588,4 +588,26 @@ def upload_file!(name, ext = 'csv')
588588
expect { add_author_resource(options) }.to raise_error(ArgumentError)
589589
end
590590
end
591+
592+
context 'when submitting empty form after validation error' do
593+
let(:options) { {} }
594+
595+
before do
596+
add_author_resource(options)
597+
visit '/admin/authors/import'
598+
end
599+
600+
it 'should NOT reuse cached file from previous submission' do
601+
expect do
602+
upload_file!(:author_broken_header)
603+
expect(page).to have_content("can't write unknown attribute")
604+
end.not_to change { Author.count }
605+
606+
# Second submission without selecting a file
607+
expect do
608+
find_button('Import').click
609+
expect(page).to have_content(I18n.t('active_admin_import.no_file_error'))
610+
end.not_to change { Author.count }
611+
end
612+
end
591613
end

0 commit comments

Comments
 (0)