diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-06 03:09:54 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-02-06 03:09:54 +0300 |
commit | b4d79e4b910389d348987dcd35c28d0162ea6480 (patch) | |
tree | f6be3cadac54c0c56a72f17068b89cdc818f0700 /spec | |
parent | 854956bd52cc724f53e3f37b7f9fb2b0aca82d61 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/controllers/projects_controller_spec.rb | 23 | ||||
-rw-r--r-- | spec/experiments/new_project_readme_experiment_spec.rb | 93 | ||||
-rw-r--r-- | spec/features/projects/user_creates_project_spec.rb | 6 | ||||
-rw-r--r-- | spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb | 16 | ||||
-rw-r--r-- | spec/services/merge_requests/update_service_spec.rb | 13 | ||||
-rw-r--r-- | spec/support/gitlab_experiment.rb | 2 | ||||
-rw-r--r-- | spec/workers/post_receive_spec.rb | 8 |
7 files changed, 160 insertions, 1 deletions
diff --git a/spec/controllers/projects_controller_spec.rb b/spec/controllers/projects_controller_spec.rb index a611ac16cd9..5f09e8a0747 100644 --- a/spec/controllers/projects_controller_spec.rb +++ b/spec/controllers/projects_controller_spec.rb @@ -384,6 +384,29 @@ RSpec.describe ProjectsController do end end + describe 'POST create' do + let!(:project_params) do + { + path: 'foo', + description: 'bar', + namespace_id: user.namespace.id, + visibility_level: Gitlab::VisibilityLevel::PUBLIC + } + end + + before do + sign_in(user) + end + + it 'tracks a created event for the new_project_readme experiment', :experiment do + expect(experiment(:new_project_readme)).to track(:created, property: 'blank').on_any_instance.with_context( + actor: user + ) + + post :create, params: { project: project_params } + end + end + describe 'POST #archive' do let_it_be(:group) { create(:group) } let_it_be(:project) { create(:project, group: group) } 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 diff --git a/spec/features/projects/user_creates_project_spec.rb b/spec/features/projects/user_creates_project_spec.rb index feb5f348256..aff3022bd4e 100644 --- a/spec/features/projects/user_creates_project_spec.rb +++ b/spec/features/projects/user_creates_project_spec.rb @@ -8,6 +8,8 @@ RSpec.describe 'User creates a project', :js do before do sign_in(user) create(:personal_key, user: user) + + stub_experiments(new_project_readme: :candidate) end it 'creates a new project' do @@ -16,6 +18,10 @@ RSpec.describe 'User creates a project', :js do find('[data-qa-selector="blank_project_link"]').click fill_in(:project_name, with: 'Empty') + # part of the new_project_readme experiment + expect(page).to have_checked_field 'Initialize repository with a README' + uncheck 'Initialize repository with a README' + page.within('#content-body') do click_button('Create project') end diff --git a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb index 509ba43ef32..f5fc2e71097 100644 --- a/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb +++ b/spec/lib/gitlab/usage_data_counters/merge_request_activity_unique_counter_spec.rb @@ -89,6 +89,22 @@ RSpec.describe Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter, :cl end end + describe '.track_title_edit_action' do + subject { described_class.track_title_edit_action(user: user) } + + it_behaves_like 'a tracked merge request unique event' do + let(:action) { described_class::MR_EDIT_MR_TITLE_ACTION } + end + end + + describe '.track_description_edit_action' do + subject { described_class.track_description_edit_action(user: user) } + + it_behaves_like 'a tracked merge request unique event' do + let(:action) { described_class::MR_EDIT_MR_DESC_ACTION } + end + end + describe '.track_create_comment_action' do subject { described_class.track_create_comment_action(note: note) } diff --git a/spec/services/merge_requests/update_service_spec.rb b/spec/services/merge_requests/update_service_spec.rb index a161379b5f1..6505bf85919 100644 --- a/spec/services/merge_requests/update_service_spec.rb +++ b/spec/services/merge_requests/update_service_spec.rb @@ -87,6 +87,19 @@ RSpec.describe MergeRequests::UpdateService, :mailer do expect(@merge_request.discussion_locked).to be_truthy end + context 'usage counters' do + let(:merge_request2) { create(:merge_request) } + + it 'update as expected' do + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_title_edit_action).once.with(user: user) + expect(Gitlab::UsageDataCounters::MergeRequestActivityUniqueCounter) + .to receive(:track_description_edit_action).once.with(user: user) + + MergeRequests::UpdateService.new(project, user, opts).execute(merge_request2) + end + end + context 'updating milestone' do RSpec.shared_examples 'updates milestone' do it 'sets milestone' do diff --git a/spec/support/gitlab_experiment.rb b/spec/support/gitlab_experiment.rb index 7844b85963d..2281c18eb2e 100644 --- a/spec/support/gitlab_experiment.rb +++ b/spec/support/gitlab_experiment.rb @@ -6,7 +6,7 @@ require 'gitlab/experiment/rspec' # This is a temporary fix until we have a larger discussion around the # challenges raised in https://gitlab.com/gitlab-org/gitlab/-/issues/300104 class ApplicationExperiment < Gitlab::Experiment # rubocop:disable Gitlab/NamespacedClass - def initialize(*args) + def initialize(name = nil, variant_name = nil, **context) super Feature.persist_used!(feature_flag_name) end diff --git a/spec/workers/post_receive_spec.rb b/spec/workers/post_receive_spec.rb index 5b8d8878a99..aaae0988602 100644 --- a/spec/workers/post_receive_spec.rb +++ b/spec/workers/post_receive_spec.rb @@ -85,6 +85,14 @@ RSpec.describe PostReceive do perform end + + it 'tracks an event for the new_project_readme experiment', :experiment do + expect_next_instance_of(NewProjectReadmeExperiment, :new_project_readme, nil, actor: empty_project.owner) do |e| + expect(e).to receive(:track_initial_writes).with(empty_project) + end + + perform + end end shared_examples 'not updating remote mirrors' do |