Fix API bug accepting wrong merge requests parameters

This commit is contained in:
Felipe Artur 2017-06-14 17:38:27 -03:00
parent 43e1481c81
commit c472017078
3 changed files with 28 additions and 4 deletions

View file

@ -0,0 +1,4 @@
---
title: Fix API bug accepting wrong parameter to create merge request
merge_request:
author:

View file

@ -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

View file

@ -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