From 6e5a9868f572ef97f1c115b62ff878e83351c798 Mon Sep 17 00:00:00 2001 From: kolaente Date: Thu, 15 Apr 2021 16:36:24 +0200 Subject: [PATCH] Fix moving repeating tasks to the done bucket --- pkg/models/tasks.go | 6 +++--- pkg/models/tasks_test.go | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/pkg/models/tasks.go b/pkg/models/tasks.go index 3243b153..54d308c9 100644 --- a/pkg/models/tasks.go +++ b/pkg/models/tasks.go @@ -954,14 +954,14 @@ func (t *Task) Update(s *xorm.Session, a web.Auth) (err error) { "repeat_mode", } + // When a repeating task is marked as done, we update all deadlines and reminders and set it as undone + updateDone(&ot, t) + err = setTaskBucket(s, t, &ot, t.BucketID != ot.BucketID) if err != nil { return err } - // When a repeating task is marked as done, we update all deadlines and reminders and set it as undone - updateDone(&ot, t) - // If the task is being moved between lists, make sure to move the bucket + index as well if t.ListID != 0 && ot.ListID != t.ListID { latestTask := &Task{} diff --git a/pkg/models/tasks_test.go b/pkg/models/tasks_test.go index 4f9e1ada..1d6ad6ac 100644 --- a/pkg/models/tasks_test.go +++ b/pkg/models/tasks_test.go @@ -302,6 +302,28 @@ func TestTask_Update(t *testing.T) { "bucket_id": 4, }, false) }) + t.Run("repeating tasks should not be moved to the done bucket", func(t *testing.T) { + db.LoadAndAssertFixtures(t) + s := db.NewSession() + defer s.Close() + + task := &Task{ + ID: 28, + Done: true, + } + err := task.Update(s, u) + assert.NoError(t, err) + err = s.Commit() + assert.NoError(t, err) + assert.False(t, task.Done) + assert.Equal(t, int64(1), task.BucketID) + + db.AssertExists(t, "tasks", map[string]interface{}{ + "id": 28, + "done": false, + "bucket_id": 1, + }, false) + }) } func TestTask_Delete(t *testing.T) {