Tidy up attachments controller, add tests.