Commit a4a5cbf2 authored by Sean McGivern's avatar Sean McGivern

Merge branch 'issue_33205' into 'master'

Fix API bug accepting wrong merge requests parameters

Closes #33205

See merge request !12173
parents ea59f664 c4720170
---
title: Fix API bug accepting wrong parameter to create merge request
merge_request:
author:
......@@ -97,7 +97,7 @@ module API
authorize! :create_merge_request, user_project
mr_params = declared_params(include_missing: false)
mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch) if mr_params[:remove_source_branch].present?
mr_params[:force_remove_source_branch] = mr_params.delete(:remove_source_branch)
merge_request = ::MergeRequests::CreateService.new(user_project, current_user, mr_params).execute
......
......@@ -334,14 +334,13 @@ describe API::MergeRequests do
target_branch: 'master',
author: user,
labels: 'label, label2',
milestone_id: milestone.id,
remove_source_branch: true
milestone_id: milestone.id
expect(response).to have_http_status(201)
expect(json_response['title']).to eq('Test merge_request')
expect(json_response['labels']).to eq(%w(label label2))
expect(json_response['milestone']['id']).to eq(milestone.id)
expect(json_response['force_remove_source_branch']).to be_truthy
expect(json_response['force_remove_source_branch']).to be_falsy
end
it "returns 422 when source_branch equals target_branch" do
......@@ -404,6 +403,27 @@ describe API::MergeRequests do
expect(response).to have_http_status(409)
end
end
context 'accepts remove_source_branch parameter' do
let(:params) do
{ title: 'Test merge_request',
source_branch: 'markdown',
target_branch: 'master',
author: user }
end
it 'sets force_remove_source_branch to false' do
post api("/projects/#{project.id}/merge_requests", user), params.merge(remove_source_branch: false)
expect(json_response['force_remove_source_branch']).to be_falsy
end
it 'sets force_remove_source_branch to true' do
post api("/projects/#{project.id}/merge_requests", user), params.merge(remove_source_branch: true)
expect(json_response['force_remove_source_branch']).to be_truthy
end
end
end
context 'forked projects' do
......
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