How to do proper database testing (TDD) on Rails 3 using MongDB through MongoID?

There's no way to make MongoDB non-persistent. You simply have to delete data before or after each test. There's some documentation on that here.

There's no way to make MongoDB non-persistent. You simply have to delete data before or after each test. There's some documentation on that here: mongodb.org/display/DOCS/Rails+-+Getting....

Thanks, that's what I was afraid of... Good link though, I thought I have read through the complete mongoDB pages, but not yet apparently :) I'll try that solution to avoid having to add manual code every time I am writing test. – Alex Jan 15 at 5:25.

Ok thanks to Kyle who pointed me in the right direction, I found out how to make it work. So basically the trick is to drop all your collections in mongodb for each test case that you will run. This is a bit radical, but it works.

But keep in mind that you won't retain any data at all in you test db. Finally I found that link: adventuresincoding.com/2010/07/how-to-co... And basically what you need to do is simple: add a block in you spec_helper. Rb: RSpec.

Configure do |config| # blabla other confs config. Before :each do Mongoid.master.collections. Select {|c| c.Name!

~ /system/ }. Each(&:drop) end # blabla other confs end This effectively kills all the collection within the db allowing you to run your tests fresh every time.Alex.

The mongoid documentation covers this as well. You can also use the database_cleaner gem mongoid. Org/docs/integration – Christos Jan 19 at 0:19 Thank you.

This is so much nicer than having to worry about a gem specifically for cleaning the database haha. – Batkins Oct 25 at 23:14.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions