putAttachment should create doc if it does not exist

with tests.