Unit testing models of legacy database

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

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

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?

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

Thanks Paul

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

-daya