2020-07-15 14:09:09 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
|
|
|
RSpec.describe ApprovableBase do
|
2020-07-20 14:09:27 -04:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
let(:user) { create(:user) }
|
2020-07-15 14:09:09 -04:00
|
|
|
|
2020-07-20 14:09:27 -04:00
|
|
|
describe '#approved_by?' do
|
2020-07-16 11:09:38 -04:00
|
|
|
subject { merge_request.approved_by?(user) }
|
2020-07-15 14:09:09 -04:00
|
|
|
|
|
|
|
context 'when a user has not approved' do
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user has approved' do
|
|
|
|
let!(:approval) { create(:approval, merge_request: merge_request, user: user) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user is nil' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-07-20 14:09:27 -04:00
|
|
|
|
|
|
|
describe '#can_be_approved_by?' do
|
|
|
|
subject { merge_request.can_be_approved_by?(user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
merge_request.project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user has approved' do
|
|
|
|
let!(:approval) { create(:approval, merge_request: merge_request, user: user) }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
2021-09-03 14:10:36 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user is nil' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '#can_be_unapproved_by?' do
|
|
|
|
subject { merge_request.can_be_unapproved_by?(user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
merge_request.project.add_developer(user)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user has approved' do
|
|
|
|
let!(:approval) { create(:approval, merge_request: merge_request, user: user) }
|
|
|
|
|
|
|
|
it 'returns true' do
|
|
|
|
is_expected.to be_truthy
|
|
|
|
end
|
2020-07-20 14:09:27 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'when a user is nil' do
|
|
|
|
let(:user) { nil }
|
|
|
|
|
|
|
|
it 'returns false' do
|
|
|
|
is_expected.to be_falsy
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-07-01 05:07:33 -04:00
|
|
|
|
|
|
|
describe '.not_approved_by_users_with_usernames' do
|
|
|
|
subject { MergeRequest.not_approved_by_users_with_usernames([user.username, user2.username]) }
|
|
|
|
|
|
|
|
let!(:merge_request2) { create(:merge_request) }
|
|
|
|
let!(:merge_request3) { create(:merge_request) }
|
|
|
|
let!(:merge_request4) { create(:merge_request) }
|
|
|
|
let(:user2) { create(:user) }
|
|
|
|
let(:user3) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
create(:approval, merge_request: merge_request, user: user)
|
|
|
|
create(:approval, merge_request: merge_request2, user: user2)
|
|
|
|
create(:approval, merge_request: merge_request2, user: user3)
|
|
|
|
create(:approval, merge_request: merge_request4, user: user3)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'has the merge request that is not approved at all and not approved by either user' do
|
|
|
|
expect(subject).to contain_exactly(merge_request3, merge_request4)
|
|
|
|
end
|
|
|
|
end
|
2020-07-15 14:09:09 -04:00
|
|
|
end
|