# Setup new data in the test database \_after\_ unit test runs

**URL:** <https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873>\
**Category:** Rails\
**Created:** [July 11, 2006, 12:32am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873 "2006-07-11T00:32:12Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 12:32am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/1 "2006-07-11T00:32:12Z")

</div>

All,

I want to run automated unit tests as part of my build. I am building  
to my test environment. Upon successful completion of all of my unit  
tests, I would then like to load some data (using a fixture, I imagine)  
into my test database that will act as fresh “system test” data for my  
users to play with.

What is the best way to “load the standard system test/user acceptance  
data” after I’ve successfully run through all of my automated tests?

Thanks,  
Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 12:35am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/2 "2006-07-11T00:35:22Z")

</div>

Wes G. wrote:

> All,
> 
> I want to run automated unit tests as part of my build. I am building  
> to my test environment. Upon successful completion of all of my unit  
> tests, I would then like to load some data (using a fixture, I imagine)  
> into my test database that will act as fresh “system test” data for my  
> users to play with.
> 
> What is the best way to “load the standard system test/user acceptance  
> data” after I’ve successfully run through all of my automated tests?
> 
> Thanks,  
> Wes

Or should I just have a separate Rails environment for “system test” (as  
opposed to unit test) and manage that data separately? Even if I did  
that, I would still want an easy way to load/delete the system test data  
set easily.

WG

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 12:42am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/3 "2006-07-11T00:42:37Z")

</div>

On Tue, Jul 11, 2006, Wes G. wrote:

> All,
> 
> I want to run automated unit tests as part of my build. I am building  
> to my test environment. Upon successful completion of all of my unit  
> tests, I would then like to load some data (using a fixture, I imagine)  
> into my test database that will act as fresh “system test” data for my  
> users to play with.
> 
> What is the best way to “load the standard system test/user acceptance  
> data” after I’ve successfully run through all of my automated tests?

There is a rake task for this purpose. rake db:fixtures:load

You could either run that after your tests are done (and you do a purge)  
or, alternately, structure your tests/fixtures so that when they finish  
running, the data is still valid and interesting. For instance, you  
might do destructive tests before constructive tests, so that once the  
tests are finished, the test objects you created still exist.

Ben

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 12:53am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/4 "2006-07-11T00:53:18Z")

</div>

Thanks, Ben, I figured it was a no-brainer.

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 1:01am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/5 "2006-07-11T01:01:09Z")

</div>

On Tue, Jul 11, 2006, Wes G. wrote:

> Is there a way to specify the order in which the data is loaded so that  
> FK constraints aren’t broken?

I don’t know for sure. My gut tells me no, since I believe it just  
loads everything into hashes and hash order is unpredictable. Other  
people probably know better than I do; I primarily develop with MySQL so  
it’s not a problem for me 😉

Ben

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 1:01am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/6 "2006-07-11T01:01:34Z")

</div>

Wes G. wrote:

> Is there a way to specify the order in which the data is loaded so that  
> FK constraints aren’t broken?

Because I wanted to use the existing data in my DB for my test data, I  
easily dumped it to YAML using the following:

File.open(‘filename’, “w”) { |f| YAML.dump(ModelObject.find(:all), f)}

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 12:54am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/7 "2006-07-11T00:54:48Z")

</div>

Is there a way to specify the order in which the data is loaded so that  
FK constraints aren’t broken?

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 5:51am UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/8 "2006-07-11T05:51:56Z")

</div>

Wes G. wrote:

> Wes G. wrote:
> 
> > Is there a way to specify the order in which the data is loaded so that  
> > FK constraints aren’t broken?
> 
> Because I wanted to use the existing data in my DB for my test data, I  
> easily dumped it to YAML using the following:
> 
> File.open(‘filename’, “w”) { |f| YAML.dump(ModelObject.find(:all), f)}

It appears that just calling db:fixtures:load will load the fixture  
files in alphanumeric order, so I may just prefix the files in such a  
way that they will load in the correct order.

Wes

---

<div class="post-metadata">

**Author:** ![weyus](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/7ab992/32.png) [@weyus](https://www.ruby-forum.com/u/weyus)\
**Post date:** [July 11, 2006, 5:55pm UTC](https://www.ruby-forum.com/t/setup-new-data-in-the-test-database-after-unit-test-runs/97873/9 "2006-07-11T17:55:46Z")

</div>

On 7/10/06, Wes G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> It appears that just calling db:fixtures:load will load the fixture  
> files in alphanumeric order, so I may just prefix the files in such a  
> way that they will load in the correct order.

There is usually a command to tell your db to ignore constraints - I  
know you can switch the fk constraints on and off with mysql. So one  
solution I’ve seen is a simple script that turns of fk constraints,  
does all the data loading, then turns constraints back on.

- Rob  
–  
[http://www.robsanheim.com](http://www.robsanheim.com)  
[http://www.seekingalpha.com](http://www.seekingalpha.com)  
[http://www.ajaxian.com](http://www.ajaxian.com)
