Commit 42be0ec7 authored by Dallas Reedy's avatar Dallas Reedy

Fix ApplicationExperiment#publish_to_database functionality

The expectation is that we can either call `record!` on an experiment to
have it automatically run `publish_to_database` as part of the normal
`publish` flow or we can explicitly call `publish_to_database` ourselves
to get the same behavior (without needing to first call `record!`).

This was broken by https://gitlab.com/gitlab-org/gitlab/-/merge_requests/67366
parent bfd7e162
...@@ -13,7 +13,7 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp ...@@ -13,7 +13,7 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
super super
publish_to_client publish_to_client
publish_to_database publish_to_database if @record
end end
def publish_to_client def publish_to_client
...@@ -25,7 +25,6 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp ...@@ -25,7 +25,6 @@ class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/Namesp
end end
def publish_to_database def publish_to_database
return unless @record
return unless should_track? return unless should_track?
# if the context contains a namespace, group, project, user, or actor # if the context contains a namespace, group, project, user, or actor
......
...@@ -80,6 +80,8 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -80,6 +80,8 @@ RSpec.describe ApplicationExperiment, :experiment do
end end
it "publishes to the database if we've opted for that" do it "publishes to the database if we've opted for that" do
subject.record!
expect(subject).to receive(:publish_to_database) expect(subject).to receive(:publish_to_database)
subject.publish subject.publish
...@@ -121,6 +123,8 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -121,6 +123,8 @@ RSpec.describe ApplicationExperiment, :experiment do
end end
describe '#publish_to_database' do describe '#publish_to_database' do
using RSpec::Parameterized::TableSyntax
shared_examples 'does not record to the database' do shared_examples 'does not record to the database' do
it 'does not create an experiment record' do it 'does not create an experiment record' do
expect { subject.publish_to_database }.not_to change(Experiment, :count) expect { subject.publish_to_database }.not_to change(Experiment, :count)
...@@ -131,13 +135,6 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -131,13 +135,6 @@ RSpec.describe ApplicationExperiment, :experiment do
end end
end end
context 'when we explicitly request to record' do
using RSpec::Parameterized::TableSyntax
before do
subject.record!
end
context 'when there is a usable subject' do context 'when there is a usable subject' do
let(:context) { { context_key => context_value } } let(:context) { { context_key => context_value } }
...@@ -178,11 +175,6 @@ RSpec.describe ApplicationExperiment, :experiment do ...@@ -178,11 +175,6 @@ RSpec.describe ApplicationExperiment, :experiment do
include_examples 'does not record to the database' include_examples 'does not record to the database'
end end
end end
context 'when we have not explicitly requested to record' do
include_examples 'does not record to the database'
end
end
end end
describe "#track", :snowplow do describe "#track", :snowplow do
......
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