From baed01f24753afb600a2984dcb9bcda0bb8502b6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Mon, 22 Nov 2021 23:21:55 +0800 Subject: Remove unnecessary attributes of User struct (#17745) * Remove unnecessary functions of User struct * Move more database methods out of user struct * Move more database methods out of user struct * Fix template failure * Fix bug * Remove finished FIXME * remove unnecessary code --- models/star_test.go | 50 ++------------------------------------------------ 1 file changed, 2 insertions(+), 48 deletions(-) (limited to 'models/star_test.go') diff --git a/models/star_test.go b/models/star_test.go index f9a7ddb0f2..eef1a0c5fb 100644 --- a/models/star_test.go +++ b/models/star_test.go @@ -36,7 +36,7 @@ func TestRepository_GetStargazers(t *testing.T) { // repo with stargazers assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 4}).(*Repository) - gazers, err := repo.GetStargazers(db.ListOptions{Page: 0}) + gazers, err := GetStargazers(repo, db.ListOptions{Page: 0}) assert.NoError(t, err) if assert.Len(t, gazers, 1) { assert.Equal(t, int64(2), gazers[0].ID) @@ -47,53 +47,7 @@ func TestRepository_GetStargazers2(t *testing.T) { // repo with stargazers assert.NoError(t, unittest.PrepareTestDatabase()) repo := unittest.AssertExistsAndLoadBean(t, &Repository{ID: 3}).(*Repository) - gazers, err := repo.GetStargazers(db.ListOptions{Page: 0}) + gazers, err := GetStargazers(repo, db.ListOptions{Page: 0}) assert.NoError(t, err) assert.Len(t, gazers, 0) } - -func TestUser_GetStarredRepos(t *testing.T) { - // user who has starred repos - assert.NoError(t, unittest.PrepareTestDatabase()) - - user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - starred, err := user.GetStarredRepos(false, 1, 10, "") - assert.NoError(t, err) - if assert.Len(t, starred, 1) { - assert.Equal(t, int64(4), starred[0].ID) - } - - starred, err = user.GetStarredRepos(true, 1, 10, "") - assert.NoError(t, err) - if assert.Len(t, starred, 2) { - assert.Equal(t, int64(2), starred[0].ID) - assert.Equal(t, int64(4), starred[1].ID) - } -} - -func TestUser_GetStarredRepos2(t *testing.T) { - // user who has no starred repos - assert.NoError(t, unittest.PrepareTestDatabase()) - - user := unittest.AssertExistsAndLoadBean(t, &User{ID: 1}).(*User) - starred, err := user.GetStarredRepos(false, 1, 10, "") - assert.NoError(t, err) - assert.Len(t, starred, 0) - - starred, err = user.GetStarredRepos(true, 1, 10, "") - assert.NoError(t, err) - assert.Len(t, starred, 0) -} - -func TestUserGetStarredRepoCount(t *testing.T) { - assert.NoError(t, unittest.PrepareTestDatabase()) - - user := unittest.AssertExistsAndLoadBean(t, &User{ID: 2}).(*User) - counts, err := user.GetStarredRepoCount(false) - assert.NoError(t, err) - assert.Equal(t, int64(1), counts) - - counts, err = user.GetStarredRepoCount(true) - assert.NoError(t, err) - assert.Equal(t, int64(2), counts) -} -- cgit v1.2.3