Allow assets to be uploaded for the document field

Rewritten the attachment methods with a bit of
metaprogramming to support other fields.

More comprehensive unit tests too.