summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2020-08-21 06:10:27 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-21 06:10:27 +0000
commit3c63ea4631f629f83c7d35e65963ffc1acf83161 (patch)
tree8c907616211b88594dd828257ca2c8131a429225 /spec
parentf2eb66fef8aa8cebea25bc9e671a1f146514682f (diff)
downloadgitlab-ce-3c63ea4631f629f83c7d35e65963ffc1acf83161.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/features/projects/commit/mini_pipeline_graph_spec.rb2
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb1
-rw-r--r--spec/lib/product_analytics/tracker_spec.rb51
-rw-r--r--spec/models/environment_status_spec.rb20
-rw-r--r--spec/models/merge_request_spec.rb31
5 files changed, 81 insertions, 24 deletions
diff --git a/spec/features/projects/commit/mini_pipeline_graph_spec.rb b/spec/features/projects/commit/mini_pipeline_graph_spec.rb
index 7bd3bce85d5..cf9b86f16bb 100644
--- a/spec/features/projects/commit/mini_pipeline_graph_spec.rb
+++ b/spec/features/projects/commit/mini_pipeline_graph_spec.rb
@@ -26,8 +26,6 @@ RSpec.describe 'Mini Pipeline Graph in Commit View', :js do
build.run
visit project_commit_path(project, project.commit.id)
- wait_for_all_requests
-
expect(page).to have_selector('.mr-widget-pipeline-graph')
first('.mini-pipeline-graph-dropdown-toggle').click
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 589c11f79a7..d38635292a5 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -25,6 +25,7 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
it 'clears memoized values' do
values = %i(issue_minimum_id issue_maximum_id
+ project_minimum_id project_maximum_id
user_minimum_id user_maximum_id unique_visit_service
deployment_minimum_id deployment_maximum_id
approval_merge_request_rule_minimum_id
diff --git a/spec/lib/product_analytics/tracker_spec.rb b/spec/lib/product_analytics/tracker_spec.rb
index d5e85e6e1cd..0d0660235f1 100644
--- a/spec/lib/product_analytics/tracker_spec.rb
+++ b/spec/lib/product_analytics/tracker_spec.rb
@@ -1,8 +1,57 @@
# frozen_string_literal: true
-require "spec_helper"
+require 'spec_helper'
RSpec.describe ProductAnalytics::Tracker do
it { expect(described_class::URL).to eq('http://localhost/-/sp.js') }
it { expect(described_class::COLLECTOR_URL).to eq('localhost/-/collector') }
+
+ describe '.event' do
+ after do
+ described_class.clear_memoization(:snowplow)
+ end
+
+ context 'when usage ping is enabled' do
+ let(:tracker) { double }
+ let(:project_id) { 1 }
+
+ before do
+ stub_application_setting(usage_ping_enabled: true, self_monitoring_project_id: project_id)
+ end
+
+ it 'sends an event to Product Analytics snowplow collector' do
+ expect(SnowplowTracker::AsyncEmitter)
+ .to receive(:new)
+ .with(described_class::COLLECTOR_URL, { protocol: 'http' })
+ .and_return('_emitter_')
+
+ expect(SnowplowTracker::Tracker)
+ .to receive(:new)
+ .with('_emitter_', an_instance_of(SnowplowTracker::Subject), 'gl', project_id.to_s)
+ .and_return(tracker)
+
+ freeze_time do
+ expect(tracker)
+ .to receive(:track_struct_event)
+ .with('category', 'action', '_label_', '_property_', '_value_', nil, (Time.current.to_f * 1000).to_i)
+
+ described_class.event('category', 'action', label: '_label_', property: '_property_',
+ value: '_value_', context: nil)
+ end
+ end
+ end
+
+ context 'when usage ping is disabled' do
+ before do
+ stub_application_setting(usage_ping_enabled: false)
+ end
+
+ it 'does not send an event' do
+ expect(SnowplowTracker::Tracker).not_to receive(:new)
+
+ described_class.event('category', 'action', label: '_label_', property: '_property_',
+ value: '_value_', context: nil)
+ end
+ end
+ end
end
diff --git a/spec/models/environment_status_spec.rb b/spec/models/environment_status_spec.rb
index 7eefb8f714a..a6954fb5d56 100644
--- a/spec/models/environment_status_spec.rb
+++ b/spec/models/environment_status_spec.rb
@@ -90,22 +90,6 @@ RSpec.describe EnvironmentStatus do
end
end
- describe '.after_merge_request' do
- let(:admin) { create(:admin) }
- let(:pipeline) { create(:ci_pipeline, sha: sha) }
-
- before do
- merge_request.mark_as_merged!
- end
-
- it 'is based on merge_request.merge_commit_sha' do
- expect(merge_request).to receive(:merge_commit_sha)
- expect(merge_request).not_to receive(:diff_head_sha)
-
- described_class.after_merge_request(merge_request, admin)
- end
- end
-
describe '.for_deployed_merge_request' do
context 'when a merge request has no explicitly linked deployments' do
it 'returns the statuses based on the CI pipelines' do
@@ -191,7 +175,7 @@ RSpec.describe EnvironmentStatus do
let(:environment) { build.deployment.environment }
let(:user) { project.owner }
- context 'when environment is created on a forked project' do
+ context 'when environment is created on a forked project', :sidekiq_inline do
let(:project) { create(:project, :repository) }
let(:forked) { fork_project(project, user, repository: true) }
let(:sha) { forked.commit.sha }
@@ -205,7 +189,7 @@ RSpec.describe EnvironmentStatus do
head_pipeline: pipeline)
end
- it 'returns environment status', :sidekiq_might_not_need_inline do
+ it 'returns environment status' do
expect(subject.count).to eq(1)
expect(subject[0].environment).to eq(environment)
expect(subject[0].merge_request).to eq(merge_request)
diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb
index 6edef54b153..656a93cee62 100644
--- a/spec/models/merge_request_spec.rb
+++ b/spec/models/merge_request_spec.rb
@@ -1575,11 +1575,36 @@ RSpec.describe MergeRequest do
before do
subject.mark_as_merged!
- subject.update_attribute(:merge_commit_sha, pipeline.sha)
end
- it 'returns the post-merge pipeline' do
- expect(subject.merge_pipeline).to eq(pipeline)
+ context 'and there is a merge commit' do
+ before do
+ subject.update_attribute(:merge_commit_sha, pipeline.sha)
+ end
+
+ it 'returns the pipeline associated with that merge request' do
+ expect(subject.merge_pipeline).to eq(pipeline)
+ end
+ end
+
+ context 'and there is no merge commit, but there is a diff head' do
+ before do
+ allow(subject).to receive(:diff_head_sha).and_return(pipeline.sha)
+ end
+
+ it 'returns the pipeline associated with that merge request' do
+ expect(subject.merge_pipeline).to eq(pipeline)
+ end
+ end
+
+ context 'and there is no merge commit, but there is a squash commit' do
+ before do
+ subject.update_attribute(:squash_commit_sha, pipeline.sha)
+ end
+
+ it 'returns the pipeline associated with that merge request' do
+ expect(subject.merge_pipeline).to eq(pipeline)
+ end
end
end
end