mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-12-18 03:17:56 +01:00
Merge pull request '[BUG] Ensure HasIssueContentHistory
takes into account comment_id
' (#2518) from gusted/forgejo-default-value-sql-error into forgejo
Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/2518 Reviewed-by: oliverpool <oliverpool@noreply.codeberg.org>
This commit is contained in:
commit
9ce3068f36
2 changed files with 14 additions and 9 deletions
|
@ -172,15 +172,7 @@ func FetchIssueContentHistoryList(dbCtx context.Context, issueID, commentID int6
|
||||||
|
|
||||||
// HasIssueContentHistory check if a ContentHistory entry exists
|
// HasIssueContentHistory check if a ContentHistory entry exists
|
||||||
func HasIssueContentHistory(dbCtx context.Context, issueID, commentID int64) (bool, error) {
|
func HasIssueContentHistory(dbCtx context.Context, issueID, commentID int64) (bool, error) {
|
||||||
exists, err := db.GetEngine(dbCtx).Cols("id").Exist(&ContentHistory{
|
return db.GetEngine(dbCtx).Where("issue_id = ? AND comment_id = ?", issueID, commentID).Exist(new(ContentHistory))
|
||||||
IssueID: issueID,
|
|
||||||
CommentID: commentID,
|
|
||||||
})
|
|
||||||
if err != nil {
|
|
||||||
log.Error("can not fetch issue content history. err=%v", err)
|
|
||||||
return false, err
|
|
||||||
}
|
|
||||||
return exists, err
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// SoftDeleteIssueContentHistory soft delete
|
// SoftDeleteIssueContentHistory soft delete
|
||||||
|
|
|
@ -78,3 +78,16 @@ func TestContentHistory(t *testing.T) {
|
||||||
assert.EqualValues(t, 7, list2[1].HistoryID)
|
assert.EqualValues(t, 7, list2[1].HistoryID)
|
||||||
assert.EqualValues(t, 4, list2[2].HistoryID)
|
assert.EqualValues(t, 4, list2[2].HistoryID)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestHasIssueContentHistory(t *testing.T) {
|
||||||
|
assert.NoError(t, unittest.PrepareTestDatabase())
|
||||||
|
|
||||||
|
// Ensures that comment_id is into taken account even if it's zero.
|
||||||
|
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 11, 100, timeutil.TimeStampNow(), "c-a", true)
|
||||||
|
_ = issues_model.SaveIssueContentHistory(db.DefaultContext, 1, 11, 100, timeutil.TimeStampNow().Add(5), "c-b", false)
|
||||||
|
|
||||||
|
hasHistory1, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 11, 0)
|
||||||
|
assert.False(t, hasHistory1)
|
||||||
|
hasHistory2, _ := issues_model.HasIssueContentHistory(db.DefaultContext, 11, 100)
|
||||||
|
assert.True(t, hasHistory2)
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue