add test to demonstrate the bug in undelivered segments
Fix undelivered issue.

Also, fix bad test.
Merge pull request #3 from tidepool-org/cheddar/undelivered-bugfix

bug in undelivered segments