Fix CSV import preview crash on empty values (#756)
This commit was merged in pull request #756.
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
class Import::Csv
|
||||
def self.parse_csv(csv_str)
|
||||
CSV.parse((csv_str || "").strip, headers: true, converters: [ ->(str) { str.strip } ])
|
||||
CSV.parse((csv_str || "").strip, headers: true, converters: [ ->(str) { str&.strip } ])
|
||||
end
|
||||
|
||||
def self.create_with_field_mappings(raw_csv_str, fields, field_mappings)
|
||||
|
||||
@@ -36,6 +36,11 @@ class Import::CsvTest < ActiveSupport::TestCase
|
||||
assert_not invalid_csv.valid?
|
||||
end
|
||||
|
||||
test "csv with additional columns and empty values" do
|
||||
csv = Import::Csv.new valid_csv_with_extra_column
|
||||
assert csv.valid?
|
||||
end
|
||||
|
||||
test "updating a cell returns a copy of the original csv" do
|
||||
original_date = "2024-01-01"
|
||||
new_date = "2024-01-01"
|
||||
|
||||
@@ -14,6 +14,14 @@ module ImportTestHelper
|
||||
ROWS
|
||||
end
|
||||
|
||||
def valid_csv_with_extra_column
|
||||
<<-ROWS
|
||||
date,name,category,"optional id",amount
|
||||
2024-01-01,Starbucks drink,Food,1234,20
|
||||
2024-01-02,Amazon stuff,Shopping,,200
|
||||
ROWS
|
||||
end
|
||||
|
||||
def malformed_csv_str
|
||||
<<-ROWS
|
||||
name,age
|
||||
|
||||
Reference in New Issue
Block a user