Task Attachments #104

Merged
konrad merged 63 commits from feature/attachments into master 2019-10-16 20:52:31 +00:00
2 changed files with 15 additions and 6 deletions
Showing only changes of commit f11e889102 - Show all commits

View File

@ -56,6 +56,7 @@ func (ta *TaskAttachment) NewAttachment(f io.ReadCloser, realname string, realsi
// Add an entry to the db
ta.FileID = file.ID
ta.CreatedByID = a.GetID()
_, err = x.Insert(ta)
if err != nil {
// remove the uploaded file if adding it to the db fails

View File

@ -87,16 +87,24 @@ func TestTaskAttachment_NewAttachment(t *testing.T) {
ta := TaskAttachment{
TaskID: 1,
}
tf := &testfile{
content: []byte("testingstuff"),
}
err := ta.NewAttachment(tf, "testfile", 100, &User{ID: 1})
assert.NoError(t, err)
_, err = files.FileStat("/2")
assert.False(t, os.IsNotExist(err))
testuser := &User{ID: 1}
// Also assert created_by_id is correct in the files table
err := ta.NewAttachment(tf, "testfile", 100, testuser)
assert.NoError(t, err)
_, err = files.FileStat("/2") // The new file has the id 2 since it's the second attachment
assert.False(t, os.IsNotExist(err))
assert.Equal(t, testuser.ID, ta.CreatedByID)
// Check the file was inserted correctly
ta.File = &files.File{ID: ta.FileID}
err = ta.File.LoadFileMetaByID()
assert.NoError(t, err)
assert.Equal(t, testuser.ID, ta.File.CreatedByID)
assert.Equal(t, "testfile", ta.File.Name)
assert.Equal(t, int64(100), ta.File.Size)
// Extra test for max size test
}