summaryrefslogtreecommitdiff
path: root/spec/services/groups/create_service_spec.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-18 09:45:46 +0000
commita7b3560714b4d9cc4ab32dffcd1f74a284b93580 (patch)
tree7452bd5c3545c2fa67a28aa013835fb4fa071baf /spec/services/groups/create_service_spec.rb
parentee9173579ae56a3dbfe5afe9f9410c65bb327ca7 (diff)
downloadgitlab-ce-a7b3560714b4d9cc4ab32dffcd1f74a284b93580.tar.gz
Add latest changes from gitlab-org/gitlab@14-8-stable-eev14.8.0-rc42
Diffstat (limited to 'spec/services/groups/create_service_spec.rb')
-rw-r--r--spec/services/groups/create_service_spec.rb57
1 files changed, 57 insertions, 0 deletions
diff --git a/spec/services/groups/create_service_spec.rb b/spec/services/groups/create_service_spec.rb
index 81cab973b30..7ec523a1f2b 100644
--- a/spec/services/groups/create_service_spec.rb
+++ b/spec/services/groups/create_service_spec.rb
@@ -8,6 +8,10 @@ RSpec.describe Groups::CreateService, '#execute' do
subject { service.execute }
+ shared_examples 'has sync-ed traversal_ids' do
+ specify { expect(subject.reload.traversal_ids).to eq([subject.parent&.traversal_ids, subject.id].flatten.compact) }
+ end
+
describe 'visibility level restrictions' do
let!(:service) { described_class.new(user, group_params) }
@@ -77,6 +81,18 @@ RSpec.describe Groups::CreateService, '#execute' do
it 'adds an onboarding progress record' do
expect { subject }.to change(OnboardingProgress, :count).from(0).to(1)
end
+
+ context 'with before_commit callback' do
+ it_behaves_like 'has sync-ed traversal_ids'
+ end
+
+ context 'with after_create callback' do
+ before do
+ stub_feature_flags(sync_traversal_ids_before_commit: false)
+ end
+
+ it_behaves_like 'has sync-ed traversal_ids'
+ end
end
context 'when user can not create a group' do
@@ -102,6 +118,18 @@ RSpec.describe Groups::CreateService, '#execute' do
it 'does not add an onboarding progress record' do
expect { subject }.not_to change(OnboardingProgress, :count).from(0)
end
+
+ context 'with before_commit callback' do
+ it_behaves_like 'has sync-ed traversal_ids'
+ end
+
+ context 'with after_create callback' do
+ before do
+ stub_feature_flags(sync_traversal_ids_before_commit: false)
+ end
+
+ it_behaves_like 'has sync-ed traversal_ids'
+ end
end
context 'as guest' do
@@ -289,4 +317,33 @@ RSpec.describe Groups::CreateService, '#execute' do
end
end
end
+
+ describe 'logged_out_marketing_header experiment', :experiment do
+ let(:service) { described_class.new(user, group_params) }
+
+ subject { service.execute }
+
+ before do
+ stub_experiments(logged_out_marketing_header: :candidate)
+ end
+
+ it 'tracks signed_up event' do
+ expect(experiment(:logged_out_marketing_header)).to track(
+ :namespace_created,
+ namespace: an_instance_of(Group)
+ ).on_next_instance.with_context(actor: user)
+
+ subject
+ end
+
+ context 'when group has not been persisted' do
+ let(:service) { described_class.new(user, group_params.merge(name: '<script>alert("Attack!")</script>')) }
+
+ it 'does not track signed_up event' do
+ expect(experiment(:logged_out_marketing_header)).not_to track(:namespace_created)
+
+ subject
+ end
+ end
+ end
end