(#2779) - fix undeletion with wrong rev

turned #2779 into an actual test
This logic could probably be simplified, but I don't know how. Evidently I am not one of the 5 people in the world who fully understands CouchDB replication.

All I can tell you is that the tests are passing.