Bug fix and test for mongoid