summaryrefslogtreecommitdiff
path: root/spec/experiments
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-06-16 18:25:58 +0000
commita5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch)
treefb69158581673816a8cd895f9d352dcb3c678b1e /spec/experiments
parentd16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff)
downloadgitlab-ce-a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4.tar.gz
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/experiments')
-rw-r--r--spec/experiments/application_experiment_spec.rb65
-rw-r--r--spec/experiments/members/invite_email_experiment_spec.rb10
2 files changed, 66 insertions, 9 deletions
diff --git a/spec/experiments/application_experiment_spec.rb b/spec/experiments/application_experiment_spec.rb
index 2ff16604c33..22c436e4159 100644
--- a/spec/experiments/application_experiment_spec.rb
+++ b/spec/experiments/application_experiment_spec.rb
@@ -64,8 +64,12 @@ RSpec.describe ApplicationExperiment, :experiment do
end
describe "publishing results" do
- it "doesn't track or push data to the client if we shouldn't track", :snowplow do
+ it "doesn't record, track or push data to the client if we shouldn't track", :snowplow do
allow(subject).to receive(:should_track?).and_return(false)
+ subject.record!
+
+ expect(subject).not_to receive(:record_experiment)
+ expect(subject).not_to receive(:track)
expect(Gon).not_to receive(:push)
subject.publish(:action)
@@ -73,6 +77,22 @@ RSpec.describe ApplicationExperiment, :experiment do
expect_no_snowplow_event
end
+ describe 'recording the experiment' do
+ it 'does not record the experiment if we do not tell it to' do
+ expect(subject).not_to receive(:record_experiment)
+
+ subject.publish
+ end
+
+ it 'records the experiment if we tell it to' do
+ subject.record!
+
+ expect(subject).to receive(:record_experiment)
+
+ subject.publish
+ end
+ end
+
it "tracks the assignment" do
expect(subject).to receive(:track).with(:assignment)
@@ -96,6 +116,49 @@ RSpec.describe ApplicationExperiment, :experiment do
expect(described_class.new('namespaced/stub') { |e| e.exclude! }).to be_excluded
end
+ describe 'recording the experiment subject' do
+ using RSpec::Parameterized::TableSyntax
+
+ subject { described_class.new('namespaced/stub', nil, **context) }
+
+ before do
+ subject.record!
+ end
+
+ context 'when providing a compatible context' do
+ where(:context_key, :object_type) do
+ :namespace | :namespace
+ :group | :namespace
+ :project | :project
+ :user | :user
+ :actor | :user
+ end
+
+ with_them do
+ let(:context) { { context_key => build(object_type) }}
+
+ it 'records the experiment and the experiment subject from the context' do
+ expect { subject.publish }.to change(Experiment, :count).by(1)
+
+ expect(Experiment.last.name).to eq('namespaced/stub')
+ expect(ExperimentSubject.last.send(object_type)).to eq(context[context_key])
+ end
+ end
+ end
+
+ context 'when providing an incompatible or no context' do
+ where(context_hash: [{ foo: :bar }, {}])
+
+ with_them do
+ let(:context) { context_hash }
+
+ it 'does not record the experiment' do
+ expect { subject.publish }.not_to change(Experiment, :count)
+ end
+ end
+ end
+ end
+
describe "tracking events", :snowplow do
it "doesn't track if we shouldn't track" do
allow(subject).to receive(:should_track?).and_return(false)
diff --git a/spec/experiments/members/invite_email_experiment_spec.rb b/spec/experiments/members/invite_email_experiment_spec.rb
index ac4c05e3058..47ae6e529a1 100644
--- a/spec/experiments/members/invite_email_experiment_spec.rb
+++ b/spec/experiments/members/invite_email_experiment_spec.rb
@@ -39,20 +39,14 @@ RSpec.describe Members::InviteEmailExperiment, :clean_gitlab_redis_shared_state
allow(instance_1).to receive(:enabled?).and_return(true)
instance_2 = described_class.new('members/invite_email', **context)
allow(instance_2).to receive(:enabled?).and_return(true)
- instance_3 = described_class.new('members/invite_email', **context)
- allow(instance_3).to receive(:enabled?).and_return(true)
instance_1.try { }
- expect(instance_1.variant.name).to eq('permission_info')
+ expect(instance_1.variant.name).to eq('control')
instance_2.try { }
- expect(instance_2.variant.name).to eq('control')
-
- instance_3.try { }
-
- expect(instance_3.variant.name).to eq('avatar')
+ expect(instance_2.variant.name).to eq('activity')
end
end