def test_find_by_contents assert_equal 2, MyModel.find_by_contents('bla').total_hits endThis is great, except for one small problem: it almost always fails! The total_hits are sometimes 1, sometimes 0 and hardly ever 2. Why? Because the data from the fixtures is rebuilt before every test case so ferret can't keep it's index up to date quickly enough. A very crude but simple solution is to rebuild the index before ferret-related tests:
def test_find_by_contents MyModel.rebuild_index assert_equal 2, MyModel.find_by_contents('bla').total_hits endNow it works as expected. This will affect performance, though. So if you have a huge test suite, you might want to consider using the preload fixtures plugin from ELC Technologies. I haven't tried this, but it most likely will also eliminate the need to rebuild the index before ferret related tests since the fixtures are not constantly dumped and rebuilt. If this was useful for you, please take a minute and recommend me:
Gene Tani said...
see alsoSeptember 07, 2008 07:17 PM