When my unit test is done running, the fixtures are supposed to be deleted, right? Loaded suite test/unit/workday_test Started . Finished in 0.064923 seconds. 1 tests, 1 assertions, 0 failures, 0 errors But if I look in the database/table, the fixture data is still there. How can I get rid of it upon the end of the test?
I believe the deleting of the table data occurs *before* each test method in your unit test. The order of things for each method in your unit test class is: 1. Delete data in tables whose fixtures are mentioned 2. Add mentioned fixture data to the tables 3. Run the "setup" method, if there is one 4. Run your test method 5. Repeat until all test methods are done. So there should be some data left in the test database''s tables when the model tests are complete (assuming the last method in the test unit class did not delete all of the data). Let me know if I''m wrong :) Duane Johnson (canadaduane) On Apr 8, 2005 1:05 PM, Caleb Tennis <caleb-PfRr3eUzJn1Wk0Htik3J/w@public.gmane.org> wrote:> When my unit test is done running, the fixtures are supposed to be deleted, > right? > > Loaded suite test/unit/workday_test > Started > . > Finished in 0.064923 seconds. > > 1 tests, 1 assertions, 0 failures, 0 errors > > But if I look in the database/table, the fixture data is still there. How can > I get rid of it upon the end of the test? > _______________________________________________ > Rails mailing list > Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
On Friday 08 April 2005 02:40 pm, Duane Johnson wrote:> So there should be some data left in the test database''s tables when > the model tests are complete (assuming the last method in the test > unit class did not delete all of the data). Let me know if I''m wrongYep, this is what is seemingly happening, though the inline docs say: " By adding a "fixtures" method to the test case and passing it a list of symbols (only one is shown here tho), we trigger the testing environment to automatically load the appropriate fixtures into the database before each test, and automatically delete them after each test." The problem I''m having is that foreign key constraints are breaking when my "users" table fixture gets loaded (that is, initially deleted), because the data from previous tests still exists in other tables referencing this table.
Note that I''ve opened a bug report to clarify which way it should be happening. In the meantime, I can manually delete the fixures in the teardown method, though it seems like I''m RM (repeating myself).
On Apr 8, 2005, at 12:44 PM, Caleb Tennis wrote:> On Friday 08 April 2005 02:40 pm, Duane Johnson wrote: >> So there should be some data left in the test database''s tables when >> the model tests are complete (assuming the last method in the test >> unit class did not delete all of the data). Let me know if I''m wrong > > Yep, this is what is seemingly happening, though the inline docs say: > > " By adding a "fixtures" method to the test case and passing it a list > of > symbols (only one is shown here tho), we trigger the testing > environment to > automatically load the appropriate fixtures into the database before > each > test, and automatically delete them after each test." > > The problem I''m having is that foreign key constraints are breaking > when my > "users" table fixture gets loaded (that is, initially deleted), > because the > data from previous tests still exists in other tables referencing this > table.Apparently the fixtures are supposed to be deleted in reverse order to avoid this problem, but there''s currently a bug. Here''s a patch: http://dev.rubyonrails.com/ticket/890 See the recent "fixtures & foreign keys" thread for some more info... Zach
On Friday 08 April 2005 03:17 pm, Zach Thompson wrote:> Apparently the fixtures are supposed to be deleted in reverse order to > avoid this problem, but there''s currently a bug. Here''s a patch: > > http://dev.rubyonrails.com/ticket/890 > > See the recent "fixtures & foreign keys" thread for some more info...Thanks - I missed that thread I guess. I''ll just delete the fixtures during teardown for now. Caleb