Fix a few bugs with the new ID cursors.

 - stop once end of collection reached (empty result).
 - don't raise ValueError if ResultSet is empty when
   trying to get max/min ID of the set (max() and min() don't
   accept empty lists)
Move cursors tests into its own module.