A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
910 B

  1. // Copyright 2021 Gitea. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package models
  5. import (
  6. "testing"
  7. "github.com/stretchr/testify/assert"
  8. )
  9. func TestDeleteOrphanedObjects(t *testing.T) {
  10. assert.NoError(t, PrepareTestDatabase())
  11. countBefore, err := x.Count(&PullRequest{})
  12. assert.NoError(t, err)
  13. _, err = x.Insert(&PullRequest{IssueID: 1000}, &PullRequest{IssueID: 1001}, &PullRequest{IssueID: 1003})
  14. assert.NoError(t, err)
  15. orphaned, err := CountOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
  16. assert.NoError(t, err)
  17. assert.EqualValues(t, 3, orphaned)
  18. err = DeleteOrphanedObjects("pull_request", "issue", "pull_request.issue_id=issue.id")
  19. assert.NoError(t, err)
  20. countAfter, err := x.Count(&PullRequest{})
  21. assert.NoError(t, err)
  22. assert.EqualValues(t, countBefore, countAfter)
  23. }