Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/experiments/new_project_readme_experiment_spec.rb')
-rw-r--r--spec/experiments/new_project_readme_experiment_spec.rb93
1 files changed, 93 insertions, 0 deletions
diff --git a/spec/experiments/new_project_readme_experiment_spec.rb b/spec/experiments/new_project_readme_experiment_spec.rb
new file mode 100644
index 00000000000..17e28cf6e7f
--- /dev/null
+++ b/spec/experiments/new_project_readme_experiment_spec.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe NewProjectReadmeExperiment, :experiment do
+ subject { described_class.new(actor: actor) }
+
+ let(:actor) { User.new(id: 42, created_at: Time.current) }
+
+ before do
+ stub_experiments(new_project_readme: :control)
+ end
+
+ describe "exclusions" do
+ let(:threshold) { described_class::MAX_ACCOUNT_AGE }
+
+ it { is_expected.to exclude(actor: User.new(created_at: (threshold + 1.minute).ago)) }
+ it { is_expected.not_to exclude(actor: User.new(created_at: (threshold - 1.minute).ago)) }
+ end
+
+ describe "the control behavior" do
+ subject { described_class.new(actor: actor).run(:control) }
+
+ it { is_expected.to be false }
+ end
+
+ describe "the candidate behavior" do
+ subject { described_class.new(actor: actor).run(:candidate) }
+
+ it { is_expected.to be true }
+ end
+
+ context "when tracking initial writes" do
+ let!(:project) { create(:project, :repository) }
+
+ def stub_gitaly_count(count = 1)
+ allow(Gitlab::GitalyClient).to receive(:call).and_call_original
+ allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
+ .and_return(double(count: count))
+ end
+
+ before do
+ stub_gitaly_count
+ end
+
+ it "tracks an event for the first commit on a project with a repository" do
+ expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 1).and_call_original
+
+ subject.track_initial_writes(project)
+ end
+
+ it "tracks an event for the second commit on a project with a repository" do
+ stub_gitaly_count(2)
+
+ expect(subject).to receive(:track).with(:write, property: project.created_at.to_s, value: 2).and_call_original
+
+ subject.track_initial_writes(project)
+ end
+
+ it "doesn't track if the repository has more then 2 commits" do
+ stub_gitaly_count(3)
+
+ expect(subject).not_to receive(:track)
+
+ subject.track_initial_writes(project)
+ end
+
+ it "doesn't track when we generally shouldn't" do
+ allow(subject).to receive(:should_track?).and_return(false)
+
+ expect(subject).not_to receive(:track)
+
+ subject.track_initial_writes(project)
+ end
+
+ it "doesn't track if the project is older" do
+ expect(project).to receive(:created_at).and_return(described_class::EXPERIMENT_START_DATE - 1.minute)
+
+ expect(subject).not_to receive(:track)
+
+ subject.track_initial_writes(project)
+ end
+
+ it "handles exceptions by logging them" do
+ allow(Gitlab::GitalyClient).to receive(:call).with(anything, :commit_service, :count_commits, anything, anything)
+ .and_raise(e = StandardError.new('_message_'))
+
+ expect(Gitlab::ErrorTracking).to receive(:track_exception).with(e, experiment: 'new_project_readme')
+
+ subject.track_initial_writes(project)
+ end
+ end
+end