Commit 9415d0b1 authored by Jarka Kadlecova's avatar Jarka Kadlecova

Check if a merge request is approved when using merge slash command

parent bf993f70
......@@ -967,6 +967,7 @@ class MergeRequest < ActiveRecord::Base
def mergeable_with_slash_command?(current_user, autocomplete_precheck: false, last_diff_sha: nil)
return false unless can_be_merged_by?(current_user)
return false unless approved?
return true if autocomplete_precheck
......
......@@ -1956,6 +1956,22 @@ describe MergeRequest, models: true do
expect(merge_request.mergeable_with_slash_command?(developer, last_diff_sha: mr_sha)).to be_truthy
end
end
context 'with approvals' do
before do
merge_request.target_project.update_attributes(approvals_before_merge: 1)
end
it 'is not mergeable when not approved' do
expect(merge_request.mergeable_with_slash_command?(developer, last_diff_sha: mr_sha)).to be_falsey
end
it 'is mergeable when approved' do
merge_request.approvals.create(user: user)
expect(merge_request.mergeable_with_slash_command?(developer, last_diff_sha: mr_sha)).to be_truthy
end
end
end
end
......
......@@ -230,6 +230,35 @@ describe MergeRequests::UpdateService, services: true do
it { expect(@merge_request.state).to eq('opened') }
end
context 'when not approved' do
before do
merge_request.update_attributes(approvals_before_merge: 1)
perform_enqueued_jobs do
service.execute(merge_request)
@merge_request = MergeRequest.find(merge_request.id)
end
end
it { expect(@merge_request).to be_valid }
it { expect(@merge_request.state).to eq('opened') }
end
context 'when approved' do
before do
merge_request.update_attributes(approvals_before_merge: 1)
merge_request.approvals.create(user: user)
perform_enqueued_jobs do
service.execute(merge_request)
@merge_request = MergeRequest.find(merge_request.id)
end
end
it { expect(@merge_request).to be_valid }
it { expect(@merge_request.state).to eq('merged') }
end
end
context 'todos' do
......
......@@ -355,6 +355,29 @@ describe SlashCommands::InterpretService, services: true do
let(:issuable) { build(:merge_request, source_project: project) }
end
end
context 'not approved merge request can not be merged' do
before do
merge_request.target_project.update_attributes(approvals_before_merge: 1)
end
it_behaves_like 'empty command' do
let(:content) { "/merge" }
let(:issuable) { build(:merge_request, source_project: project) }
end
end
context 'approved merge request can be merged' do
before do
merge_request.update_attributes(approvals_before_merge: 1)
merge_request.approvals.create(user: developer)
end
it_behaves_like 'empty command' do
let(:content) { "/merge" }
let(:issuable) { build(:merge_request, source_project: project) }
end
end
end
it_behaves_like 'title command' 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