(#2779) - fix undeletion with wrong rev

turned #2779 into an actual test
I am evidently not one of the 5 people in the world who fully understands CouchDB replication. That's why the logic looks like this.

It could doubtless be simplified, but for the moment I'm just interested in adding new tests and getting them passing.