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 ...@@ -83,6 +83,13 @@ describe ApprovalState do
end end
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 '#approval_rules_overwritten?' do
context 'when approval rule on the merge request does not exist' do context 'when approval rule on the merge request does not exist' do
it 'returns false' do it 'returns false' do
...@@ -461,17 +468,12 @@ describe ApprovalState do ...@@ -461,17 +468,12 @@ describe ApprovalState do
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 'requires one approval' do it 'requires one approval' do
expect(subject.approvals_left).to eq(1) expect(subject.approvals_left).to eq(1)
end 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 it 'does not allow a logged-out user to approve the MR' do
expect(subject.can_approve?(nil)).to be_falsey expect(subject.can_approve?(nil)).to be_falsey
end end
...@@ -526,6 +528,8 @@ describe ApprovalState do ...@@ -526,6 +528,8 @@ describe ApprovalState do
create(:approval, user: approver2, merge_request: merge_request) create(:approval, user: approver2, merge_request: merge_request)
end end
it_behaves_like 'a MR that all members with write access can approve'
it 'requires the original number of approvals' do it 'requires the original number of approvals' do
expect(subject.approvals_left).to eq(1) expect(subject.approvals_left).to eq(1)
end end
...@@ -538,14 +542,6 @@ describe ApprovalState do ...@@ -538,14 +542,6 @@ describe ApprovalState do
expect(subject.can_approve?(approver)).to be_falsey expect(subject.can_approve?(approver)).to be_falsey
expect(subject.can_approve?(approver2)).to be_falsey expect(subject.can_approve?(approver2)).to be_falsey
end 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 end
context 'when self-approval is enabled and all of the valid approvers have approved the MR' do context 'when self-approval is enabled and all of the valid approvers have approved the MR' do
...@@ -1031,17 +1027,12 @@ describe ApprovalState do ...@@ -1031,17 +1027,12 @@ describe ApprovalState do
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 'requires one approval' do it 'requires one approval' do
expect(subject.approvals_left).to eq(1) expect(subject.approvals_left).to eq(1)
end 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 it 'does not allow a logged-out user to approve the MR' do
expect(subject.can_approve?(nil)).to be_falsey expect(subject.can_approve?(nil)).to be_falsey
end end
...@@ -1096,6 +1087,8 @@ describe ApprovalState do ...@@ -1096,6 +1087,8 @@ describe ApprovalState do
create(:approval, user: approver2, merge_request: merge_request) create(:approval, user: approver2, merge_request: merge_request)
end end
it_behaves_like 'a MR that all members with write access can approve'
it 'requires the original number of approvals' do it 'requires the original number of approvals' do
expect(subject.approvals_left).to eq(1) expect(subject.approvals_left).to eq(1)
end end
...@@ -1108,14 +1101,6 @@ describe ApprovalState do ...@@ -1108,14 +1101,6 @@ describe ApprovalState do
expect(subject.can_approve?(approver)).to be_falsey expect(subject.can_approve?(approver)).to be_falsey
expect(subject.can_approve?(approver2)).to be_falsey expect(subject.can_approve?(approver2)).to be_falsey
end 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 end
context 'when self-approval is enabled and all of the valid approvers have approved the MR' do 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