aboutsummaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
Diffstat (limited to 'models')
-rw-r--r--models/issues/issue_list_test.go4
-rw-r--r--models/issues/issue_project.go9
-rw-r--r--models/issues/issue_test.go45
3 files changed, 51 insertions, 7 deletions
diff --git a/models/issues/issue_list_test.go b/models/issues/issue_list_test.go
index 97ce9e43b3..696c3b765d 100644
--- a/models/issues/issue_list_test.go
+++ b/models/issues/issue_list_test.go
@@ -67,9 +67,7 @@ func TestIssueList_LoadAttributes(t *testing.T) {
if issue.ID == int64(1) {
assert.Equal(t, int64(400), issue.TotalTrackedTime)
assert.NotNil(t, issue.Project)
- } else if issue.ID == int64(2) {
- assert.Equal(t, int64(3682), issue.TotalTrackedTime)
- assert.Nil(t, issue.Project)
+ assert.Equal(t, int64(1), issue.Project.ID)
} else {
assert.Nil(t, issue.Project)
}
diff --git a/models/issues/issue_project.go b/models/issues/issue_project.go
index b163c68357..782638d997 100644
--- a/models/issues/issue_project.go
+++ b/models/issues/issue_project.go
@@ -16,13 +16,14 @@ import (
func (issue *Issue) LoadProject(ctx context.Context) (err error) {
if issue.Project == nil {
var p project_model.Project
- if _, err = db.GetEngine(ctx).Table("project").
+ has, err := db.GetEngine(ctx).Table("project").
Join("INNER", "project_issue", "project.id=project_issue.project_id").
- Where("project_issue.issue_id = ?", issue.ID).
- Get(&p); err != nil {
+ Where("project_issue.issue_id = ?", issue.ID).Get(&p)
+ if err != nil {
return err
+ } else if has {
+ issue.Project = &p
}
- issue.Project = &p
}
return err
}
diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go
index 80699a57b4..7f1eab1971 100644
--- a/models/issues/issue_test.go
+++ b/models/issues/issue_test.go
@@ -17,6 +17,7 @@ import (
repo_model "code.gitea.io/gitea/models/repo"
"code.gitea.io/gitea/models/unittest"
user_model "code.gitea.io/gitea/models/user"
+ "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"
"github.com/stretchr/testify/assert"
@@ -539,3 +540,47 @@ func TestCountIssues(t *testing.T) {
assert.NoError(t, err)
assert.EqualValues(t, 18, count)
}
+
+func TestIssueLoadAttributes(t *testing.T) {
+ assert.NoError(t, unittest.PrepareTestDatabase())
+ setting.Service.EnableTimetracking = true
+
+ issueList := issues_model.IssueList{
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}),
+ unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 4}),
+ }
+
+ for _, issue := range issueList {
+ assert.NoError(t, issue.LoadAttributes(db.DefaultContext))
+ assert.EqualValues(t, issue.RepoID, issue.Repo.ID)
+ for _, label := range issue.Labels {
+ assert.EqualValues(t, issue.RepoID, label.RepoID)
+ unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
+ }
+ if issue.PosterID > 0 {
+ assert.EqualValues(t, issue.PosterID, issue.Poster.ID)
+ }
+ if issue.AssigneeID > 0 {
+ assert.EqualValues(t, issue.AssigneeID, issue.Assignee.ID)
+ }
+ if issue.MilestoneID > 0 {
+ assert.EqualValues(t, issue.MilestoneID, issue.Milestone.ID)
+ }
+ if issue.IsPull {
+ assert.EqualValues(t, issue.ID, issue.PullRequest.IssueID)
+ }
+ for _, attachment := range issue.Attachments {
+ assert.EqualValues(t, issue.ID, attachment.IssueID)
+ }
+ for _, comment := range issue.Comments {
+ assert.EqualValues(t, issue.ID, comment.IssueID)
+ }
+ if issue.ID == int64(1) {
+ assert.Equal(t, int64(400), issue.TotalTrackedTime)
+ assert.NotNil(t, issue.Project)
+ assert.Equal(t, int64(1), issue.Project.ID)
+ } else {
+ assert.Nil(t, issue.Project)
+ }
+ }
+}