diff options
Diffstat (limited to 'spec/services/groups')
-rw-r--r-- | spec/services/groups/create_service_spec.rb | 9 | ||||
-rw-r--r-- | spec/services/groups/destroy_service_spec.rb | 15 | ||||
-rw-r--r-- | spec/services/groups/merge_requests_count_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/groups/open_issues_count_service_spec.rb | 2 | ||||
-rw-r--r-- | spec/services/groups/transfer_service_spec.rb | 37 | ||||
-rw-r--r-- | spec/services/groups/update_service_spec.rb | 40 | ||||
-rw-r--r-- | spec/services/groups/update_statistics_service_spec.rb | 2 |
7 files changed, 100 insertions, 7 deletions
diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb index 6e074f451c4..0cfde9ef434 100644 --- a/spec/services/groups/create_service_spec.rb +++ b/spec/services/groups/create_service_spec.rb @@ -176,6 +176,15 @@ RSpec.describe Groups::CreateService, '#execute' do end end + describe 'creating a details record' do + let(:service) { described_class.new(user, group_params) } + + it 'create the details record connected to the group' do + group = subject + expect(group.namespace_details).to be_persisted + end + end + describe 'create service for the group' do let(:service) { described_class.new(user, group_params) } let(:created_group) { service.execute } diff --git a/spec/services/groups/destroy_service_spec.rb b/spec/services/groups/destroy_service_spec.rb index f43f64fdf89..0d699dd447b 100644 --- a/spec/services/groups/destroy_service_spec.rb +++ b/spec/services/groups/destroy_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Groups::DestroyService do let!(:group) { create(:group) } let!(:nested_group) { create(:group, parent: group) } let!(:project) { create(:project, :repository, :legacy_storage, namespace: group) } - let!(:notification_setting) { create(:notification_setting, source: group)} + let!(:notification_setting) { create(:notification_setting, source: group) } let(:gitlab_shell) { Gitlab::Shell.new } let(:remove_path) { group.path + "+#{group.id}+deleted" } @@ -74,6 +74,17 @@ RSpec.describe Groups::DestroyService do end end end + + context 'event store', :sidekiq_might_not_need_inline do + it 'publishes a GroupDeletedEvent' do + expect { destroy_group(group, user, async) } + .to publish_event(Groups::GroupDeletedEvent) + .with( + group_id: group.id, + root_namespace_id: group.root_ancestor.id + ) + end + end end describe 'asynchronous delete' do @@ -271,7 +282,7 @@ RSpec.describe Groups::DestroyService do end context 'the shared_with group is deleted' do - let!(:group2_subgroup) { create(:group, :private, parent: group2)} + let!(:group2_subgroup) { create(:group, :private, parent: group2) } let!(:group2_subgroup_project) { create(:project, :private, group: group2_subgroup) } it 'updates project authorizations so users of both groups lose access', :aggregate_failures do diff --git a/spec/services/groups/merge_requests_count_service_spec.rb b/spec/services/groups/merge_requests_count_service_spec.rb index 10c7ba5fca4..8bd350d6f0e 100644 --- a/spec/services/groups/merge_requests_count_service_spec.rb +++ b/spec/services/groups/merge_requests_count_service_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' RSpec.describe Groups::MergeRequestsCountService, :use_clean_rails_memory_store_caching do let_it_be(:user) { create(:user) } - let_it_be(:group) { create(:group, :public)} + let_it_be(:group) { create(:group, :public) } let_it_be(:project) { create(:project, :repository, namespace: group) } let_it_be(:merge_request) { create(:merge_request, source_project: project, target_project: project) } diff --git a/spec/services/groups/open_issues_count_service_spec.rb b/spec/services/groups/open_issues_count_service_spec.rb index fca09bfdebe..923caa6c150 100644 --- a/spec/services/groups/open_issues_count_service_spec.rb +++ b/spec/services/groups/open_issues_count_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Groups::OpenIssuesCountService, :use_clean_rails_memory_store_caching do - let_it_be(:group) { create(:group, :public)} + let_it_be(:group) { create(:group, :public) } let_it_be(:project) { create(:project, :public, namespace: group) } let_it_be(:user) { create(:user) } let_it_be(:issue) { create(:issue, :opened, project: project) } diff --git a/spec/services/groups/transfer_service_spec.rb b/spec/services/groups/transfer_service_spec.rb index fbcca215282..b543661e9a0 100644 --- a/spec/services/groups/transfer_service_spec.rb +++ b/spec/services/groups/transfer_service_spec.rb @@ -22,6 +22,18 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do let!(:group_member) { create(:group_member, :owner, group: group, user: user) } let(:transfer_service) { described_class.new(group, user) } + shared_examples 'publishes a GroupTransferedEvent' do + it do + expect { transfer_service.execute(target) } + .to publish_event(Groups::GroupTransferedEvent) + .with( + group_id: group.id, + old_root_namespace_id: group.root_ancestor.id, + new_root_namespace_id: target.root_ancestor.id + ) + end + end + context 'handling packages' do let_it_be(:group) { create(:group, :public) } let_it_be(:new_group) { create(:group, :public) } @@ -895,6 +907,10 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect { transfer_service.execute(root_group) } .not_to change { CustomerRelations::IssueContact.count } end + + it_behaves_like 'publishes a GroupTransferedEvent' do + let(:target) { root_group } + end end context 'moving down' do @@ -904,6 +920,10 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect { transfer_service.execute(another_subgroup) } .not_to change { CustomerRelations::IssueContact.count } end + + it_behaves_like 'publishes a GroupTransferedEvent' do + let(:target) { another_subgroup } + end end context 'moving sideways' do @@ -913,6 +933,10 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect { transfer_service.execute(another_subgroup) } .not_to change { CustomerRelations::IssueContact.count } end + + it_behaves_like 'publishes a GroupTransferedEvent' do + let(:target) { another_subgroup } + end end context 'moving to new root group' do @@ -932,6 +956,10 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect { transfer_service.execute(new_parent_group) } .not_to change { CustomerRelations::IssueContact.count } end + + it_behaves_like 'publishes a GroupTransferedEvent' do + let(:target) { new_parent_group } + end end context 'moving to a subgroup within a new root group' do @@ -953,6 +981,10 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect { transfer_service.execute(subgroup_in_new_parent_group) } .not_to change { CustomerRelations::IssueContact.count } end + + it_behaves_like 'publishes a GroupTransferedEvent' do + let(:target) { subgroup_in_new_parent_group } + end end context 'with permission on the subgroup' do @@ -965,6 +997,11 @@ RSpec.describe Groups::TransferService, :sidekiq_inline do expect(transfer_service.error).to eq("Transfer failed: Group contains contacts/organizations and you don't have enough permissions to move them to the new root group.") end + + it 'does not publish a GroupTransferedEvent' do + expect { transfer_service.execute(subgroup_in_new_parent_group) } + .not_to publish_event(Groups::GroupTransferedEvent) + end end end end diff --git a/spec/services/groups/update_service_spec.rb b/spec/services/groups/update_service_spec.rb index 856dd4a2567..5c87b9ac8bb 100644 --- a/spec/services/groups/update_service_spec.rb +++ b/spec/services/groups/update_service_spec.rb @@ -339,8 +339,44 @@ RSpec.describe Groups::UpdateService do end end + context 'EventStore' do + let(:service) { described_class.new(group, user, **params) } + let(:root_group) { create(:group, path: 'root') } + let(:group) do + create(:group, parent: root_group, path: 'old-path').tap { |g| g.add_owner(user) } + end + + context 'when changing a group path' do + let(:new_path) { SecureRandom.hex } + let(:params) { { path: new_path } } + + it 'publishes a GroupPathChangedEvent' do + old_path = group.full_path + + expect { service.execute } + .to publish_event(Groups::GroupPathChangedEvent) + .with( + group_id: group.id, + root_namespace_id: group.root_ancestor.id, + old_path: old_path, + new_path: "root/#{new_path}" + ) + end + end + + context 'when not changing a group path' do + let(:params) { { name: 'very-new-name' } } + + it 'does not publish a GroupPathChangedEvent' do + expect { service.execute } + .not_to publish_event(Groups::GroupPathChangedEvent) + end + end + end + context 'rename group' do - let!(:service) { described_class.new(internal_group, user, path: SecureRandom.hex) } + let(:new_path) { SecureRandom.hex } + let!(:service) { described_class.new(internal_group, user, path: new_path) } before do internal_group.add_member(user, Gitlab::Access::MAINTAINER) @@ -371,7 +407,7 @@ RSpec.describe Groups::UpdateService do end it "hasn't changed the path" do - expect { service.execute}.not_to change { internal_group.reload.path} + expect { service.execute }.not_to change { internal_group.reload.path } end end end diff --git a/spec/services/groups/update_statistics_service_spec.rb b/spec/services/groups/update_statistics_service_spec.rb index 5bef51c2727..84b18b670a7 100644 --- a/spec/services/groups/update_statistics_service_spec.rb +++ b/spec/services/groups/update_statistics_service_spec.rb @@ -7,7 +7,7 @@ RSpec.describe Groups::UpdateStatisticsService do let(:statistics) { %w(wiki_size) } - subject(:service) { described_class.new(group, statistics: statistics)} + subject(:service) { described_class.new(group, statistics: statistics) } describe '#execute', :aggregate_failures do context 'when group is nil' do |