How would go about writing proper unit testing (and integration testing for that matter) using MongoDB through Mongoid on Rails ?
I am asking, because to the opposite of using let's say SQLite3, even when running tests, everything I do does persists. So for the moment I am writing the creation test and then I manually delete everything I do. But it's getting annoying and even complicated to do for integration testing.
Sample of what I do:
before(:each) do
@user = User.create!(@attr)
end
after(:each) do
# MongoDB is not a transactional DB, so added objects (create) during tests can't be rollbacked
# checking for the existance of a similar object with exact :name and :email (regex make it case insensitive)
cleanup = User.where(:name => "Example User", :email => /^user@example.com/i)
cleanup.destroy unless cleanup.nil?
end
Any idea how to make MongoDB not persistent during Testing ? (I can't even run the console in sandbox mode because to use Mongoid I had to deactivate Active Record).