Fix resetting the bucket limit

This commit is contained in:
kolaente 2021-01-31 12:40:02 +01:00
parent 2e88600c93
commit d69c799197
No known key found for this signature in database
GPG key ID: F40E70337AB24C9B
2 changed files with 49 additions and 1 deletions

View file

@ -191,7 +191,10 @@ func (b *Bucket) Create(s *xorm.Session, a web.Auth) (err error) {
// @Failure 500 {object} models.Message "Internal error"
// @Router /lists/{listID}/buckets/{bucketID} [post]
func (b *Bucket) Update(s *xorm.Session) (err error) {
_, err = s.Where("id = ?", b.ID).Update(b)
_, err = s.
Where("id = ?", b.ID).
Cols("title", "limit").
Update(b)
return
}

View file

@ -18,6 +18,7 @@ package models
import (
"testing"
"xorm.io/xorm"
"code.vikunja.io/api/pkg/db"
"code.vikunja.io/api/pkg/user"
@ -135,3 +136,47 @@ func TestBucket_Delete(t *testing.T) {
}, false)
})
}
func TestBucket_Update(t *testing.T) {
testAndAssertBucketUpdate := func(t *testing.T, b *Bucket, s *xorm.Session) {
err := b.Update(s)
assert.NoError(t, err)
err = s.Commit()
assert.NoError(t, err)
db.AssertExists(t, "buckets", map[string]interface{}{
"id": 1,
"title": b.Title,
"limit": b.Limit,
}, false)
}
t.Run("normal", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
b := &Bucket{
ID: 1,
Title: "New Name",
Limit: 2,
}
testAndAssertBucketUpdate(t, b, s)
})
t.Run("reset limit", func(t *testing.T) {
db.LoadAndAssertFixtures(t)
s := db.NewSession()
defer s.Close()
b := &Bucket{
ID: 1,
Title: "testbucket1",
Limit: 0,
}
testAndAssertBucketUpdate(t, b, s)
})
}