Stupid postgresql test fixtures

Hi,

So, I've got a postgresql database with referential integrity on the foreign keys. It's a pain in the ass because I get a ton of errors like this if I don't have each test load fixtures in exactly the right order.

ActiveRecord::StatementInvalid: PGError: ERROR: update or delete on "users" violates foreign key constraint "user_id_fkey" on "bids"

DETAIL: Key (id)=(1) is still referenced from table "bids".

: DELETE FROM users

How can I make it not such a pain?

I guess I don't get why I have to specify the fixtures used in each test. Shouldn't all the fixtures be loaded and dropped via a transaction for each test?/

Hi Joe,

I guess I don't get why I have to specify the fixtures used in each test. Shouldn't all the fixtures be loaded and dropped via a transaction for each test?/

> Hi, > > So, I've got a postgresql database with referential integrity on the > foreign keys. It's a pain in the ass because I get a ton of errors > like this if I don't have each test load fixtures in exactly the right > order. > > ActiveRecord::StatementInvalid: PGError: ERROR: update or delete on > "users" violates foreign key constraint "user_id_fkey" on "bids" > > DETAIL: Key (id)=(1) is still referenced from table "bids". > > : DELETE FROM users > > How can I make it not such a pain?

Please search the list archives for further discussion.

You can either declare all fixtures in test/test_helper.rb so they're all loaded, all the time, or preload the test database with your fixtures and never load or delete them unless they've changed. This is safe because all your test runs are wrapped in a transaction that's rolled back at the end.

jeremy

Can you give me an idea of what to search for? My first few searches came up with squat.