2020-01-28 19:08:58 -05:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe MergeRequestAssignee do
|
2021-12-02 04:10:59 -05:00
|
|
|
let(:assignee) { create(:user) }
|
2020-01-28 19:08:58 -05:00
|
|
|
let(:merge_request) { create(:merge_request) }
|
|
|
|
|
2021-12-02 04:10:59 -05:00
|
|
|
subject { merge_request.merge_request_assignees.build(assignee: assignee) }
|
2020-01-28 19:08:58 -05:00
|
|
|
|
|
|
|
describe 'associations' do
|
|
|
|
it { is_expected.to belong_to(:merge_request).class_name('MergeRequest') }
|
|
|
|
it { is_expected.to belong_to(:assignee).class_name('User') }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'validations' do
|
|
|
|
it { is_expected.to validate_uniqueness_of(:assignee).scoped_to(:merge_request_id) }
|
|
|
|
end
|
2020-06-23 11:08:41 -04:00
|
|
|
|
|
|
|
describe 'scopes' do
|
|
|
|
let_it_be(:user) { create(:user) }
|
|
|
|
let_it_be(:project) { create(:project, :repository) }
|
|
|
|
let_it_be(:project_merge_request) { create(:merge_request, target_project: project, source_project: project, assignee_ids: [user.id]) }
|
|
|
|
|
|
|
|
before do
|
|
|
|
merge_request.update!(assignee_ids: [user.id])
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'in_projects' do
|
|
|
|
it 'returns issue assignees for given project' do
|
|
|
|
expect(MergeRequestAssignee.count).to eq 2
|
|
|
|
|
|
|
|
assignees = MergeRequestAssignee.in_projects([project])
|
|
|
|
|
|
|
|
expect(assignees.count).to eq 1
|
|
|
|
expect(assignees.first.user_id).to eq project_merge_request.merge_request_assignees.first.user_id
|
|
|
|
expect(assignees.first.merge_request_id).to eq project_merge_request.merge_request_assignees.first.merge_request_id
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2021-10-25 05:12:21 -04:00
|
|
|
|
|
|
|
it_behaves_like 'having unique enum values'
|
2021-11-03 02:10:20 -04:00
|
|
|
|
2022-02-23 01:18:49 -05:00
|
|
|
describe '#attention_requested_by' do
|
|
|
|
let(:current_user) { create(:user) }
|
|
|
|
|
|
|
|
before do
|
2022-05-05 17:09:10 -04:00
|
|
|
subject.update!(updated_state_by: current_user, state: :attention_requested)
|
2022-02-23 01:18:49 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
context 'attention requested' do
|
|
|
|
it { expect(subject.attention_requested_by).to eq(current_user) }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'attention requested' do
|
|
|
|
before do
|
|
|
|
subject.update!(state: :reviewed)
|
|
|
|
end
|
|
|
|
|
|
|
|
it { expect(subject.attention_requested_by).to eq(nil) }
|
|
|
|
end
|
|
|
|
end
|
2020-01-28 19:08:58 -05:00
|
|
|
end
|