Make sure a task is moved to the done bucket when marked as done from elsewhere
This commit is contained in:
parent
cd5599a10d
commit
6d78ee7ce1
|
@ -929,6 +929,22 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) {
|
|||
|
||||
// Make sure we have a bucket
|
||||
var bucket *Bucket
|
||||
if t.Done {
|
||||
bucket = &Bucket{}
|
||||
exists, err := s.
|
||||
Where("list_id = ? and is_done_bucket = ?", t.ListID, true).
|
||||
Get(bucket)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !exists {
|
||||
bucket = nil
|
||||
}
|
||||
if bucket != nil {
|
||||
t.BucketID = bucket.ID
|
||||
}
|
||||
}
|
||||
|
||||
if t.BucketID == 0 || (t.ListID != 0 && ot.ListID != t.ListID) {
|
||||
bucket, err = getDefaultBucket(s, t.ListID)
|
||||
if err != nil {
|
||||
|
|
|
@ -260,6 +260,28 @@ func TestTask_Update(t *testing.T) {
|
|||
assert.Equal(t, int64(4), task.BucketID) // bucket 4 is the default bucket on list 2
|
||||
assert.True(t, task.Done) // bucket 4 is the done bucket, so the task should be marked as done as well
|
||||
})
|
||||
t.Run("marking a task as done should move it to the done bucket", func(t *testing.T) {
|
||||
db.LoadAndAssertFixtures(t)
|
||||
s := db.NewSession()
|
||||
defer s.Close()
|
||||
|
||||
task := &Task{
|
||||
ID: 1,
|
||||
Done: true,
|
||||
}
|
||||
err := task.Update(s, u)
|
||||
assert.NoError(t, err)
|
||||
err = s.Commit()
|
||||
assert.NoError(t, err)
|
||||
assert.True(t, task.Done)
|
||||
assert.Equal(t, int64(3), task.BucketID)
|
||||
|
||||
db.AssertExists(t, "tasks", map[string]interface{}{
|
||||
"id": 1,
|
||||
"done": true,
|
||||
"bucket_id": 3,
|
||||
}, false)
|
||||
})
|
||||
}
|
||||
|
||||
func TestTask_Delete(t *testing.T) {
|
||||
|
|
Loading…
Reference in New Issue