Commit c17f5d06 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Fix merge api and spec

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent 66bdbdb3
...@@ -200,7 +200,7 @@ module API ...@@ -200,7 +200,7 @@ module API
if merge_request.can_be_merged? if merge_request.can_be_merged?
commit_message = params[:merge_commit_message] || merge_request.merge_commit_message commit_message = params[:merge_commit_message] || merge_request.merge_commit_message
MergeRequests::MergeService.new(merge_request.target_project, current_user). ::MergeRequests::MergeService.new(merge_request.target_project, current_user).
execute(merge_request, commit_message) execute(merge_request, commit_message)
present merge_request, with: Entities::MergeRequest present merge_request, with: Entities::MergeRequest
......
...@@ -147,7 +147,7 @@ describe API::API, api: true do ...@@ -147,7 +147,7 @@ describe API::API, api: true do
it "should return merge_request" do it "should return merge_request" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request', title: 'Test merge_request',
source_branch: 'stable', source_branch: 'feature_conflict',
target_branch: 'master', target_branch: 'master',
author: user, author: user,
labels: 'label, label2' labels: 'label, label2'
...@@ -170,20 +170,20 @@ describe API::API, api: true do ...@@ -170,20 +170,20 @@ describe API::API, api: true do
it "should return 400 when target_branch is missing" do it "should return 400 when target_branch is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: "Test merge_request", source_branch: "stable", author: user title: "Test merge_request", source_branch: "markdown", author: user
expect(response.status).to eq(400) expect(response.status).to eq(400)
end end
it "should return 400 when title is missing" do it "should return 400 when title is missing" do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
target_branch: 'master', source_branch: 'stable' target_branch: 'master', source_branch: 'markdown'
expect(response.status).to eq(400) expect(response.status).to eq(400)
end end
it 'should return 400 on invalid label names' do it 'should return 400 on invalid label names' do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request', title: 'Test merge_request',
source_branch: 'stable', source_branch: 'markdown',
target_branch: 'master', target_branch: 'master',
author: user, author: user,
labels: 'label, ?' labels: 'label, ?'
...@@ -197,7 +197,7 @@ describe API::API, api: true do ...@@ -197,7 +197,7 @@ describe API::API, api: true do
before do before do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request', title: 'Test merge_request',
source_branch: 'stable', source_branch: 'feature_conflict',
target_branch: 'master', target_branch: 'master',
author: user author: user
@mr = MergeRequest.all.last @mr = MergeRequest.all.last
...@@ -207,7 +207,7 @@ describe API::API, api: true do ...@@ -207,7 +207,7 @@ describe API::API, api: true do
expect do expect do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: 'New test merge_request', title: 'New test merge_request',
source_branch: 'stable', source_branch: 'feature_conflict',
target_branch: 'master', target_branch: 'master',
author: user author: user
end.to change { MergeRequest.count }.by(0) end.to change { MergeRequest.count }.by(0)
...@@ -227,7 +227,8 @@ describe API::API, api: true do ...@@ -227,7 +227,8 @@ describe API::API, api: true do
it "should return merge_request" do it "should return merge_request" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', source_branch: "stable", target_branch: "master", author: user2, target_project_id: project.id, description: 'Test description for Test merge_request' title: 'Test merge_request', source_branch: "feature_conflict", target_branch: "master",
author: user2, target_project_id: project.id, description: 'Test description for Test merge_request'
expect(response.status).to eq(201) expect(response.status).to eq(201)
expect(json_response['title']).to eq('Test merge_request') expect(json_response['title']).to eq('Test merge_request')
expect(json_response['description']).to eq('Test description for Test merge_request') expect(json_response['description']).to eq('Test description for Test merge_request')
...@@ -257,7 +258,7 @@ describe API::API, api: true do ...@@ -257,7 +258,7 @@ describe API::API, api: true do
it "should return 400 when title is missing" do it "should return 400 when title is missing" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: project.id target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: project.id
expect(response.status).to eq(400) expect(response.status).to eq(400)
end end
...@@ -266,7 +267,7 @@ describe API::API, api: true do ...@@ -266,7 +267,7 @@ describe API::API, api: true do
post api("/projects/#{project.id}/merge_requests", user), post api("/projects/#{project.id}/merge_requests", user),
title: 'Test merge_request', title: 'Test merge_request',
target_branch: 'master', target_branch: 'master',
source_branch: 'stable', source_branch: 'markdown',
author: user, author: user,
target_project_id: fork_project.id target_project_id: fork_project.id
expect(response.status).to eq(422) expect(response.status).to eq(422)
...@@ -276,7 +277,7 @@ describe API::API, api: true do ...@@ -276,7 +277,7 @@ describe API::API, api: true do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', title: 'Test merge_request',
target_branch: 'master', target_branch: 'master',
source_branch: 'stable', source_branch: 'markdown',
author: user2, author: user2,
target_project_id: unrelated_project.id target_project_id: unrelated_project.id
expect(response.status).to eq(422) expect(response.status).to eq(422)
...@@ -285,7 +286,7 @@ describe API::API, api: true do ...@@ -285,7 +286,7 @@ describe API::API, api: true do
it "should return 201 when target_branch is specified and for the same project" do it "should return 201 when target_branch is specified and for the same project" do
post api("/projects/#{fork_project.id}/merge_requests", user2), post api("/projects/#{fork_project.id}/merge_requests", user2),
title: 'Test merge_request', target_branch: 'master', source_branch: 'stable', author: user2, target_project_id: fork_project.id title: 'Test merge_request', target_branch: 'master', source_branch: 'markdown', author: user2, target_project_id: fork_project.id
expect(response.status).to eq(201) expect(response.status).to eq(201)
end end
end end
...@@ -301,9 +302,6 @@ describe API::API, api: true do ...@@ -301,9 +302,6 @@ describe API::API, api: true do
describe "PUT /projects/:id/merge_request/:merge_request_id/merge" do describe "PUT /projects/:id/merge_request/:merge_request_id/merge" do
it "should return merge_request in case of success" do it "should return merge_request in case of success" do
allow_any_instance_of(MergeRequest).
to receive_messages(can_be_merged?: true, automerge!: true)
put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user) put api("/projects/#{project.id}/merge_request/#{merge_request.id}/merge", user)
expect(response.status).to eq(200) expect(response.status).to eq(200)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment