Commit f150b0ee authored by Mark Chao's avatar Mark Chao

Hide rules when approval feature is unavailable

This means existing unapproved rules would have no effect on MR
merging process.
parent 502d4014
......@@ -31,6 +31,8 @@ class ApprovalState
def wrapped_approval_rules
strong_memoize(:wrapped_approval_rules) do
next [] unless project.feature_available?(:merge_request_approvers)
result = use_fallback? ? [fallback_rule] : regular_rules
result += code_owner_rules
result
......
......@@ -17,6 +17,11 @@ describe ApprovalState do
end
end
def disable_feature
allow(subject.project).to receive(:feature_available?).and_call_original
allow(subject.project).to receive(:feature_available?).with(:merge_request_approvers).and_return(false)
end
let(:merge_request) { create(:merge_request) }
let(:project) { merge_request.target_project }
let(:approver1) { create(:user) }
......@@ -108,6 +113,14 @@ describe ApprovalState do
expect(subject.wrapped_approval_rules).to all(be_an(ApprovalWrappedRule))
expect(subject.wrapped_approval_rules.size).to eq(2)
end
context 'when approval feature is unavailable' do
it 'returns empty array' do
disable_feature
expect(subject.wrapped_approval_rules).to eq([])
end
end
end
describe '#approval_needed?' do
......@@ -150,6 +163,14 @@ describe ApprovalState do
expect(subject.approval_needed?).to eq(false)
end
end
context 'when approval feature is unavailable' do
it 'returns false' do
disable_feature
expect(subject.approval_needed?).to eq(false)
end
end
end
describe '#approved?' do
......@@ -216,6 +237,15 @@ describe ApprovalState do
it_behaves_like 'when rules are present'
end
context 'when approval feature is unavailable' do
it 'returns true' do
disable_feature
create_rule(users: [create(:user)], approvals_required: 1)
expect(subject.approved?).to eq(true)
end
end
end
describe '#any_approver_allowed?' do
......@@ -261,6 +291,14 @@ describe ApprovalState do
it 'sums approvals_left from rules' do
expect(subject.approvals_left).to eq(12)
end
context 'when approval feature is unavailable' do
it 'returns 0' do
disable_feature
expect(subject.approvals_left).to eq(0)
end
end
end
describe '#approval_rules_left' do
......@@ -268,12 +306,21 @@ describe ApprovalState do
create_rule(approvals_required: 1, users: [create(:user)])
end
it 'counts approval_rules left' do
create_unapproved_rule
create_unapproved_rule
before do
2.times { create_unapproved_rule }
end
it 'counts approval_rules left' do
expect(subject.approval_rules_left.size).to eq(2)
end
context 'when approval feature is unavailable' do
it 'returns empty array' do
disable_feature
expect(subject.approval_rules_left).to eq([])
end
end
end
describe '#approvers' 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