Skip to content

Commit

Permalink
Merge pull request #1291 from SplitTime/oveson/fix-single-column-csv-…
Browse files Browse the repository at this point in the history
…import

Fix single-column CSV import bug
  • Loading branch information
moveson authored Dec 2, 2024
2 parents 559b26e + 05a124e commit 12f29f8
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/etl/extractors/csv_file_strategy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class CsvFileStrategy
MAX_FILE_SIZE = 1.megabyte
BYTE_ORDER_MARK = String.new("\xEF\xBB\xBF").force_encoding("UTF-8").freeze
IMPORT_OPTIONS = {
col_sep: ",",
downcase_header: false,
duplicate_header_suffix: nil,
force_utf8: true,
Expand Down
4 changes: 4 additions & 0 deletions spec/fixtures/files/single_column.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Order ID
123
456
789
18 changes: 18 additions & 0 deletions spec/lib/etl/extractors/csv_file_strategy_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,24 @@
end
end

context "when the file has a single column" do
let(:file) { file_fixture("single_column.csv") }

it "does not return errors" do
subject.extract

expect(subject.errors).to be_empty
end

it "returns headers converted to symbols" do
expect(raw_data.first.to_h.keys).to eq([:Order_ID])
end

it "returns expected parsed structs" do
expect(raw_data.map { |struct| struct[:Order_ID] }).to match_array([123, 456, 789])
end
end

context "when the file has non-standard characters in headers" do
let(:file) { file_fixture("test_efforts_header_formats.csv") }

Expand Down

0 comments on commit 12f29f8

Please sign in to comment.