diff --git a/models/fixtures/repository.yml b/models/fixtures/repository.yml index d50b88c3013..873eb612c7b 100644 --- a/models/fixtures/repository.yml +++ b/models/fixtures/repository.yml @@ -105,3 +105,29 @@ num_pulls: 0 num_closed_pulls: 0 is_mirror: false + +- + id: 10 + owner_id: 12 + lower_name: repo10 + name: repo10 + is_private: false + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + is_mirror: false + num_forks: 1 + +- + id: 11 + fork_id: 10 + owner_id: 13 + lower_name: repo11 + name: repo11 + is_private: false + num_issues: 0 + num_closed_issues: 0 + num_pulls: 0 + num_closed_pulls: 0 + is_mirror: false diff --git a/models/fixtures/user.yml b/models/fixtures/user.yml index 337fb54590d..8874498c916 100644 --- a/models/fixtures/user.yml +++ b/models/fixtures/user.yml @@ -164,3 +164,33 @@ avatar_email: user11@example.com num_repos: 1 is_active: true + +- + id: 12 + lower_name: user12 + name: user12 + full_name: User 12 + email: user12@example.com + passwd: password + type: 0 # individual + salt: salt + is_admin: false + avatar: avatar12 + avatar_email: user12@example.com + num_repos: 1 + is_active: true + +- + id: 13 + lower_name: user13 + name: user13 + full_name: User 13 + email: user13@example.com + passwd: password + type: 0 # individual + salt: salt + is_admin: false + avatar: avatar13 + avatar_email: user13@example.com + num_repos: 1 + is_active: true diff --git a/models/repo_test.go b/models/repo_test.go index 18da682059b..7c0e94a5aed 100644 --- a/models/repo_test.go +++ b/models/repo_test.go @@ -92,3 +92,36 @@ func TestUpdateRepositoryVisibilityChanged(t *testing.T) { assert.NoError(t, err) assert.Equal(t, true, act.IsPrivate) } + +func TestGetUserFork(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + // User13 has repo 11 forked from repo10 + repo, err := GetRepositoryByID(10) + assert.NoError(t, err) + assert.NotNil(t, repo) + repo, err = repo.GetUserFork(13) + assert.NoError(t, err) + assert.NotNil(t, repo) + + repo, err = GetRepositoryByID(9) + assert.NoError(t, err) + assert.NotNil(t, repo) + repo, err = repo.GetUserFork(13) + assert.NoError(t, err) + assert.Nil(t, repo) +} + +func TestForkRepository(t *testing.T) { + assert.NoError(t, PrepareTestDatabase()) + + // User13 has repo 11 forked from repo10 + repo, err := GetRepositoryByID(10) + assert.NoError(t, err) + assert.NotNil(t, repo) + + repo, err = ForkRepository(&User{ID: 13}, repo, "test", "test") + assert.Nil(t, repo) + assert.Error(t, err) + assert.True(t, IsErrRepoAlreadyExist(err)) +}