Topic: Unit testing and associations
Finally facing something I've been putting off for ages and trying to get into the habit of writing tests but I'm having a problem with one and I was hoping someone might be able to help me with.
I've got a after_save filter on a a model which updates another model it belongs to (to keep a running total of a column's values) but this for some reason isn't tallying up when I test it.
My test currently creates a new parent object then two new child objects, associates them, then saves the parent (and so the children). If I check the test.log I can see it all appear to work but when I try to do an assert_equal for it the value in the parent model always returns 0 and so fails the test. I've also found that the counter cache exhibits the same behaviour.
When I test it manually all works fine. Am I missing something!?