| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
A CSV with an empty header cell (e.g. a leading comma) produced a nil header, and prepare_headers crashed with `undefined method 'underscore' for nil`. Merely coercing the header to a string only moves the failure to import time (`Missing column for value <> at index 0`), since an unnamed column maps to no attribute. Detect blank headers up front and raise an ActiveAdminImport::Exception naming the offending column, so the user gets an actionable flash instead of a NoMethodError.
Generalize the blank-header spec into a shared example and exercise a blank column at the beginning (col 1), the middle (col 2) and the end (col 4), asserting the reported column position for each.
| Back | FazBrowse Home | New Git URL |
Closes #197.
Problem
A CSV whose header row contains an empty cell — e.g. a stray leading comma from a spreadsheet export:
parses the first header as nil, and prepare_headers crashed on nil.underscore:
The fix suggested in the issue (coercing headers with to_s) does not resolve it — it only moves the failure to import time, because an unnamed "" column maps to no attribute:
Fix
Detect blank header cells up front and raise an ActiveAdminImport::Exception naming the offending column (1‑based). That exception is already rescued by the import action, so the user sees an actionable flash instead of a NoMethodError:
This is the option B behaviour (fail with a clear message) rather than silently dropping unnamed columns — a stray comma shouldn't quietly discard data.
Tests
New with a blank column header context: uploads a fixture with an empty leading header, asserts the clear error, that no NoMethodError leaks, and that nothing is imported.
Full suite green locally on Ruby 3.3 / Rails 8.1.3 / AA 3.5.1 / SQLite — 62 examples, 0 failures.