pouchdb/pouchdb — pull request #2804 by nolanlawson (2014-09-27 16:41:53+00:00)
Title: (#2803) - throw 412s when stubs are missing

We are supposed to throw a 412 error if a stub is missing.

Interestingly, CouchDB also throws a 412 error if you have the exact same digest but shared between two attachments in the same document. However, I think it's nice that PouchDB just looks up the attachment by digest, without regard for the parent document or filename. So I do not test this case; I only test the case where the digest is unknown.

If you're wondering why the logic looks so tortured, recall that IndexedDB and WebSQL are jealous lovers, and if you try to do any other async operation within the normal callback chain (such as FileReader), then the transaction will become stale and auto-close. So I am very careful to do `verifyAttachments` outside of `preprocessAttachments`, since the former entails transactional stuff whereas the latter entails FileReader stuff.