# Running a "CSV-row massager" on Fixtures

**URL:** <https://www.ruby-forum.com/t/running-a-csv-row-massager-on-fixtures/116376>\
**Category:** Rails\
**Created:** [October 4, 2007, 11:52pm UTC](https://www.ruby-forum.com/t/running-a-csv-row-massager-on-fixtures/116376 "2007-10-04T23:52:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/90db22/32.png) [@edward](https://www.ruby-forum.com/u/edward)\
**Post date:** [October 4, 2007, 11:52pm UTC](https://www.ruby-forum.com/t/running-a-csv-row-massager-on-fixtures/116376/1 "2007-10-04T23:52:49Z")

</div>

Hi All,

I was wondering if anyone had run into a similar problem and had  
advice:

I’m using ActiveRecord (without the rest of Rails) to manage data  
import for large collections of CSV data files into a database. The  
problem is that each CSV file comes from a different source, and each  
source uses completely different conventions for encoding just about  
everything (Country names, phone numbers, dates, null values, etc)

Is there an easy way to sneak a step into the fixture loading process  
whereupon I have the chance to normalize the data in each row before  
it is dumped into the database?

For example, I’d need to turn:

John,Doe,us,4/23/1970,null,null,yes

into:

John,Doe,USA,1970-23-4,1

I know I could just monkeypatch the Rails source, but I was hoping for  
a cleaner solution.

Thanks,  
Ted [Singing the data integration blues]

---

<div class="post-metadata">

**Author:** ![edward](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/e/90db22/32.png) [@edward](https://www.ruby-forum.com/u/edward)\
**Post date:** [October 5, 2007, 3:42am UTC](https://www.ruby-forum.com/t/running-a-csv-row-massager-on-fixtures/116376/2 "2007-10-05T03:42:32Z")

</div>

Edward wrote:

> John,Doe,USA,1970-23-4,1
> 
> I know I could just monkeypatch the Rails source, but I was hoping for  
> a cleaner solution.
> 
> Thanks,  
> Ted [Singing the data integration blues]

If these are test fixtures why not have a separate script that massages  
the data beforehand? Otherwise you’ll need to do this “translation”  
everytime you run a test.

–  
Michael W.
