summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2019-10-24 21:06:26 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2019-10-24 21:06:26 +0000
commit46bfa73d93786bc2a832be7e42e2119712a0bafb (patch)
treeda48cc5babc92871cda768a980042aeb061c5ace /spec
parentc4edbefa458319a81e238f8f034d19f6ea6292ca (diff)
downloadgitlab-ce-46bfa73d93786bc2a832be7e42e2119712a0bafb.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/db/schema_spec.rb46
-rw-r--r--spec/frontend/tracking_spec.js5
-rw-r--r--spec/lib/gitlab/tracking_spec.rb7
-rw-r--r--spec/support/matchers/db_schema_matchers.rb32
-rw-r--r--spec/views/layouts/_head.html.haml_spec.rb22
5 files changed, 81 insertions, 31 deletions
diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb
index 53f4a261092..e4eddb87858 100644
--- a/spec/db/schema_spec.rb
+++ b/spec/db/schema_spec.rb
@@ -120,9 +120,55 @@ describe 'Database schema' do
end
end
+ # These pre-existing enums have limits > 2 bytes
+ IGNORED_LIMIT_ENUMS = {
+ 'Analytics::CycleAnalytics::GroupStage' => %w[start_event_identifier end_event_identifier],
+ 'Analytics::CycleAnalytics::ProjectStage' => %w[start_event_identifier end_event_identifier],
+ 'Ci::Bridge' => %w[failure_reason],
+ 'Ci::Build' => %w[failure_reason],
+ 'Ci::BuildMetadata' => %w[timeout_source],
+ 'Ci::BuildTraceChunk' => %w[data_store],
+ 'Ci::JobArtifact' => %w[file_type],
+ 'Ci::Pipeline' => %w[source config_source failure_reason],
+ 'Ci::Runner' => %w[access_level],
+ 'Ci::Stage' => %w[status],
+ 'Clusters::Applications::Ingress' => %w[ingress_type],
+ 'Clusters::Cluster' => %w[platform_type provider_type],
+ 'CommitStatus' => %w[failure_reason],
+ 'GenericCommitStatus' => %w[failure_reason],
+ 'Gitlab::DatabaseImporters::CommonMetrics::PrometheusMetric' => %w[group],
+ 'InternalId' => %w[usage],
+ 'List' => %w[list_type],
+ 'NotificationSetting' => %w[level],
+ 'Project' => %w[auto_cancel_pending_pipelines],
+ 'ProjectAutoDevops' => %w[deploy_strategy],
+ 'PrometheusMetric' => %w[group],
+ 'ResourceLabelEvent' => %w[action],
+ 'User' => %w[layout dashboard project_view],
+ 'UserCallout' => %w[feature_name],
+ 'PrometheusAlert' => %w[operator]
+ }.freeze
+
+ context 'for enums' do
+ ApplicationRecord.descendants.each do |model|
+ describe model do
+ let(:ignored_enums) { ignored_limit_enums(model.name) }
+ let(:enums) { model.defined_enums.keys - ignored_enums }
+
+ it 'uses smallint for enums' do
+ expect(model).to use_smallint_for_enums(enums)
+ end
+ end
+ end
+ end
+
private
def ignored_fk_columns(column)
IGNORED_FK_COLUMNS.fetch(column, [])
end
+
+ def ignored_limit_enums(model)
+ IGNORED_LIMIT_ENUMS.fetch(model, [])
+ end
end
diff --git a/spec/frontend/tracking_spec.js b/spec/frontend/tracking_spec.js
index d9cc7104139..964f8b8787e 100644
--- a/spec/frontend/tracking_spec.js
+++ b/spec/frontend/tracking_spec.js
@@ -11,7 +11,6 @@ describe('Tracking', () => {
namespace: '_namespace_',
hostname: 'app.gitfoo.com',
cookieDomain: '.gitfoo.com',
- userId: null,
};
snowplowSpy = jest.spyOn(window, 'snowplow');
});
@@ -35,7 +34,6 @@ describe('Tracking', () => {
contexts: { webPage: true },
formTracking: false,
linkClickTracking: false,
- userId: null,
});
});
@@ -43,18 +41,15 @@ describe('Tracking', () => {
initUserTracking();
expect(snowplowSpy).toHaveBeenCalledWith('enableActivityTracking', 30, 30);
expect(snowplowSpy).toHaveBeenCalledWith('trackPageView');
- expect(snowplowSpy).not.toHaveBeenCalledWith('setUserId');
expect(snowplowSpy).not.toHaveBeenCalledWith('enableFormTracking');
expect(snowplowSpy).not.toHaveBeenCalledWith('enableLinkClickTracking');
window.snowplowOptions = Object.assign({}, window.snowplowOptions, {
formTracking: true,
linkClickTracking: true,
- userId: '1',
});
initUserTracking();
- expect(snowplowSpy).toHaveBeenCalledWith('setUserId', '1');
expect(snowplowSpy).toHaveBeenCalledWith('enableFormTracking');
expect(snowplowSpy).toHaveBeenCalledWith('enableLinkClickTracking');
});
diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb
index 4615599be7e..3ceaf159b3f 100644
--- a/spec/lib/gitlab/tracking_spec.rb
+++ b/spec/lib/gitlab/tracking_spec.rb
@@ -19,11 +19,10 @@ describe Gitlab::Tracking do
cookieDomain: '.gitfoo.com',
appId: '_abc123_',
formTracking: true,
- linkClickTracking: true,
- userId: nil
+ linkClickTracking: true
}
- expect(subject.snowplow_options(nil, nil)).to match(expected_fields)
+ expect(subject.snowplow_options(nil)).to match(expected_fields)
end
it 'enables features using feature flags' do
@@ -37,7 +36,7 @@ describe Gitlab::Tracking do
linkClickTracking: false
}
- expect(subject.snowplow_options('_group_', nil)).to include(addition_feature_fields)
+ expect(subject.snowplow_options('_group_')).to include(addition_feature_fields)
end
end
diff --git a/spec/support/matchers/db_schema_matchers.rb b/spec/support/matchers/db_schema_matchers.rb
new file mode 100644
index 00000000000..55843b7bb49
--- /dev/null
+++ b/spec/support/matchers/db_schema_matchers.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+EXPECTED_SMALLINT_LIMIT = 2
+
+RSpec::Matchers.define :use_smallint_for_enums do |enums|
+ match do |actual|
+ @failing_enums = enums.select do |enum|
+ enum_type = actual.type_for_attribute(enum)
+ actual_limit = enum_type.send(:subtype).limit
+ actual_limit != EXPECTED_SMALLINT_LIMIT
+ end
+ @failing_enums.empty?
+ end
+
+ failure_message do
+ <<~FAILURE_MESSAGE
+ Expected #{actual.name} enums: #{failing_enums.join(', ')} to use the smallint type.
+
+ The smallint type is 2 bytes which is more than sufficient for an enum.
+ Using the smallint type would help us save space in the database.
+ To fix this, please add `limit: 2` in the migration file, for example:
+
+ def change
+ add_column :ci_job_artifacts, :file_format, :integer, limit: 2
+ end
+ FAILURE_MESSAGE
+ end
+
+ def failing_enums
+ @failing_enums ||= []
+ end
+end
diff --git a/spec/views/layouts/_head.html.haml_spec.rb b/spec/views/layouts/_head.html.haml_spec.rb
index 41e685f185a..f181e18e53d 100644
--- a/spec/views/layouts/_head.html.haml_spec.rb
+++ b/spec/views/layouts/_head.html.haml_spec.rb
@@ -92,28 +92,6 @@ describe 'layouts/_head' do
end
end
- context 'when pendo is enabled' do
- it 'adds a pendo initialization snippet with url', :aggregate_failures do
- allow(Gitlab::CurrentSettings).to receive(:pendo_enabled?).and_return(true)
- allow(Gitlab::CurrentSettings).to receive(:pendo_url).and_return('www.pen.do')
-
- render
-
- expect(rendered).to match('pendo.initialize')
- expect(rendered).to match('www.pen.do')
- end
- end
-
- context 'when pendo is not enabled' do
- it 'do not add pendo snippet' do
- allow(Gitlab::CurrentSettings).to receive(:pendo_enabled?).and_return(false)
-
- render
-
- expect(rendered).not_to match('pendo.initialize')
- end
- end
-
context 'when a Piwik config is set' do
let(:piwik_host) { 'piwik.example.com' }