Fixed bugs with attachments and their tests