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:
parent
e63627c74c
commit
9e97c6e11a
|
@ -36,8 +36,8 @@ module CsvDiff
|
|||
setup_output(current_csv.headers)
|
||||
|
||||
@db.transaction do
|
||||
insert("previous", row_previous, previous_csv, current_csv.headers)
|
||||
insert("current", row_current, current_csv, nil)
|
||||
insert("previous", row_previous, previous_csv, current_csv.headers) if row_previous
|
||||
insert("current", row_current, current_csv, nil) if row_current
|
||||
end
|
||||
|
||||
find_updates
|
||||
|
|
|
@ -76,6 +76,12 @@ pk1,col1,pk2,col2
|
|||
CSV
|
||||
end
|
||||
|
||||
def only_header_row
|
||||
CSV.new(<<CSV, headers: true)
|
||||
pk1,col1,pk2,col2
|
||||
CSV
|
||||
end
|
||||
|
||||
context 'validation' do
|
||||
it 'rejects csvs without headers' do
|
||||
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
|
||||
expect { subject.generate(missing_pk, missing_pk) }.to raise_error(CsvDiff::Failure, /primary key/)
|
||||
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
|
||||
|
||||
context 'creates and updates' do
|
||||
|
|
Loading…
Reference in New Issue