From bc78ae6985ee37f9ac2ffc2dbf6f445078d16038 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Mon, 22 Jan 2018 18:10:56 +0000 Subject: Add specs --- spec/requests/api/internal_spec.rb | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) (limited to 'spec/requests/api/internal_spec.rb') diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 884a258fd12..5f6790312e4 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -366,25 +366,28 @@ describe API::Internal do end end - context 'project as /namespace/project' do + context 'project as namespace/project' do it do - pull(key, project_with_repo_path('/' + project.full_path)) + push(key, project_with_repo_path(project.full_path)) expect(response).to have_gitlab_http_status(200) expect(json_response["status"]).to be_truthy expect(json_response["repository_path"]).to eq(project.repository.path_to_repo) expect(json_response["gl_repository"]).to eq("project-#{project.id}") end - end - context 'project as namespace/project' do - it do - pull(key, project_with_repo_path(project.full_path)) + context 'when project does not exist' do + it 'creates a new project' do + path = "#{user.namespace.path}/notexist.git" - expect(response).to have_gitlab_http_status(200) - expect(json_response["status"]).to be_truthy - expect(json_response["repository_path"]).to eq(project.repository.path_to_repo) - expect(json_response["gl_repository"]).to eq("project-#{project.id}") + expect do + push_with_path(key, path) + end.to change { Project.count }.by(1) + + expect(response).to have_gitlab_http_status(200) + expect(json_response["status"]).to be_truthy + expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(path) + end end end end @@ -818,6 +821,19 @@ describe API::Internal do end end + context 'with new project data' do + it 'returns new project message on the response' do + new_project = Gitlab::Checks::NewProject.new(user, project, 'http') + new_project.add_new_project_message + + post api("/internal/post_receive"), valid_params + + expect(response).to have_gitlab_http_status(200) + expect(json_response["new_project_message"]).to be_present + expect(json_response["new_project_message"]).to eq(new_project.new_project_message) + end + end + context 'with an orphaned write deploy key' do it 'does not try to notify that project moved' do allow_any_instance_of(Gitlab::Identifier).to receive(:identify).and_return(nil) -- cgit v1.2.1 From e42a548f1dac02577d0c1731fef508dab68c45a5 Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Thu, 25 Jan 2018 12:26:52 +0000 Subject: Move new project on push logic to a service --- spec/requests/api/internal_spec.rb | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) (limited to 'spec/requests/api/internal_spec.rb') diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 5f6790312e4..1e8197653ce 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -366,6 +366,17 @@ describe API::Internal do end end + context 'project as /namespace/project' do + it do + push(key, project_with_repo_path('/' + project.full_path)) + + expect(response).to have_gitlab_http_status(200) + expect(json_response["status"]).to be_truthy + expect(json_response["repository_path"]).to eq(project.repository.path_to_repo) + expect(json_response["gl_repository"]).to eq("project-#{project.id}") + end + end + context 'project as namespace/project' do it do push(key, project_with_repo_path(project.full_path)) @@ -823,14 +834,14 @@ describe API::Internal do context 'with new project data' do it 'returns new project message on the response' do - new_project = Gitlab::Checks::NewProject.new(user, project, 'http') - new_project.add_new_project_message + project_created = Gitlab::Checks::ProjectCreated.new(user, project, 'http') + project_created.add_project_created_message post api("/internal/post_receive"), valid_params expect(response).to have_gitlab_http_status(200) - expect(json_response["new_project_message"]).to be_present - expect(json_response["new_project_message"]).to eq(new_project.new_project_message) + expect(json_response["project_created_message"]).to be_present + expect(json_response["project_created_message"]).to eq(project_created.project_created_message) end end -- cgit v1.2.1 From dc229c076cdc0ef6e7f3f74f6e462c22880ff08c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 26 Jan 2018 14:28:08 +0000 Subject: Abstracts ProjectMoved and ProjectCreated into a BaseProject --- spec/requests/api/internal_spec.rb | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) (limited to 'spec/requests/api/internal_spec.rb') diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 1e8197653ce..5ef180348aa 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -399,6 +399,18 @@ describe API::Internal do expect(json_response["status"]).to be_truthy expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(path) end + + it 'handles project creation failure' do + path = "#{user.namespace.path}/new.git" + + expect do + push_with_path(key, path) + end.not_to change { Project.count } + + expect(response).to have_gitlab_http_status(200) + expect(json_response["status"]).to be_falsey + expect(json_response["message"]).to eq("Could not create project: Path new is a reserved name") + end end end end @@ -821,27 +833,27 @@ describe API::Internal do context 'with a redirected data' do it 'returns redirected message on the response' do - project_moved = Gitlab::Checks::ProjectMoved.new(project, user, 'foo/baz', 'http') - project_moved.add_redirect_message + project_moved = Gitlab::Checks::ProjectMoved.new(project, user, 'http', 'foo/baz') + project_moved.add_message post api("/internal/post_receive"), valid_params expect(response).to have_gitlab_http_status(200) expect(json_response["redirected_message"]).to be_present - expect(json_response["redirected_message"]).to eq(project_moved.redirect_message) + expect(json_response["redirected_message"]).to eq(project_moved.message) end end context 'with new project data' do it 'returns new project message on the response' do - project_created = Gitlab::Checks::ProjectCreated.new(user, project, 'http') - project_created.add_project_created_message + project_created = Gitlab::Checks::ProjectCreated.new(project, user, 'http') + project_created.add_message post api("/internal/post_receive"), valid_params expect(response).to have_gitlab_http_status(200) expect(json_response["project_created_message"]).to be_present - expect(json_response["project_created_message"]).to eq(project_created.project_created_message) + expect(json_response["project_created_message"]).to eq(project_created.message) end end -- cgit v1.2.1 From 1e56b3f476f9779ec747534e94156a6b8076209c Mon Sep 17 00:00:00 2001 From: Tiago Botelho Date: Fri, 2 Feb 2018 15:27:30 +0000 Subject: Moves project creationg to git access check for git push --- spec/requests/api/internal_spec.rb | 26 -------------------------- 1 file changed, 26 deletions(-) (limited to 'spec/requests/api/internal_spec.rb') diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index 5ef180348aa..ea6b0a71849 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -386,32 +386,6 @@ describe API::Internal do expect(json_response["repository_path"]).to eq(project.repository.path_to_repo) expect(json_response["gl_repository"]).to eq("project-#{project.id}") end - - context 'when project does not exist' do - it 'creates a new project' do - path = "#{user.namespace.path}/notexist.git" - - expect do - push_with_path(key, path) - end.to change { Project.count }.by(1) - - expect(response).to have_gitlab_http_status(200) - expect(json_response["status"]).to be_truthy - expect(json_response["gitaly"]["repository"]["relative_path"]).to eq(path) - end - - it 'handles project creation failure' do - path = "#{user.namespace.path}/new.git" - - expect do - push_with_path(key, path) - end.not_to change { Project.count } - - expect(response).to have_gitlab_http_status(200) - expect(json_response["status"]).to be_falsey - expect(json_response["message"]).to eq("Could not create project: Path new is a reserved name") - end - end end end end -- cgit v1.2.1