Commit 1353b579 authored by Igor Drozdov's avatar Igor Drozdov Committed by Mike Kozono

Show regular rules without approvers

parent b8bc2883
---
title: Show regular rules without approvers
merge_request: 21918
author:
type: fixed
...@@ -176,11 +176,8 @@ class ApprovalState ...@@ -176,11 +176,8 @@ class ApprovalState
def user_defined_merge_request_rules def user_defined_merge_request_rules
strong_memoize(:user_defined_merge_request_rules) do strong_memoize(:user_defined_merge_request_rules) do
# Filter out the rules without approvers since such rules aren't useful
regular_rules = regular_rules =
wrapped_rules wrapped_rules.select(&:regular?).sort_by(&:id)
.select { |rule| rule.regular? && rule.approvers.present? }
.sort_by(&:id)
any_approver_rules = any_approver_rules =
wrapped_rules.select(&:any_approver?) wrapped_rules.select(&:any_approver?)
......
...@@ -106,28 +106,6 @@ describe ApprovalState do ...@@ -106,28 +106,6 @@ describe ApprovalState do
end end
end end
context 'when approval rule on the merge request exists' do
before do
create(:approval_merge_request_rule, merge_request: merge_request, users: approvers)
end
context 'without approvers' do
let(:approvers) { [] }
it 'returns false' do
expect(subject.approval_rules_overwritten?).to eq(false)
end
end
context 'with approvers' do
let(:approvers) { [create(:user)] }
it 'returns true' do
expect(subject.approval_rules_overwritten?).to eq(true)
end
end
end
context 'when merge request has any approver rule' do context 'when merge request has any approver rule' do
let!(:any_approver_rule) { create(:any_approver_rule, merge_request: merge_request) } let!(:any_approver_rule) { create(:any_approver_rule, merge_request: merge_request) }
...@@ -594,14 +572,10 @@ describe ApprovalState do ...@@ -594,14 +572,10 @@ describe ApprovalState do
end end
context 'when there is one approver required' do context 'when there is one approver required' do
let!(:rule) { create_rule(approvals_required: 1, users: []) } let!(:any_approver_rule) { create_rule(rule_type: :any_approver, approvals_required: 1) }
let!(:rule) { create_rule(approvals_required: 1, users: [author]) }
context 'when that approver is the MR author' do context 'when that approver is the MR author' do
before do
project.update!(approvals_before_merge: 2)
rule.users << author
end
it_behaves_like 'authors self-approval authorization' it_behaves_like 'authors self-approval authorization'
it_behaves_like 'a MR that all members with write access can approve' it_behaves_like 'a MR that all members with write access can approve'
...@@ -610,30 +584,10 @@ describe ApprovalState do ...@@ -610,30 +584,10 @@ describe ApprovalState do
expect(subject.can_approve?(nil)).to be_falsey expect(subject.can_approve?(nil)).to be_falsey
end end
it 'fallback rule is used' do
expect(subject.approvals_left).to eq(2)
end
it 'is not approved' do it 'is not approved' do
expect(subject.approvals_left).to eq(2)
expect(subject.approved?).to eq(false) expect(subject.approved?).to eq(false)
end end
context 'with project approval rule' do
before do
create(:approval_project_rule, project: project, approvals_required: 1, users: [approver])
end
context 'with approvers' do
let(:approver) { create(:user) }
it 'requires one approval' do
rule = subject.wrapped_approval_rules.last.approval_rule
expect(rule).to be_a(ApprovalProjectRule)
expect(subject.approvers).to eq([approver])
end
end
end
end end
end end
...@@ -1251,14 +1205,10 @@ describe ApprovalState do ...@@ -1251,14 +1205,10 @@ describe ApprovalState do
end end
context 'when there is one approver required' do context 'when there is one approver required' do
let!(:rule) { create_rule(approvals_required: 1, users: []) } let!(:rule) { create_rule(approvals_required: 1, users: [author]) }
let!(:any_approver_rule) { create_rule(rule_type: :any_approver, approvals_required: 1) }
context 'when that approver is the MR author' do context 'when that approver is the MR author' do
before do
project.update!(approvals_before_merge: 1)
rule.users << author
end
it_behaves_like 'authors self-approval authorization' it_behaves_like 'authors self-approval authorization'
it_behaves_like 'a MR that all members with write access can approve' it_behaves_like 'a MR that all members with write access can approve'
......
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