Commit a40973ae authored by Gary Holtz's avatar Gary Holtz Committed by Heinrich Lee Yu

Forward the `approvals_required` method

Initial exploration of this problem. I would think if an MR needs "X"
approvals, that would supersede the project's rule of "Y" approvals.

We'll see what the pipeline says!
parent a195f9d9
...@@ -11,6 +11,7 @@ module Approvable ...@@ -11,6 +11,7 @@ module Approvable
approval_needed? approval_needed?
approved? approved?
approvals_left approvals_left
approvals_required
can_approve? can_approve?
has_approved? has_approved?
authors_can_approve? authors_can_approve?
...@@ -38,10 +39,6 @@ module Approvable ...@@ -38,10 +39,6 @@ module Approvable
approvals.size approvals.size
end end
def approvals_required
[approvals_before_merge.to_i, target_project.approvals_before_merge.to_i].max
end
def approvals_before_merge def approvals_before_merge
return unless approval_feature_available? return unless approval_feature_available?
......
---
title: Correctly display the number of approvals for a merge request
merge_request: 23827
author:
type: fixed
...@@ -323,6 +323,15 @@ describe ApprovalState do ...@@ -323,6 +323,15 @@ describe ApprovalState do
end end
end end
describe '#approvals_required' do
it "correctly sums the approvals" do
create_rule(approvals_required: 3)
create_rule(approvals_required: 10)
expect(subject.approvals_required).to eq(13)
end
end
describe '#approvers' do describe '#approvers' do
it 'includes all approvers, including code owner and group members' do it 'includes all approvers, including code owner and group members' do
create_rule(users: [approver1]) create_rule(users: [approver1])
......
...@@ -684,30 +684,6 @@ describe MergeRequest do ...@@ -684,30 +684,6 @@ describe MergeRequest do
end end
end end
describe '#approvals_required' do
where(:license_value, :db_value, :project_db_value, :expected) do
true | 5 | 6 | 6
true | 6 | 5 | 6
true | nil | 5 | 5
false | 5 | 6 | 0
false | nil | 5 | 0
end
with_them do
let(:merge_request) { build(:merge_request, approvals_before_merge: db_value) }
subject { merge_request.approvals_required }
before do
stub_licensed_features(merge_request_approvers: license_value)
merge_request.target_project.approvals_before_merge = project_db_value
end
it { is_expected.to eq(expected) }
end
end
describe '#mergeable?' do describe '#mergeable?' do
let(:project) { create(:project) } let(:project) { create(:project) }
......
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