Commit 62362ba9 authored by Luke Duncalfe's avatar Luke Duncalfe

Refactor ApprovalState spec with shared example

Applying a shared_examples_group to DRY up the test.

Some of the tests would test

  expect(subject.can_approve?(nil)).to be_falsey

and some would miss that. So this change makes them all consistent.
parent 4e6a4d3d
......@@ -83,6 +83,13 @@ describe ApprovalState do
end
end
shared_examples_for 'a MR that all members with write access can approve' do
it { expect(subject.can_approve?(developer)).to be_truthy }
it { expect(subject.can_approve?(reporter)).to be_falsey }
it { expect(subject.can_approve?(stranger)).to be_falsey }
it { expect(subject.can_approve?(nil)).to be_falsey }
end
context '#approval_rules_overwritten?' do
context 'when approval rule on the merge request does not exist' do
it 'returns false' do
......@@ -461,17 +468,12 @@ describe ApprovalState do
it_behaves_like 'authors self-approval authorization'
it_behaves_like 'a MR that all members with write access can approve'
it 'requires one approval' do
expect(subject.approvals_left).to eq(1)
end
it 'allows any other project member with write access to approve the MR' do
expect(subject.can_approve?(developer)).to be_truthy
expect(subject.can_approve?(reporter)).to be_falsey
expect(subject.can_approve?(stranger)).to be_falsey
end
it 'does not allow a logged-out user to approve the MR' do
expect(subject.can_approve?(nil)).to be_falsey
end
......@@ -526,6 +528,8 @@ describe ApprovalState do
create(:approval, user: approver2, merge_request: merge_request)
end
it_behaves_like 'a MR that all members with write access can approve'
it 'requires the original number of approvals' do
expect(subject.approvals_left).to eq(1)
end
......@@ -538,14 +542,6 @@ describe ApprovalState do
expect(subject.can_approve?(approver)).to be_falsey
expect(subject.can_approve?(approver2)).to be_falsey
end
it 'allows any other project member with write access to approve the MR' do
expect(subject.can_approve?(developer)).to be_truthy
expect(subject.can_approve?(reporter)).to be_falsey
expect(subject.can_approve?(stranger)).to be_falsey
expect(subject.can_approve?(nil)).to be_falsey
end
end
context 'when self-approval is enabled and all of the valid approvers have approved the MR' do
......@@ -1031,17 +1027,12 @@ describe ApprovalState do
it_behaves_like 'authors self-approval authorization'
it_behaves_like 'a MR that all members with write access can approve'
it 'requires one approval' do
expect(subject.approvals_left).to eq(1)
end
it 'allows any other project member with write access to approve the MR' do
expect(subject.can_approve?(developer)).to be_truthy
expect(subject.can_approve?(reporter)).to be_falsey
expect(subject.can_approve?(stranger)).to be_falsey
end
it 'does not allow a logged-out user to approve the MR' do
expect(subject.can_approve?(nil)).to be_falsey
end
......@@ -1096,6 +1087,8 @@ describe ApprovalState do
create(:approval, user: approver2, merge_request: merge_request)
end
it_behaves_like 'a MR that all members with write access can approve'
it 'requires the original number of approvals' do
expect(subject.approvals_left).to eq(1)
end
......@@ -1108,14 +1101,6 @@ describe ApprovalState do
expect(subject.can_approve?(approver)).to be_falsey
expect(subject.can_approve?(approver2)).to be_falsey
end
it 'allows any other project member with write access to approve the MR' do
expect(subject.can_approve?(developer)).to be_truthy
expect(subject.can_approve?(reporter)).to be_falsey
expect(subject.can_approve?(stranger)).to be_falsey
expect(subject.can_approve?(nil)).to be_falsey
end
end
context 'when self-approval is enabled and all of the valid approvers have approved the MR' 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