debian-mirror-gitlab/spec/models/concerns/approvable_spec.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
2.7 KiB
Ruby
Raw Normal View History

2020-07-28 23:09:34 +05:30
# frozen_string_literal: true
require 'spec_helper'
2022-10-11 01:57:18 +05:30
RSpec.describe Approvable do
2020-07-28 23:09:34 +05:30
let(:merge_request) { create(:merge_request) }
let(:user) { create(:user) }
describe '#approved_by?' do
subject { merge_request.approved_by?(user) }
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
2022-11-25 23:54:43 +05:30
describe '#eligible_for_approval_by?' do
subject { merge_request.eligible_for_approval_by?(user) }
2020-07-28 23:09:34 +05:30
before do
2022-06-21 17:19:12 +05:30
merge_request.project.add_developer(user) if user
2020-07-28 23:09:34 +05:30
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-11-11 11:23:49 +05:30
end
context 'when a user is nil' do
let(:user) { nil }
it 'returns false' do
is_expected.to be_falsy
end
end
end
2022-11-25 23:54:43 +05:30
describe '#eligible_for_unapproval_by?' do
subject { merge_request.eligible_for_unapproval_by?(user) }
2021-11-11 11:23:49 +05:30
before do
2022-06-21 17:19:12 +05:30
merge_request.project.add_developer(user) if user
2021-11-11 11:23:49 +05:30
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-28 23:09:34 +05:30
end
context 'when a user is nil' do
let(:user) { nil }
it 'returns false' do
is_expected.to be_falsy
end
end
end
2021-09-30 23:02:18 +05:30
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-28 23:09:34 +05:30
end