# Test database and migrations

**URL:** <https://www.ruby-forum.com/t/test-database-and-migrations/186647>\
**Category:** Rails\
**Created:** [April 10, 2010, 3:31pm UTC](https://www.ruby-forum.com/t/test-database-and-migrations/186647 "2010-04-10T15:31:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 10, 2010, 3:31pm UTC](https://www.ruby-forum.com/t/test-database-and-migrations/186647/1 "2010-04-10T15:31:13Z")

</div>

Hi,

I’d like to have the results of a migration file that prepopulates my  
development database available for testing. So, right now, after the  
usual rake migration, I can access my prepopulated data via script/  
console, but not in my unit tests. I’ve reviewed comments on this  
subject but the custom rake tasks do not work or attempting a fix with  
RAILS\_ENV=test rake db:migrate as a command does not help either. Any  
suggestion on how I can get the results of my migration available in  
the test environment?

Thanks,

Grar

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 10, 2010, 3:54pm UTC](https://www.ruby-forum.com/t/test-database-and-migrations/186647/2 "2010-04-10T15:54:03Z")

</div>

On Apr 10, 2:30 pm, Grary [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> 

The test database is filled with the data from your fixture files -  
running migrations against it accomplish nothing because it is wiped  
at the start of the test run. Your best bet is probably to write  
something that will dump yml from your database. You should consider  
using db/seeds.rb to seed your database - migrations are not intended  
to fufill that need.

Fred

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 10, 2010, 4:18pm UTC](https://www.ruby-forum.com/t/test-database-and-migrations/186647/3 "2010-04-10T16:18:38Z")

</div>

Frederick,

Thanks. So, my desire to have pre-populated (whether from seeding or  
otherwise) databases available in testing is unusual? I would have  
expected a basic interest in having any and all development data,  
e.g., zip code data, available for testing purposes, but my takeaway  
from your response is that testing is typically performed on a limited  
subset of development/production data that has been supplied from  
fixtures. Can you please confirm?

Thanks,

Grar

On Apr 10, 9:52 am, Frederick C. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![grar](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/cc9497/32.png) [@grar](https://www.ruby-forum.com/u/grar)\
**Post date:** [April 10, 2010, 8:20pm UTC](https://www.ruby-forum.com/t/test-database-and-migrations/186647/4 "2010-04-10T20:20:25Z")

</div>

On Apr 10, 3:17 pm, Grary [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Frederick,
> 
> Thanks. So, my desire to have pre-populated (whether from seeding or  
> otherwise) databases available in testing is unusual? I would have  
> expected a basic interest in having any and all development data,  
> e.g., zip code data, available for testing purposes, but my takeaway  
> from your response is that testing is typically performed on a limited  
> subset of development/production data that has been supplied from  
> fixtures. Can you please confirm?

Correct (although there’s no constraint I’m aware of on the size of  
your fixture data). You want test runs to be consistent - having the  
dataset your tests run against change just because you’ve been messing  
around in development would be a bad thing. More and more people are  
actually skipping fixtures and using stuff like factory\_girl.

Fred
