# Unit testing models of legacy database

**URL:** <https://www.ruby-forum.com/t/unit-testing-models-of-legacy-database/67800>\
**Category:** Rails\
**Created:** [September 6, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/unit-testing-models-of-legacy-database/67800 "2006-09-06T21:56:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![daya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@daya](https://www.ruby-forum.com/u/daya)\
**Post date:** [September 6, 2006, 9:56pm UTC](https://www.ruby-forum.com/t/unit-testing-models-of-legacy-database/67800/1 "2006-09-06T21:56:58Z")

</div>

Hi All

I need lots of help in figuring out how to test legacy ActiveRecord data  
models.

Here are my constraints:

1. Almost all of my models have set\_table\_name, set\_primary\_key etc and  
HABTM.
2. At my work place we have DEV, QA and PROD environment. DEV is for  
developers only and QA for QA team only (no developers).

Here are my questions.

1. In database.yml there is a comment for ‘test:’ data source which  
states

# Warning: The database defined as ‘test’ will be erased and

# re-generated from your development database when you run ‘rake’.

# Do not set this db to the same as development or production.

I cannot afford to let this happen, since table creation and loading  
lots of  
data is under DBA’s control and not in my (developer) control.  
—\> Is there a way I can avoid erasing and regeneration of data? Can I  
set  
the test db to same as development without risking data loss?

1. Will I have to use set\_table\_name, set\_primary\_key in my test cases?

2. If I want to use fixtures how do I select a particular fixture from  
a list of fixtures in my test?

TIA

-daya

---

<div class="post-metadata">

**Author:** ![daya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@daya](https://www.ruby-forum.com/u/daya)\
**Post date:** [September 7, 2006, 1:27am UTC](https://www.ruby-forum.com/t/unit-testing-models-of-legacy-database/67800/2 "2006-09-07T01:27:22Z")

</div>

On 6 Sep 2006, at 20:33, linux user wrote:

> (developer) control.  
> —\> Is there a way I can avoid erasing and regeneration of data?  
> Can I set the test db to same as development without risking data  
> loss?

Your QA database is not equivalent to a test database; you should see  
if you can create a new, possibly local db on developer machines to  
act as test. The QA database probably doesn’t need to be included;  
as you say, it isn’t for devs.

The only way to set test the same as production is if you never run  
tests. The test database is for unit testing, and requires that you  
be able to set it to a default state between tests, hence the way it  
works.

Paul

---

<div class="post-metadata">

**Author:** ![daya](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/9fc348/32.png) [@daya](https://www.ruby-forum.com/u/daya)\
**Post date:** [September 7, 2006, 3:19am UTC](https://www.ruby-forum.com/t/unit-testing-models-of-legacy-database/67800/3 "2006-09-07T03:19:29Z")

</div>

On 9/6/06, Paul L. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > and HABTM.
> > 
> > # Do not set this db to the same as development or production.
> 
> act as test. The QA database probably doesn’t need to be included;  
> as you say, it isn’t for devs.
> 
> The only way to set test the same as production is if you never run  
> tests. The test database is for unit testing, and requires that you  
> be able to set it to a default state between tests, hence the way it  
> works.
> 
> Paul

Thanks Paul

I was thinking on the similar lines but couldn’t express it completely  
in my  
head 🙂

-daya
