What’s the code you have in mind?
I have things in the database that rails doesn’t like to be in the database - namely triggers.
The database uses a star schema/class-table inheritance setup for parties. A Party is either a Person or an Organisation. A Party has contact details of various types. Inserting a Person/Organisation triggers an insert into the parties table, retrieves the id value, and uses that as the id for the new Person/Organisation.
I’ve got my rails models to work with this setup - there were a few issues, but there are workarounds.
My code relies on the fact that when I save a new Person/Organisation, the Party is also saved - so I need the triggers in the test database. If you load up the :people fixture, then the parties table gets populated too. In the setup method, before loading the fixtures, the old ones are deleted - except this method doesn’t know about the rows in parties that it needs to delete. These rows reference other tables, which then throw database errors when the setup method tries to delete them. It’s fine if you run a single TestCase using transactional fixtures. If you try and run more than one test case, then the setup method throws errors for the second and any further TestCases that use fixtures related to parties/people/organisations/contact details for the above.
The simple way to fix this is to run:
before running the code to set up fixtures… except rails doesn’t allow you to do this.
I’ve tried every workaround I can think of, and can’t get any of them to work. I’ve also tried hacking the case statement in TestCase.method_added, adding this:
and defining in my TestCase:
but I’m obviously misunderstanding what’s going on in method_added, since this method doesn’t appear to be getting run.
The current implementation of
fixtures leaves a lot to be desired, but we’re hoping to tidy it up