# From development DB to test DB during tests

**URL:** <https://www.ruby-forum.com/t/from-development-db-to-test-db-during-tests/92129>\
**Category:** Rails\
**Created:** [April 16, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/from-development-db-to-test-db-during-tests/92129 "2007-04-16T14:34:51Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 16, 2007, 2:34pm UTC](https://www.ruby-forum.com/t/from-development-db-to-test-db-during-tests/92129/1 "2007-04-16T14:34:51Z")

</div>

Hello, even after several months of Rails development I’m still facing  
few problems with unit testing.

1. Inserting records during migration

My migration.rb is  
def self.up  
create\_table :rubriques do |t|  
t.column “libelle”, :string  
t.column “rubrique\_id”, :integer  
t.column “visible”, :boolean  
end

Rubrique.create(:libelle =\> ‘root’, :rubrique\_id =\> nil, :visible =\>  
true)  
end

Problem is : the ‘root’ record is never inserted in the test database  
even when using rake db:migrate RAILS\_ENV=“test” or rake test:purge and  
then rake test:units

Why ? No idea

1. Second common problem :  
I use fixtures which are loaded accordingly during unit testing. But  
when running functional tests which don’t use any :fixtures statement,  
it’s common to have the fixtures datas still loaded in the test  
database.  
The only solution I found was adding delete\_existing\_fixtures() in the  
setup() method… No the ‘right’ way in my point of view…

Any help appreciated, thank you !

---

<div class="post-metadata">

**Author:** ![nuno](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/65b543/32.png) [@nuno](https://www.ruby-forum.com/u/nuno)\
**Post date:** [April 16, 2007, 2:49pm UTC](https://www.ruby-forum.com/t/from-development-db-to-test-db-during-tests/92129/2 "2007-04-16T14:49:38Z")

</div>

rake test:units / test:functionals blasts the test database away and  
rebuilds the schema from the development database (aka, no data). This  
does  
_not_ use migrations; it uses db/schema.rb. If you want data in the test  
db,  
you need to either use fixtures or manually create the data in your  
tests  
(basically the same thing, when you think about it).

Jason
