We've moved discussions to Discord

SOLVED: Fixtures Are Created in the DB Twice

Elise Shaffer
Hi everyone. I am having a fixture issue that's driving me a bit crazy. I have some tests for a resource scoped to accounts. I am trying to add my own accounts fixtures. However, when I add the new fixture, it's loaded into the database twice. I have a Note model that is scoped to the account. When my test runs, the notes fixtures are associated with the duplicate account. e.g. I will have two accounts named "Alice." And the notes get associated with the duplicate, not the account under test.

This does not happen when I use the fixtures defined in the Jumpstart template and I can't for the life of me figure out why those would be different. I even tried renaming the accounts(:one) fixture to accounts(:alice) and had the same problem. Also this is deterministic. It is always associated to wrong duplicate account row. 

Has anyone else seen this before? It's been a while since I've used fixtures, so I'm not sure if I'm doing something wrong. But it's odd that the same thing doesn't happen for the fixtures defined in Jumpstart.
Chris Oliver
Strange! I don't have any ideas why that might be happening off the top of my head.

If you've got an example we can use to reproduce it, that'd be great. 
Elise Shaffer
Chris Oliver Thanks for the response. Sorry, I didn't get back to you earlier. I'm working on this project in my spare time and primarily on weekends. I discovered the issue this morning and have it fixed.

I created fixtures for both the users and accounts tables but not account_users. So in SetCurrentRequestDetails(link), it didn't find the associated account and created a new one. I assumed that the owner_id would be sufficient, but I guess I didn't factor in the multiple account scenario.
Chris Oliver
Ah ha! That makes sense. Glad you figured that one out. I probably wouldn't have ever thought of that without looking at your code! 😬
Notifications
You’re not receiving notifications from this thread.