2019-12-26 22:10:19 +05:30
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-07-28 23:09:34 +05:30
|
|
|
RSpec.describe Groups::GroupLinks::DestroyService, '#execute' do
|
2019-12-26 22:10:19 +05:30
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
let_it_be(:group) { create(:group, :private) }
|
|
|
|
let_it_be(:shared_group) { create(:group, :private) }
|
|
|
|
let_it_be(:project) { create(:project, group: shared_group) }
|
2020-06-23 00:09:42 +05:30
|
|
|
let_it_be(:owner) { create(:user) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
2020-06-23 00:09:42 +05:30
|
|
|
before do
|
|
|
|
group.add_developer(owner)
|
|
|
|
shared_group.add_owner(owner)
|
|
|
|
end
|
|
|
|
|
|
|
|
subject { described_class.new(shared_group, owner) }
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
context 'single link' do
|
|
|
|
let!(:link) { create(:group_group_link, shared_group: shared_group, shared_with_group: group) }
|
|
|
|
|
|
|
|
it 'destroys link' do
|
2020-06-23 00:09:42 +05:30
|
|
|
expect { subject.execute(link) }.to change { shared_group.shared_with_group_links.count }.from(1).to(0)
|
2019-12-26 22:10:19 +05:30
|
|
|
end
|
|
|
|
|
2021-09-30 23:02:18 +05:30
|
|
|
it 'revokes project authorization', :sidekiq_inline do
|
2019-12-26 22:10:19 +05:30
|
|
|
group.add_developer(user)
|
|
|
|
|
|
|
|
expect { subject.execute(link) }.to(
|
|
|
|
change { Ability.allowed?(user, :read_project, project) }.from(true).to(false))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'multiple links' do
|
|
|
|
let_it_be(:another_group) { create(:group, :private) }
|
|
|
|
let_it_be(:another_shared_group) { create(:group, :private) }
|
|
|
|
|
|
|
|
let!(:links) do
|
|
|
|
[
|
|
|
|
create(:group_group_link, shared_group: shared_group, shared_with_group: group),
|
|
|
|
create(:group_group_link, shared_group: shared_group, shared_with_group: another_group),
|
|
|
|
create(:group_group_link, shared_group: another_shared_group, shared_with_group: group),
|
|
|
|
create(:group_group_link, shared_group: another_shared_group, shared_with_group: another_group)
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'updates project authorization once per group' do
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(GroupGroupLink).to receive(:delete).and_call_original
|
2021-09-30 23:02:18 +05:30
|
|
|
expect(group).to receive(:refresh_members_authorized_projects).with(direct_members_only: true, blocking: false).once
|
|
|
|
expect(another_group).to receive(:refresh_members_authorized_projects).with(direct_members_only: true, blocking: false).once
|
2019-12-26 22:10:19 +05:30
|
|
|
|
|
|
|
subject.execute(links)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|