Here's the fix for this issue. The only part you might want to look at is the call to [self.database clearDocumentCache] in purgeDocument:. I feel like the purged document should be removed from the cache so it isn't returned again if cachedDocumentWithID: is called. Clearing the whole document cache is a bit drastic, but removing a single document from the cache would require a new method on TDDatabase.
Note that calling purgeDocument followed by documentWithID will result in a new, empty document with the same ID as the purged document. This is a bit confusing ("hey, I just purged document F45E1789-5754-41AC-8FF6-444207B919DB -- why is it coming back?") but this behavior is as designed for documentWithID, which will return a new doc if the provided doc ID doesn't exist. This is also the reason the unit test uses cachedDocumentWithID: when attempting to re-select the purged doc.
unit test for issue #203
fixed parameter type in call to purgeRevisions: and added a call to c…
…lear the document cache after purging
Clearing the document cache would be bad, as it would affect other TDDocuments and lead to multiple TDDocument instances for the same document ID. Instead we need to just remove this document ID from the cache.
Agreed. I will add a new method to TDDatabase which removes a specific document from the cache, update purgeDocument, and resubmit the pull request.