Skip to content

Commit 61d7ece

Browse files
committed
Fix test
1 parent 48c40c6 commit 61d7ece

File tree

6 files changed

+20
-15
lines changed

6 files changed

+20
-15
lines changed

models/org.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,11 @@ func (org *Organization) DisplayName() string {
193193
return org.AsUser().DisplayName()
194194
}
195195

196+
// CustomAvatarRelativePath returns user custom avatar relative path.
197+
func (org *Organization) CustomAvatarRelativePath() string {
198+
return org.Avatar
199+
}
200+
196201
// CreateOrganization creates record of a new organization.
197202
func CreateOrganization(org *Organization, owner *User) (err error) {
198203
if !owner.CanCreateOrganization() {
@@ -314,7 +319,11 @@ func CountOrganizations() int64 {
314319
}
315320

316321
// DeleteOrganization deletes models associated to an organization.
317-
func DeleteOrganization(ctx context.Context, org *User) error {
322+
func DeleteOrganization(ctx context.Context, org *Organization) error {
323+
if org.Type != UserTypeOrganization {
324+
return fmt.Errorf("%s is a user not an organization", org.Name)
325+
}
326+
318327
e := db.GetEngine(ctx)
319328

320329
if err := deleteBeans(e,

models/repo.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1803,8 +1803,8 @@ func getPrivateRepositoryCount(e db.Engine, u *User) (int64, error) {
18031803
}
18041804

18051805
// GetRepositoryCount returns the total number of repositories of user.
1806-
func GetRepositoryCount(ctx context.Context, u *User) (int64, error) {
1807-
return getRepositoryCount(db.GetEngine(ctx), u.ID)
1806+
func GetRepositoryCount(ctx context.Context, ownerID int64) (int64, error) {
1807+
return getRepositoryCount(db.GetEngine(ctx), ownerID)
18081808
}
18091809

18101810
// GetPublicRepositoryCount returns the total number of public repositories of user.

models/repo_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ func TestMetas(t *testing.T) {
7171
func TestGetRepositoryCount(t *testing.T) {
7272
assert.NoError(t, unittest.PrepareTestDatabase())
7373

74-
count, err1 := GetRepositoryCount(db.DefaultContext, &User{ID: int64(10)})
74+
count, err1 := GetRepositoryCount(db.DefaultContext, 10)
7575
privateCount, err2 := GetPrivateRepositoryCount(&User{ID: int64(10)})
7676
publicCount, err3 := GetPublicRepositoryCount(&User{ID: int64(10)})
7777
assert.NoError(t, err1)

services/org/org.go

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,15 @@ import (
1414
)
1515

1616
// DeleteOrganization completely and permanently deletes everything of organization.
17-
func DeleteOrganization(org *models.User) error {
18-
if !org.IsOrganization() {
19-
return fmt.Errorf("%s is a user not an organization", org.Name)
20-
}
21-
17+
func DeleteOrganization(org *models.Organization) error {
2218
ctx, commiter, err := db.TxContext()
2319
if err != nil {
2420
return err
2521
}
2622
defer commiter.Close()
2723

2824
// Check ownership of repository.
29-
count, err := models.GetRepositoryCount(ctx, org)
25+
count, err := models.GetRepositoryCount(ctx, org.ID)
3026
if err != nil {
3127
return fmt.Errorf("GetRepositoryCount: %v", err)
3228
} else if count > 0 {

services/org/org_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ func TestMain(m *testing.M) {
2020

2121
func TestDeleteOrganization(t *testing.T) {
2222
assert.NoError(t, unittest.PrepareTestDatabase())
23-
org := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 6}).(*models.User)
23+
org := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 6}).(*models.Organization)
2424
assert.NoError(t, DeleteOrganization(org))
25-
unittest.AssertNotExistsBean(t, &models.User{ID: 6})
25+
unittest.AssertNotExistsBean(t, &models.Organization{ID: 6})
2626
unittest.AssertNotExistsBean(t, &models.OrgUser{OrgID: 6})
2727
unittest.AssertNotExistsBean(t, &models.Team{OrgID: 6})
2828

29-
org = unittest.AssertExistsAndLoadBean(t, &models.User{ID: 3}).(*models.User)
29+
org = unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 3}).(*models.Organization)
3030
err := DeleteOrganization(org)
3131
assert.Error(t, err)
3232
assert.True(t, models.IsErrUserOwnRepos(err))
3333

34-
user := unittest.AssertExistsAndLoadBean(t, &models.User{ID: 5}).(*models.User)
34+
user := unittest.AssertExistsAndLoadBean(t, &models.Organization{ID: 5}).(*models.Organization)
3535
assert.Error(t, DeleteOrganization(user))
3636
unittest.CheckConsistencyFor(t, &models.User{}, &models.Team{})
3737
}

services/user/user.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func DeleteUser(u *models.User) error {
3535
// cannot perform delete operation.
3636

3737
// Check ownership of repository.
38-
count, err := models.GetRepositoryCount(ctx, u)
38+
count, err := models.GetRepositoryCount(ctx, u.ID)
3939
if err != nil {
4040
return fmt.Errorf("GetRepositoryCount: %v", err)
4141
} else if count > 0 {

0 commit comments

Comments
 (0)