Commit 2784a285 authored by Doug Stull's avatar Doug Stull

Merge branch 'dreedy-fix-application_experiment-publish_to_database' into 'master'

Restore ApplicationExperiment#publish_to_database functionality

See merge request gitlab-org/gitlab!68389

Changelog: fixed
parents 1813a6a0 42be0ec7
......@@ -13,7 +13,7 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
super
publish_to_client
publish_to_database
publish_to_database if @record
end
def publish_to_client
......@@ -25,7 +25,6 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
end
def publish_to_database
return unless @record
return unless should_track?
# if the context contains a namespace, group, project, user, or actor
......
......@@ -80,6 +80,8 @@ RSpec.describe ApplicationExperiment, :experiment do
end
it "publishes to the database if we've opted for that" do
subject.record!
expect(subject).to receive(:publish_to_database)
subject.publish
......@@ -121,6 +123,8 @@ RSpec.describe ApplicationExperiment, :experiment do
end
describe '#publish_to_database' do
using RSpec::Parameterized::TableSyntax
shared_examples 'does not record to the database' do
it 'does not create an experiment record' do
expect { subject.publish_to_database }.not_to change(Experiment, :count)
......@@ -131,55 +135,43 @@ RSpec.describe ApplicationExperiment, :experiment do
end
end
context 'when we explicitly request to record' do
using RSpec::Parameterized::TableSyntax
context 'when there is a usable subject' do
let(:context) { { context_key => context_value } }
before do
subject.record!
where(:context_key, :context_value, :object_type) do
:namespace | build(:namespace) | :namespace
:group | build(:namespace) | :namespace
:project | build(:project) | :project
:user | build(:user) | :user
:actor | build(:user) | :user
end
context 'when there is a usable subject' do
let(:context) { { context_key => context_value } }
where(:context_key, :context_value, :object_type) do
:namespace | build(:namespace) | :namespace
:group | build(:namespace) | :namespace
:project | build(:project) | :project
:user | build(:user) | :user
:actor | build(:user) | :user
end
with_them do
it 'creates an experiment and experiment subject record' do
expect { subject.publish_to_database }.to change(Experiment, :count).by(1)
with_them do
it 'creates an experiment and experiment subject record' do
expect { subject.publish_to_database }.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
expect(Experiment.last.name).to eq('namespaced/stub')
expect(ExperimentSubject.last.send(object_type)).to eq(context[context_key])
end
end
end
context 'when there is not a usable subject' do
let(:context) { { context_key => context_value } }
where(:context_key, :context_value) do
:namespace | nil
:foo | :bar
end
context 'when there is not a usable subject' do
let(:context) { { context_key => context_value } }
with_them do
include_examples 'does not record to the database'
end
where(:context_key, :context_value) do
:namespace | nil
:foo | :bar
end
context 'but we should not track' do
let(:should_track) { false }
with_them do
include_examples 'does not record to the database'
end
end
context 'when we have not explicitly requested to record' do
context 'but we should not track' do
let(:should_track) { false }
include_examples 'does not record to the database'
end
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment