debian-mirror-gitlab/spec/models/users/merge_request_interaction_spec.rb

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

100 lines
2.6 KiB
Ruby
Raw Normal View History

2021-04-29 21:17:54 +05:30
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::Users::MergeRequestInteraction do
let_it_be(:user) { create(:user) }
let_it_be(:project) { create(:project, :public, :repository) }
let_it_be(:merge_request) { create(:merge_request, source_project: project) }
subject(:interaction) do
::Users::MergeRequestInteraction.new(user: user, merge_request: merge_request.reset)
end
describe 'declarative policy delegation' do
it 'delegates to the merge request' do
expect(subject.declarative_policy_subject).to eq(merge_request)
end
end
describe '#can_merge?' do
context 'when the user cannot merge' do
it { is_expected.not_to be_can_merge }
end
context 'when the user can merge' do
before do
project.add_maintainer(user)
end
it { is_expected.to be_can_merge }
end
end
describe '#can_update?' do
context 'when the user cannot update the MR' do
it { is_expected.not_to be_can_update }
end
context 'when the user can update the MR' do
before do
project.add_developer(user)
end
it { is_expected.to be_can_update }
end
end
describe '#review_state' do
subject { interaction.review_state }
context 'when the user has not been asked to review the MR' do
it { is_expected.to be_nil }
it 'implies not reviewed' do
expect(interaction).not_to be_reviewed
end
end
context 'when the user has been asked to review the MR' do
before do
merge_request.reviewers << user
2022-07-16 23:28:13 +05:30
merge_request.find_reviewer(user).update!(state: :attention_requested)
2021-04-29 21:17:54 +05:30
end
2021-12-11 22:18:48 +05:30
it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['ATTENTION_REQUESTED'].value) }
2021-04-29 21:17:54 +05:30
it 'implies not reviewed' do
expect(interaction).not_to be_reviewed
end
end
context 'when the user has provided a review' do
before do
2021-12-11 22:18:48 +05:30
reviewer = merge_request.merge_request_reviewers.create!(reviewer: user)
reviewer.update!(state: MergeRequestReviewer.states['reviewed'])
2021-04-29 21:17:54 +05:30
end
it { is_expected.to eq(Types::MergeRequestReviewStateEnum.values['REVIEWED'].value) }
it 'implies reviewed' do
expect(interaction).to be_reviewed
end
end
end
describe '#approved?' do
context 'when the user has not approved the MR' do
it { is_expected.not_to be_approved }
end
context 'when the user has approved the MR' do
before do
merge_request.approved_by_users << user
end
it { is_expected.to be_approved }
end
end
end