Fix rake task and add test for it