Tuesday 18 December 2007

Rails gotchas: All the fixtures in the world

After having spent three hours debugging an error that "couldn't be happening" I have decided to just start loading every fixture for every functional test... Ok maybe not - but that's what it feels like is necessary.

The test in question was there to check if a user with expired quota could start using a feature again once they'd been given more quota. It was failing because I hadn't included the "roles" fixture... vital to the controller when deciding if the user is authorised to get into the controller in the first place... but not really directly relevant to this test, so I hadn't thought about it.

This can also cause the weird effect where an entire functional test suite runs fine when you call it via ruby test/functionals/<whatever>.rb, but several tests fail when you try to run it via rake test:functionals

Lesson: include every fixture that might be accessed by your controller in the performance of its duty - even if it doesn't seem directly relevant.

No comments: