debian-mirror-gitlab/spec/services/projects/group_links/destroy_service_spec.rb

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

87 lines
2.8 KiB
Ruby
Raw Normal View History

2019-07-31 22:56:46 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe Projects::GroupLinks::DestroyService, '#execute' do
2020-06-23 00:09:42 +05:30
let_it_be(:user) { create :user }
let_it_be(:project) { create(:project, :private) }
let_it_be(:group) { create(:group) }
2021-09-30 23:02:18 +05:30
2020-06-23 00:09:42 +05:30
let!(:group_link) { create(:project_group_link, project: project, group: group) }
subject { described_class.new(project, user) }
2018-03-17 18:26:18 +05:30
it 'removes group from project' do
expect { subject.execute(group_link) }.to change { project.project_group_links.count }.from(1).to(0)
end
2021-09-04 01:27:46 +05:30
context 'project authorizations refresh' do
before do
group.add_maintainer(user)
end
2020-06-23 00:09:42 +05:30
2021-11-11 11:23:49 +05:30
it 'calls AuthorizedProjectUpdate::ProjectRecalculateWorker to update project authorizations' do
expect(AuthorizedProjectUpdate::ProjectRecalculateWorker)
.to receive(:perform_async).with(group_link.project.id)
2021-09-04 01:27:46 +05:30
2021-11-11 11:23:49 +05:30
subject.execute(group_link)
2021-09-04 01:27:46 +05:30
end
2021-11-11 11:23:49 +05:30
it 'calls AuthorizedProjectUpdate::UserRefreshFromReplicaWorker with a delay to update project authorizations' do
expect(AuthorizedProjectUpdate::UserRefreshFromReplicaWorker).to(
receive(:bulk_perform_in)
.with(1.hour,
[[user.id]],
batch_delay: 30.seconds, batch_size: 100)
)
2021-09-04 01:27:46 +05:30
2021-11-11 11:23:49 +05:30
subject.execute(group_link)
end
2021-09-04 01:27:46 +05:30
2021-11-11 11:23:49 +05:30
it 'updates project authorizations of users who had access to the project via the group share', :sidekiq_inline do
expect { subject.execute(group_link) }.to(
change { Ability.allowed?(user, :read_project, project) }
.from(true).to(false))
2021-09-04 01:27:46 +05:30
end
2020-06-23 00:09:42 +05:30
end
2018-03-17 18:26:18 +05:30
it 'returns false if group_link is blank' do
expect { subject.execute(nil) }.not_to change { project.project_group_links.count }
end
2020-02-01 01:16:34 +05:30
describe 'todos cleanup' do
context 'when project is private' do
it 'triggers todos cleanup' do
expect(TodosDestroyer::ProjectPrivateWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, project.id)
expect(project.private?).to be true
subject.execute(group_link)
end
end
context 'when project is public or internal' do
shared_examples_for 'removes confidential todos' do
it 'does not trigger todos cleanup' do
expect(TodosDestroyer::ProjectPrivateWorker).not_to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, project.id)
expect(TodosDestroyer::ConfidentialIssueWorker).to receive(:perform_in).with(Todo::WAIT_FOR_DELETE, nil, project.id)
expect(project.private?).to be false
subject.execute(group_link)
end
end
context 'when project is public' do
let(:project) { create(:project, :public) }
it_behaves_like 'removes confidential todos'
end
context 'when project is internal' do
let(:project) { create(:project, :public) }
it_behaves_like 'removes confidential todos'
end
end
end
2018-03-17 18:26:18 +05:30
end