Decouple definiting the database query and building its indexes.

Now query is simply a set of controllers, all the fancy and complicated
machinery for builidng up the map() function has been removed.
Define some handy helper functions usefull for defining views.
Fix silly assertation.
Mind to leave clean reactor after skipping the test.
Fix one more test not performing proper cleanup.
Improve error handling when we fail to update the new design documents.