Trouble writing to db in test

Are you checking your database after the test has run ? tests are wrapped in a transaction which is rolled back at the end of the test- changes to the db made by the test don't persist (and depending on your db settings probably aren't visible to other connections to the databases).