handle empty files for diffing mode

fixes CNVS-38281

test plan
 - upload diffing file
 - upload empty diffing file with just headers
 - it should diff the files

Change-Id: I5d9c5dbf04c37e485de408ca038ba524461d0afe
Reviewed-on: https://gerrit.instructure.com/119610
Tested-by: Jenkins
QA-Review: Tucker McKnight <tmcknight@instructure.com>
Reviewed-by: Cody Cutrer <cody@instructure.com>
Product-Review: Rob Orton <rob@instructure.com>
This commit is contained in:
Rob Orton 2017-07-18 19:07:40 -06:00
parent e63627c74c
commit 9e97c6e11a
2 changed files with 14 additions and 2 deletions

View File

@ -36,8 +36,8 @@ module CsvDiff
setup_output(current_csv.headers) setup_output(current_csv.headers)
@db.transaction do @db.transaction do
insert("previous", row_previous, previous_csv, current_csv.headers) insert("previous", row_previous, previous_csv, current_csv.headers) if row_previous
insert("current", row_current, current_csv, nil) insert("current", row_current, current_csv, nil) if row_current
end end
find_updates find_updates

View File

@ -76,6 +76,12 @@ pk1,col1,pk2,col2
CSV CSV
end end
def only_header_row
CSV.new(<<CSV, headers: true)
pk1,col1,pk2,col2
CSV
end
context 'validation' do context 'validation' do
it 'rejects csvs without headers' do it 'rejects csvs without headers' do
expect { subject.generate(csv1(headers: false), csv1) }.to raise_error(CsvDiff::Failure, /headers/) expect { subject.generate(csv1(headers: false), csv1) }.to raise_error(CsvDiff::Failure, /headers/)
@ -90,6 +96,12 @@ CSV
it 'requires at least one pk column to be present' do it 'requires at least one pk column to be present' do
expect { subject.generate(missing_pk, missing_pk) }.to raise_error(CsvDiff::Failure, /primary key/) expect { subject.generate(missing_pk, missing_pk) }.to raise_error(CsvDiff::Failure, /primary key/)
end end
it 'handles empty files' do
cb = ->(row) { row['col2'] = 'deleted' }
output = subject.generate(csv1, only_header_row, deletes: cb)
expect(output.read).to eq "pk1,col1,pk2,col2\na,b,c,deleted\n1,2,3,deleted\n"
end
end end
context 'creates and updates' do context 'creates and updates' do