joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-17 01:46 UTC
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? --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Mar-17 03:15 UTC
Re: Stupid postgresql test fixtures
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?/ On Mar 16, 6:46 pm, joevan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> 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?--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi Joe, On 3/16/07, joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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?/ > > On Mar 16, 6:46 pm, joevan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
joevandyk-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Apr-04 01:01 UTC
Re: Stupid postgresql test fixtures
On Mar 17, 3:09 am, "Jeremy Kemper" <jer...-w7CzD/W5Ocjk1uMJSBkQmQ@public.gmane.org> wrote:> Hi Joe, > > On 3/16/07, joevan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org <joevan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I guess I don''t get why I have to specify thefixturesused in each > >test. Shouldn''t all thefixturesbe loaded and dropped via a > > transaction for eachtest?/ > > > On Mar 16, 6:46 pm, joevan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > 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 eachtestloadfixturesin 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 allfixturesintest/test_helper.rb so they''re > all loaded, all the time, or preload thetestdatabase with yourfixturesand never load or delete them unless they''ve changed. This is > safe because all yourtestruns are wrapped in a transaction that''s > rolled back at the end. > > jeremyCan you give me an idea of what to search for? My first few searches came up with squat. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---