Fix resetting the bucket limit
This commit is contained in:
parent
2e88600c93
commit
d69c799197
2 changed files with 49 additions and 1 deletions
|
@ -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
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue