summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/lib
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/lib')
-rw-r--r--spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb8
-rw-r--r--spec/support/shared_examples/lib/gitlab/usage_data_counters/code_review_extension_request_examples.rb47
-rw-r--r--spec/support/shared_examples/lib/sidebars/projects/menus/zentao_menu_shared_examples.rb2
3 files changed, 53 insertions, 4 deletions
diff --git a/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb
index 5baa6478225..fdca326dbea 100644
--- a/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb
+++ b/spec/support/shared_examples/lib/gitlab/experimentation_shared_examples.rb
@@ -1,6 +1,10 @@
# frozen_string_literal: true
RSpec.shared_examples 'tracks assignment and records the subject' do |experiment, subject_type|
+ before do
+ stub_experiments(experiment => true)
+ end
+
it 'tracks the assignment', :experiment do
expect(experiment(experiment))
.to track(:assignment)
@@ -11,9 +15,7 @@ RSpec.shared_examples 'tracks assignment and records the subject' do |experiment
end
it 'records the subject' do
- stub_experiments(experiment => :candidate)
-
- expect(Experiment).to receive(:add_subject).with(experiment.to_s, variant: :experimental, subject: subject)
+ expect(Experiment).to receive(:add_subject).with(experiment.to_s, variant: anything, subject: subject)
action
end
diff --git a/spec/support/shared_examples/lib/gitlab/usage_data_counters/code_review_extension_request_examples.rb b/spec/support/shared_examples/lib/gitlab/usage_data_counters/code_review_extension_request_examples.rb
new file mode 100644
index 00000000000..6221366ab51
--- /dev/null
+++ b/spec/support/shared_examples/lib/gitlab/usage_data_counters/code_review_extension_request_examples.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.shared_examples 'a request from an extension' do |event|
+ before do
+ stub_application_setting(usage_ping_enabled: true)
+ end
+
+ def count_unique(date_from:, date_to:)
+ Gitlab::UsageDataCounters::HLLRedisCounter.unique_events(event_names: action, start_date: date_from, end_date: date_to)
+ end
+
+ def track_action(params)
+ described_class.track_api_request_when_trackable(**params)
+ end
+
+ it 'tracks when the user agent is matching' do
+ aggregate_failures do
+ expect(track_action(user: user1, **user_agent)).to be_truthy
+ expect(track_action(user: user1, **user_agent)).to be_truthy
+ expect(track_action(user: user2, **user_agent)).to be_truthy
+
+ expect(count_unique(date_from: time - 1.week, date_to: time + 1.week)).to eq(2)
+ end
+ end
+
+ it 'does not track when the user agent is not matching' do
+ aggregate_failures do
+ user_agent = { user_agent: 'normal_user_agent' }
+
+ expect(track_action(user: user1, **user_agent)).to be_falsey
+ expect(track_action(user: user1, **user_agent)).to be_falsey
+ expect(track_action(user: user2, **user_agent)).to be_falsey
+
+ expect(count_unique(date_from: time - 1.week, date_to: time + 1.week)).to eq(0)
+ end
+ end
+
+ it 'does not track if user agent is not present' do
+ expect(track_action(user: nil, user_agent: nil)).to be_nil
+ end
+
+ it 'does not track if user is not present' do
+ expect(track_action(user: nil, **user_agent)).to be_nil
+ end
+end
diff --git a/spec/support/shared_examples/lib/sidebars/projects/menus/zentao_menu_shared_examples.rb b/spec/support/shared_examples/lib/sidebars/projects/menus/zentao_menu_shared_examples.rb
index d3fd28727b5..b4c438771ce 100644
--- a/spec/support/shared_examples/lib/sidebars/projects/menus/zentao_menu_shared_examples.rb
+++ b/spec/support/shared_examples/lib/sidebars/projects/menus/zentao_menu_shared_examples.rb
@@ -4,7 +4,7 @@ require 'spec_helper'
RSpec.shared_examples 'ZenTao menu with CE version' do
let(:project) { create(:project, has_external_issue_tracker: true) }
- let(:user) { project.owner }
+ let(:user) { project.first_owner }
let(:context) { Sidebars::Projects::Context.new(current_user: user, container: project) }
let(:zentao_integration) { create(:zentao_integration, project: project) }