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
path: root/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-02-28 21:14:03 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-28 21:14:03 +0300
commite804afddbf68cc6f306bc4aa9aaea88be774ebe4 (patch)
tree0ecb2ebf35e16b866b16da375920eb58f6353ef7 /spec
parent8188ca655a7437381491e565406869c747c1b40a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/application_controller_spec.rb1
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/system_hook.json24
-rw-r--r--spec/fixtures/api/schemas/public_api/v4/system_hooks.json9
-rw-r--r--spec/frontend/loading_icon_for_legacy_js_spec.js43
-rw-r--r--spec/lib/gitlab/json_cache_spec.rb86
-rw-r--r--spec/lib/gitlab/usage/metrics/instrumentations/cert_based_clusters_ff_metric_spec.rb21
-rw-r--r--spec/lib/gitlab/usage_data_spec.rb14
-rw-r--r--spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features_spec.rb28
-rw-r--r--spec/models/broadcast_message_spec.rb6
-rw-r--r--spec/models/concerns/mentionable_spec.rb1
-rw-r--r--spec/requests/api/system_hooks_spec.rb49
-rw-r--r--spec/support/helpers/sorting_helper.rb1
-rw-r--r--spec/tooling/danger/changelog_spec.rb467
-rw-r--r--spec/tooling/danger/project_helper_spec.rb23
-rw-r--r--spec/validators/array_members_validator_spec.rb1
-rw-r--r--spec/validators/color_validator_spec.rb1
-rw-r--r--spec/validators/cron_validator_spec.rb2
-rw-r--r--spec/validators/future_date_validator_spec.rb1
18 files changed, 245 insertions, 533 deletions
diff --git a/spec/controllers/application_controller_spec.rb b/spec/controllers/application_controller_spec.rb
index 004bea02580..d49d4947cd5 100644
--- a/spec/controllers/application_controller_spec.rb
+++ b/spec/controllers/application_controller_spec.rb
@@ -501,6 +501,7 @@ RSpec.describe ApplicationController do
describe '#append_info_to_payload' do
controller(described_class) do
attr_reader :last_payload
+
urgency :high, [:foo]
def index
diff --git a/spec/fixtures/api/schemas/public_api/v4/system_hook.json b/spec/fixtures/api/schemas/public_api/v4/system_hook.json
new file mode 100644
index 00000000000..f992bc8b809
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/system_hook.json
@@ -0,0 +1,24 @@
+{
+ "type": "object",
+ "required": [
+ "id",
+ "url",
+ "created_at",
+ "push_events",
+ "tag_push_events",
+ "merge_requests_events",
+ "repository_update_events",
+ "enable_ssl_verification"
+ ],
+ "properties": {
+ "id": { "type": "integer" },
+ "url": { "type": "string" },
+ "created_at": { "type": "string" },
+ "push_events": { "type": "boolean" },
+ "tag_push_events": { "type": "boolean" },
+ "merge_requests_events": { "type": "boolean" },
+ "repository_update_events": { "type": "boolean" },
+ "enable_ssl_verification": { "type": "boolean" }
+ },
+ "additionalProperties": false
+}
diff --git a/spec/fixtures/api/schemas/public_api/v4/system_hooks.json b/spec/fixtures/api/schemas/public_api/v4/system_hooks.json
new file mode 100644
index 00000000000..a56542a8b99
--- /dev/null
+++ b/spec/fixtures/api/schemas/public_api/v4/system_hooks.json
@@ -0,0 +1,9 @@
+{
+ "type": "array",
+ "items": {
+ "type": "object",
+ "properties" : {
+ "$ref": "./system_hook.json"
+ }
+ }
+}
diff --git a/spec/frontend/loading_icon_for_legacy_js_spec.js b/spec/frontend/loading_icon_for_legacy_js_spec.js
new file mode 100644
index 00000000000..46deee555ba
--- /dev/null
+++ b/spec/frontend/loading_icon_for_legacy_js_spec.js
@@ -0,0 +1,43 @@
+import { loadingIconForLegacyJS } from '~/loading_icon_for_legacy_js';
+
+describe('loadingIconForLegacyJS', () => {
+ it('sets the correct defaults', () => {
+ const el = loadingIconForLegacyJS();
+
+ expect(el.tagName).toBe('DIV');
+ expect(el.className).toBe('gl-spinner-container');
+ expect(el.querySelector('.gl-spinner-sm')).toEqual(expect.any(HTMLElement));
+ expect(el.querySelector('.gl-spinner-dark')).toEqual(expect.any(HTMLElement));
+ expect(el.querySelector('[aria-label="Loading"]')).toEqual(expect.any(HTMLElement));
+ expect(el.getAttribute('role')).toBe('status');
+ });
+
+ it('renders a span if inline = true', () => {
+ expect(loadingIconForLegacyJS({ inline: true }).tagName).toBe('SPAN');
+ });
+
+ it('can render a different size', () => {
+ const el = loadingIconForLegacyJS({ size: 'lg' });
+
+ expect(el.querySelector('.gl-spinner-lg')).toEqual(expect.any(HTMLElement));
+ });
+
+ it('can render a different color', () => {
+ const el = loadingIconForLegacyJS({ color: 'light' });
+
+ expect(el.querySelector('.gl-spinner-light')).toEqual(expect.any(HTMLElement));
+ });
+
+ it('can render a different aria-label', () => {
+ const el = loadingIconForLegacyJS({ label: 'Foo' });
+
+ expect(el.querySelector('[aria-label="Foo"]')).toEqual(expect.any(HTMLElement));
+ });
+
+ it('can render additional classes', () => {
+ const classes = ['foo', 'bar'];
+ const el = loadingIconForLegacyJS({ classes });
+
+ expect(el.classList).toContain(...classes);
+ });
+});
diff --git a/spec/lib/gitlab/json_cache_spec.rb b/spec/lib/gitlab/json_cache_spec.rb
index 7899d01b475..01c2120d9a6 100644
--- a/spec/lib/gitlab/json_cache_spec.rb
+++ b/spec/lib/gitlab/json_cache_spec.rb
@@ -8,7 +8,7 @@ RSpec.describe Gitlab::JsonCache do
let(:backend) { double('backend').as_null_object }
let(:namespace) { 'geo' }
let(:key) { 'foo' }
- let(:expanded_key) { "#{namespace}:#{key}:#{Gitlab::VERSION}:#{Rails.version}" }
+ let(:expanded_key) { "#{namespace}:#{key}:#{Gitlab.revision}" }
subject(:cache) { described_class.new(namespace: namespace, backend: backend) }
@@ -35,69 +35,63 @@ RSpec.describe Gitlab::JsonCache do
end
describe '#cache_key' do
- context 'when namespace is not defined' do
- context 'when cache_key_with_version is true' do
- it 'expands out the key with GitLab, and Rails versions' do
- cache = described_class.new(cache_key_with_version: true)
+ using RSpec::Parameterized::TableSyntax
- cache_key = cache.cache_key(key)
-
- expect(cache_key).to eq("#{key}:#{Gitlab::VERSION}:#{Rails.version}")
- end
- end
+ where(:namespace, :cache_key_strategy, :expanded_key) do
+ nil | :revision | "#{key}:#{Gitlab.revision}"
+ nil | :version | "#{key}:#{Gitlab::VERSION}:#{Rails.version}"
+ namespace | :revision | "#{namespace}:#{key}:#{Gitlab.revision}"
+ namespace | :version | "#{namespace}:#{key}:#{Gitlab::VERSION}:#{Rails.version}"
+ end
- context 'when cache_key_with_version is false' do
- it 'returns the key' do
- cache = described_class.new(namespace: nil, cache_key_with_version: false)
+ with_them do
+ let(:cache) { described_class.new(namespace: namespace, cache_key_strategy: cache_key_strategy) }
- cache_key = cache.cache_key(key)
+ subject { cache.cache_key(key) }
- expect(cache_key).to eq(key)
- end
- end
+ it { is_expected.to eq expanded_key }
end
- context 'when namespace is nil' do
- context 'when cache_key_with_version is true' do
- it 'expands out the key with GitLab, and Rails versions' do
- cache = described_class.new(cache_key_with_version: true)
-
- cache_key = cache.cache_key(key)
+ context 'when cache_key_strategy is unknown' do
+ let(:cache) { described_class.new(namespace: namespace, cache_key_strategy: 'unknown') }
- expect(cache_key).to eq("#{key}:#{Gitlab::VERSION}:#{Rails.version}")
- end
+ it 'raises KeyError' do
+ expect { cache.cache_key('key') }.to raise_error(KeyError)
end
+ end
+ end
- context 'when cache_key_with_version is false' do
- it 'returns the key' do
- cache = described_class.new(namespace: nil, cache_key_with_version: false)
+ describe '#namespace' do
+ it 'defaults to nil' do
+ cache = described_class.new
+ expect(cache.namespace).to be_nil
+ end
+ end
- cache_key = cache.cache_key(key)
+ describe '#strategy_key_component' do
+ subject { cache.strategy_key_component }
- expect(cache_key).to eq(key)
- end
- end
+ it 'defaults to Gitlab.revision' do
+ expect(described_class.new.strategy_key_component).to eq Gitlab.revision
end
- context 'when namespace is set' do
- context 'when cache_key_with_version is true' do
- it 'expands out the key with namespace and Rails version' do
- cache = described_class.new(namespace: namespace, cache_key_with_version: true)
+ context 'when cache_key_strategy is :revision' do
+ let(:cache) { described_class.new(cache_key_strategy: :revision) }
- cache_key = cache.cache_key(key)
+ it { is_expected.to eq Gitlab.revision }
+ end
- expect(cache_key).to eq("#{namespace}:#{key}:#{Gitlab::VERSION}:#{Rails.version}")
- end
- end
+ context 'when cache_key_strategy is :version' do
+ let(:cache) { described_class.new(cache_key_strategy: :version) }
- context 'when cache_key_with_version is false' do
- it 'expands out the key with namespace' do
- cache = described_class.new(namespace: namespace, cache_key_with_version: false)
+ it { is_expected.to eq [Gitlab::VERSION, Rails.version] }
+ end
- cache_key = cache.cache_key(key)
+ context 'when cache_key_strategy is invalid' do
+ let(:cache) { described_class.new(cache_key_strategy: 'unknown') }
- expect(cache_key).to eq("#{namespace}:#{key}")
- end
+ it 'raises KeyError' do
+ expect { subject }.to raise_error(KeyError)
end
end
end
diff --git a/spec/lib/gitlab/usage/metrics/instrumentations/cert_based_clusters_ff_metric_spec.rb b/spec/lib/gitlab/usage/metrics/instrumentations/cert_based_clusters_ff_metric_spec.rb
new file mode 100644
index 00000000000..09cc6ae71d4
--- /dev/null
+++ b/spec/lib/gitlab/usage/metrics/instrumentations/cert_based_clusters_ff_metric_spec.rb
@@ -0,0 +1,21 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::Usage::Metrics::Instrumentations::CertBasedClustersFfMetric do
+ context 'with FF enabled' do
+ it_behaves_like 'a correct instrumented metric value', { time_frame: '7d', data_source: 'database' } do
+ let(:expected_value) { true }
+ end
+ end
+
+ context 'with FF disabled' do
+ before do
+ stub_feature_flags(certificate_based_clusters: false)
+ end
+
+ it_behaves_like 'a correct instrumented metric value', { time_frame: '7d', data_source: 'database' } do
+ let(:expected_value) { false }
+ end
+ end
+end
diff --git a/spec/lib/gitlab/usage_data_spec.rb b/spec/lib/gitlab/usage_data_spec.rb
index 868c667e69d..958df7baf72 100644
--- a/spec/lib/gitlab/usage_data_spec.rb
+++ b/spec/lib/gitlab/usage_data_spec.rb
@@ -1100,6 +1100,20 @@ RSpec.describe Gitlab::UsageData, :aggregate_failures do
expect(subject[:settings][:user_cap_feature_enabled]).to eq(Gitlab::CurrentSettings.new_user_signups_cap)
end
+ it 'reports status of the certificate_based_clusters feature flag as true' do
+ expect(subject[:settings][:certificate_based_clusters_ff]).to eq(true)
+ end
+
+ context 'with certificate_based_clusters disabled' do
+ before do
+ stub_feature_flags(certificate_based_clusters: false)
+ end
+
+ it 'reports status of the certificate_based_clusters feature flag as false' do
+ expect(subject[:settings][:certificate_based_clusters_ff]).to eq(false)
+ end
+ end
+
context 'snowplow stats' do
before do
stub_feature_flags(usage_data_instrumentation: false)
diff --git a/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features_spec.rb b/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features_spec.rb
new file mode 100644
index 00000000000..8ec51d86779
--- /dev/null
+++ b/spec/migrations/recreate_index_security_ci_builds_on_name_and_id_parser_with_new_features_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+require_migration!
+
+RSpec.describe RecreateIndexSecurityCiBuildsOnNameAndIdParserWithNewFeatures, :migration do
+ let(:db) { described_class.new }
+ let(:pg_class) { table(:pg_class) }
+ let(:pg_index) { table(:pg_index) }
+ let(:async_indexes) { table(:postgres_async_indexes) }
+
+ it 'recreates index' do
+ reversible_migration do |migration|
+ migration.before -> {
+ expect(async_indexes.where(name: described_class::OLD_INDEX_NAME).exists?).to be false
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::OLD_INDEX_NAME)).to be true
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::NEW_INDEX_NAME)).to be false
+ }
+
+ migration.after -> {
+ expect(async_indexes.where(name: described_class::OLD_INDEX_NAME).exists?).to be true
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::OLD_INDEX_NAME)).to be false
+ expect(db.index_exists?(described_class::TABLE, described_class::COLUMNS, name: described_class::NEW_INDEX_NAME)).to be true
+ }
+ end
+ end
+end
diff --git a/spec/models/broadcast_message_spec.rb b/spec/models/broadcast_message_spec.rb
index d981189c6f1..17f3b2e5072 100644
--- a/spec/models/broadcast_message_spec.rb
+++ b/spec/models/broadcast_message_spec.rb
@@ -286,9 +286,9 @@ RSpec.describe BroadcastMessage do
it 'flushes the Redis cache' do
message = create(:broadcast_message)
- expect(Rails.cache).to receive(:delete).with(described_class::CACHE_KEY)
- expect(Rails.cache).to receive(:delete).with(described_class::BANNER_CACHE_KEY)
- expect(Rails.cache).to receive(:delete).with(described_class::NOTIFICATION_CACHE_KEY)
+ expect(Rails.cache).to receive(:delete).with("#{described_class::CACHE_KEY}:#{Gitlab.revision}")
+ expect(Rails.cache).to receive(:delete).with("#{described_class::BANNER_CACHE_KEY}:#{Gitlab.revision}")
+ expect(Rails.cache).to receive(:delete).with("#{described_class::NOTIFICATION_CACHE_KEY}:#{Gitlab.revision}")
message.flush_redis_cache
end
diff --git a/spec/models/concerns/mentionable_spec.rb b/spec/models/concerns/mentionable_spec.rb
index 3c095477ea9..9daea3438cb 100644
--- a/spec/models/concerns/mentionable_spec.rb
+++ b/spec/models/concerns/mentionable_spec.rb
@@ -9,6 +9,7 @@ RSpec.describe Mentionable do
include Mentionable
attr_accessor :project, :message
+
attr_mentionable :message
def author
diff --git a/spec/requests/api/system_hooks_spec.rb b/spec/requests/api/system_hooks_spec.rb
index 1511872d183..d94b70ec0f9 100644
--- a/spec/requests/api/system_hooks_spec.rb
+++ b/spec/requests/api/system_hooks_spec.rb
@@ -36,12 +36,57 @@ RSpec.describe API::SystemHooks do
expect(response).to have_gitlab_http_status(:ok)
expect(response).to include_pagination_headers
- expect(json_response).to be_an Array
+ expect(response).to match_response_schema('public_api/v4/system_hooks')
+ expect(json_response.first).not_to have_key("token")
expect(json_response.first['url']).to eq(hook.url)
expect(json_response.first['push_events']).to be false
expect(json_response.first['tag_push_events']).to be false
expect(json_response.first['merge_requests_events']).to be false
expect(json_response.first['repository_update_events']).to be true
+ expect(json_response.first['enable_ssl_verification']).to be true
+ end
+ end
+ end
+
+ describe "GET /hooks/:id" do
+ context "when no user" do
+ it "returns authentication error" do
+ get api("/hooks/#{hook.id}")
+
+ expect(response).to have_gitlab_http_status(:unauthorized)
+ end
+ end
+
+ context "when not an admin" do
+ it "returns forbidden error" do
+ get api("/hooks/#{hook.id}", user)
+
+ expect(response).to have_gitlab_http_status(:forbidden)
+ end
+ end
+
+ context "when authenticated as admin" do
+ it "gets a hook", :aggregate_failures do
+ get api("/hooks/#{hook.id}", admin)
+
+ expect(response).to have_gitlab_http_status(:ok)
+ expect(response).to match_response_schema('public_api/v4/system_hook')
+ expect(json_response).to match(
+ 'id' => be(hook.id),
+ 'url' => eq(hook.url),
+ 'created_at' => eq(hook.created_at.iso8601(3)),
+ 'push_events' => be(hook.push_events),
+ 'tag_push_events' => be(hook.tag_push_events),
+ 'merge_requests_events' => be(hook.merge_requests_events),
+ 'repository_update_events' => be(hook.repository_update_events),
+ 'enable_ssl_verification' => be(hook.enable_ssl_verification)
+ )
+ end
+
+ it 'returns 404 if the system hook does not exist' do
+ get api("/hooks/#{non_existing_record_id}", admin)
+
+ expect(response).to have_gitlab_http_status(:not_found)
end
end
end
@@ -77,6 +122,7 @@ RSpec.describe API::SystemHooks do
post api('/hooks', admin), params: { url: 'http://mep.mep' }
expect(response).to have_gitlab_http_status(:created)
+ expect(response).to match_response_schema('public_api/v4/system_hook')
expect(json_response['enable_ssl_verification']).to be true
expect(json_response['push_events']).to be false
expect(json_response['tag_push_events']).to be false
@@ -98,6 +144,7 @@ RSpec.describe API::SystemHooks do
}
expect(response).to have_gitlab_http_status(:created)
+ expect(response).to match_response_schema('public_api/v4/system_hook')
expect(json_response['enable_ssl_verification']).to be false
expect(json_response['push_events']).to be true
expect(json_response['tag_push_events']).to be true
diff --git a/spec/support/helpers/sorting_helper.rb b/spec/support/helpers/sorting_helper.rb
index f19f8c12928..6ff6dbb7800 100644
--- a/spec/support/helpers/sorting_helper.rb
+++ b/spec/support/helpers/sorting_helper.rb
@@ -26,6 +26,7 @@ module SortingHelper
include Comparable
attr_reader :value
+
delegate :==, :eql?, :hash, to: :value
def initialize(value)
diff --git a/spec/tooling/danger/changelog_spec.rb b/spec/tooling/danger/changelog_spec.rb
deleted file mode 100644
index 377c3e881c9..00000000000
--- a/spec/tooling/danger/changelog_spec.rb
+++ /dev/null
@@ -1,467 +0,0 @@
-# frozen_string_literal: true
-
-require 'gitlab-dangerfiles'
-require 'gitlab/dangerfiles/spec_helper'
-
-require_relative '../../../tooling/danger/changelog'
-require_relative '../../../tooling/danger/project_helper'
-
-RSpec.describe Tooling::Danger::Changelog do
- include_context "with dangerfile"
-
- let(:fake_danger) { DangerSpecHelper.fake_danger.include(described_class) }
- let(:fake_project_helper) { double('fake-project-helper', helper: fake_helper).tap { |h| h.class.include(Tooling::Danger::ProjectHelper) } }
-
- subject(:changelog) { fake_danger.new(helper: fake_helper) }
-
- before do
- allow(changelog).to receive(:project_helper).and_return(fake_project_helper)
- end
-
- describe '#check_changelog_commit_categories' do
- context 'when all changelog commits are correct' do
- it 'does not produce any messages' do
- commit = double(:commit, message: "foo\nChangelog: fixed")
-
- allow(changelog).to receive(:changelog_commits).and_return([commit])
-
- expect(changelog).not_to receive(:fail)
-
- changelog.check_changelog_commit_categories
- end
- end
-
- context 'when a commit has an incorrect trailer' do
- it 'adds a message' do
- commit = double(:commit, message: "foo\nChangelog: foo", sha: '123')
-
- allow(changelog).to receive(:changelog_commits).and_return([commit])
-
- expect(changelog).to receive(:fail)
-
- changelog.check_changelog_commit_categories
- end
- end
- end
-
- describe '#check_changelog_trailer' do
- subject { changelog.check_changelog_trailer(commit) }
-
- context "when commit include a changelog trailer with an unknown category" do
- let(:commit) { double('commit', message: "Hello world\n\nChangelog: foo", sha: "abc123") }
-
- it { is_expected.to have_attributes(errors: ["Commit #{commit.sha} uses an invalid changelog category: foo"]) }
- end
-
- context 'when a commit uses the wrong casing for a trailer' do
- let(:commit) { double('commit', message: "Hello world\n\nchangelog: foo", sha: "abc123") }
-
- it { is_expected.to have_attributes(errors: ["The changelog trailer for commit #{commit.sha} must be `Changelog` (starting with a capital C), not `changelog`"]) }
- end
-
- described_class::CATEGORIES.each do |category|
- context "when commit include a changelog trailer with category set to '#{category}'" do
- let(:commit) { double('commit', message: "Hello world\n\nChangelog: #{category}", sha: "abc123") }
-
- it { is_expected.to have_attributes(errors: []) }
- end
- end
- end
-
- describe '#check_changelog_path' do
- let(:changelog_path) { 'changelog-path.yml' }
- let(:foss_change) { nil }
- let(:ee_change) { nil }
- let(:changelog_change) { nil }
- let(:changes) { changes_class.new([foss_change, ee_change, changelog_change].compact) }
-
- before do
- allow(changelog).to receive(:present?).and_return(true)
- end
-
- subject { changelog.check_changelog_path }
-
- context "when changelog is not present" do
- before do
- allow(changelog).to receive(:present?).and_return(false)
- end
-
- it { is_expected.to have_attributes(errors: [], warnings: [], markdowns: [], messages: []) }
- end
-
- context "with EE changes" do
- let(:ee_change) { change_class.new('ee/app/models/foo.rb', :added, :backend) }
-
- context "and a non-EE changelog, and changelog not required" do
- before do
- allow(changelog).to receive(:required?).and_return(false)
- allow(changelog).to receive(:ee_changelog?).and_return(false)
- end
-
- it { is_expected.to have_attributes(warnings: ["This MR changes code in `ee/`, but its Changelog commit is missing the [`EE: true` trailer](https://docs.gitlab.com/ee/development/changelog.html#gitlab-enterprise-changes). Consider adding it to your Changelog commits."]) }
- end
-
- context "and a EE changelog" do
- before do
- allow(changelog).to receive(:ee_changelog?).and_return(true)
- end
-
- it { is_expected.to have_attributes(errors: [], warnings: [], markdowns: [], messages: []) }
-
- context "and there are DB changes" do
- let(:foss_change) { change_class.new('db/migrate/foo.rb', :added, :migration) }
-
- it { is_expected.to have_attributes(warnings: ["This MR has a Changelog commit with the `EE: true` trailer, but there are database changes which [requires](https://docs.gitlab.com/ee/development/changelog.html#what-warrants-a-changelog-entry) the Changelog commit to not have the `EE: true` trailer. Consider removing the `EE: true` trailer from your commits."]) }
- end
- end
- end
-
- context "with no EE changes" do
- let(:foss_change) { change_class.new('app/models/foo.rb', :added, :backend) }
-
- context "and a non-EE changelog" do
- before do
- allow(changelog).to receive(:ee_changelog?).and_return(false)
- end
-
- it { is_expected.to have_attributes(errors: [], warnings: [], markdowns: [], messages: []) }
- end
-
- context "and a EE changelog" do
- before do
- allow(changelog).to receive(:ee_changelog?).and_return(true)
- end
-
- it { is_expected.to have_attributes(warnings: ["This MR has a Changelog commit for EE, but no code changes in `ee/`. Consider removing the `EE: true` trailer from your commits."]) }
- end
- end
- end
-
- describe '#required_reasons' do
- subject { changelog.required_reasons }
-
- context "added files contain a migration" do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) }
-
- it { is_expected.to include(:db_changes) }
- end
-
- context "removed files contains a feature flag" do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) }
-
- it { is_expected.to include(:feature_flag_removed) }
- end
-
- context "added files do not contain a migration" do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :frontend)]) }
-
- it { is_expected.to be_empty }
- end
-
- context "removed files do not contain a feature flag" do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :backend)]) }
-
- it { is_expected.to be_empty }
- end
- end
-
- describe '#required?' do
- subject { changelog.required? }
-
- context 'added files contain a migration' do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) }
-
- it { is_expected.to be_truthy }
- end
-
- context "removed files contains a feature flag" do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) }
-
- it { is_expected.to be_truthy }
- end
-
- context 'added files do not contain a migration' do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :frontend)]) }
-
- it { is_expected.to be_falsey }
- end
-
- context "removed files do not contain a feature flag" do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :backend)]) }
-
- it { is_expected.to be_falsey }
- end
- end
-
- describe '#optional?' do
- let(:category_with_changelog) { :backend }
- let(:label_with_changelog) { 'frontend' }
- let(:category_without_changelog) { Tooling::Danger::Changelog::NO_CHANGELOG_CATEGORIES.first }
- let(:label_without_changelog) { Tooling::Danger::Changelog::NO_CHANGELOG_LABELS.first }
-
- subject { changelog.optional? }
-
- context 'when MR contains only categories requiring no changelog' do
- let(:changes) { changes_class.new([change_class.new('foo', :modified, category_without_changelog)]) }
-
- it 'is falsey' do
- is_expected.to be_falsy
- end
- end
-
- context 'when MR contains a label that require no changelog' do
- let(:changes) { changes_class.new([change_class.new('foo', :modified, category_with_changelog)]) }
- let(:mr_labels) { [label_with_changelog, label_without_changelog] }
-
- it 'is falsey' do
- is_expected.to be_falsy
- end
- end
-
- context 'when MR contains a category that require changelog and a category that require no changelog' do
- let(:changes) { changes_class.new([change_class.new('foo', :modified, category_with_changelog), change_class.new('foo', :modified, category_without_changelog)]) }
-
- context 'with no labels' do
- it 'is truthy' do
- is_expected.to be_truthy
- end
- end
-
- context 'with changelog label' do
- let(:mr_labels) { ['type::feature'] }
-
- it 'is truthy' do
- is_expected.to be_truthy
- end
- end
-
- context 'with no changelog label' do
- let(:mr_labels) { ['type::tooling'] }
-
- it 'is truthy' do
- is_expected.to be_falsey
- end
- end
- end
- end
-
- describe '#present?' do
- it 'returns true when a Changelog commit is present' do
- allow(changelog)
- .to receive(:valid_changelog_commits)
- .and_return([double(:commit)])
-
- expect(changelog).to be_present
- end
-
- it 'returns false when a Changelog commit is missing' do
- allow(changelog).to receive(:valid_changelog_commits).and_return([])
-
- expect(changelog).not_to be_present
- end
- end
-
- describe '#changelog_commits' do
- it 'returns the commits that include a Changelog trailer' do
- commit1 = double(:commit, message: "foo\nChangelog: fixed")
- commit2 = double(:commit, message: "bar\nChangelog: kittens")
- commit3 = double(:commit, message: 'testing')
- git = double(:git)
-
- allow(changelog).to receive(:git).and_return(git)
- allow(git).to receive(:commits).and_return([commit1, commit2, commit3])
-
- expect(changelog.changelog_commits).to eq([commit1, commit2])
- end
- end
-
- describe '#valid_changelog_commits' do
- it 'returns the commits with a valid Changelog trailer' do
- commit1 = double(:commit, message: "foo\nChangelog: fixed")
- commit2 = double(:commit, message: "bar\nChangelog: kittens")
-
- allow(changelog)
- .to receive(:changelog_commits)
- .and_return([commit1, commit2])
-
- expect(changelog.valid_changelog_commits).to eq([commit1])
- end
- end
-
- describe '#ee_changelog?' do
- it 'returns true when an EE changelog commit is present' do
- commit = double(:commit, message: "foo\nEE: true")
-
- allow(changelog).to receive(:changelog_commits).and_return([commit])
-
- expect(changelog.ee_changelog?).to eq(true)
- end
-
- it 'returns false when an EE changelog commit is missing' do
- commit = double(:commit, message: 'foo')
-
- allow(changelog).to receive(:changelog_commits).and_return([commit])
-
- expect(changelog.ee_changelog?).to eq(false)
- end
- end
-
- describe '#modified_text' do
- subject { changelog.modified_text }
-
- context 'when in CI context' do
- shared_examples 'changelog modified text' do |key|
- specify do
- expect(subject).to include('CHANGELOG.md was edited')
- expect(subject).to include('`Changelog` trailer')
- expect(subject).to include('`EE: true`')
- end
- end
-
- before do
- allow(fake_helper).to receive(:ci?).and_return(true)
- end
-
- context "when title is not changed from sanitization", :aggregate_failures do
- let(:mr_title) { 'Fake Title' }
-
- it_behaves_like 'changelog modified text'
- end
-
- context "when title needs sanitization", :aggregate_failures do
- let(:mr_title) { 'DRAFT: Fake Title' }
-
- it_behaves_like 'changelog modified text'
- end
- end
-
- context 'when in local context' do
- let(:mr_title) { 'Fake Title' }
-
- before do
- allow(fake_helper).to receive(:ci?).and_return(false)
- end
-
- specify do
- expect(subject).to include('CHANGELOG.md was edited')
- expect(subject).not_to include('`Changelog` trailer')
- end
- end
- end
-
- describe '#required_texts' do
- let(:mr_title) { 'Fake Title' }
-
- subject { changelog.required_texts }
-
- context 'when in CI context' do
- before do
- allow(fake_helper).to receive(:ci?).and_return(true)
- end
-
- shared_examples 'changelog required text' do |key|
- specify do
- expect(subject).to have_key(key)
- expect(subject[key]).to include('CHANGELOG missing')
- expect(subject[key]).to include('`Changelog` trailer')
- end
- end
-
- context 'with a new migration file' do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) }
-
- context "when title is not changed from sanitization", :aggregate_failures do
- it_behaves_like 'changelog required text', :db_changes
- end
-
- context "when title needs sanitization", :aggregate_failures do
- let(:mr_title) { 'DRAFT: Fake Title' }
-
- it_behaves_like 'changelog required text', :db_changes
- end
- end
-
- context 'with a removed feature flag file' do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) }
-
- it_behaves_like 'changelog required text', :feature_flag_removed
- end
- end
-
- context 'when in local context' do
- before do
- allow(fake_helper).to receive(:ci?).and_return(false)
- end
-
- shared_examples 'changelog required text' do |key|
- specify do
- expect(subject).to have_key(key)
- expect(subject[key]).to include('CHANGELOG missing')
- expect(subject[key]).not_to include('`Changelog` trailer')
- end
- end
-
- context 'with a new migration file' do
- let(:changes) { changes_class.new([change_class.new('foo', :added, :migration)]) }
-
- context "when title is not changed from sanitization", :aggregate_failures do
- it_behaves_like 'changelog required text', :db_changes
- end
-
- context "when title needs sanitization", :aggregate_failures do
- let(:mr_title) { 'DRAFT: Fake Title' }
-
- it_behaves_like 'changelog required text', :db_changes
- end
- end
-
- context 'with a removed feature flag file' do
- let(:changes) { changes_class.new([change_class.new('foo', :deleted, :feature_flag)]) }
-
- it_behaves_like 'changelog required text', :feature_flag_removed
- end
- end
- end
-
- describe '#optional_text' do
- subject { changelog.optional_text }
-
- context 'when in CI context' do
- shared_examples 'changelog optional text' do |key|
- specify do
- expect(subject).to include('CHANGELOG missing')
- expect(subject).to include('`Changelog` trailer')
- expect(subject).to include('EE: true')
- end
- end
-
- before do
- allow(fake_helper).to receive(:ci?).and_return(true)
- end
-
- context "when title is not changed from sanitization", :aggregate_failures do
- let(:mr_title) { 'Fake Title' }
-
- it_behaves_like 'changelog optional text'
- end
-
- context "when title needs sanitization", :aggregate_failures do
- let(:mr_title) { 'DRAFT: Fake Title' }
-
- it_behaves_like 'changelog optional text'
- end
- end
-
- context 'when in local context' do
- let(:mr_title) { 'Fake Title' }
-
- before do
- allow(fake_helper).to receive(:ci?).and_return(false)
- end
-
- specify do
- expect(subject).to include('CHANGELOG missing')
- end
- end
- end
-end
diff --git a/spec/tooling/danger/project_helper_spec.rb b/spec/tooling/danger/project_helper_spec.rb
index eaafb13b61a..03f5836beab 100644
--- a/spec/tooling/danger/project_helper_spec.rb
+++ b/spec/tooling/danger/project_helper_spec.rb
@@ -44,7 +44,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'ee/README' | [:unknown]
'app/assets/foo' | [:frontend]
- 'app/views/foo' | [:frontend]
+ 'app/views/foo' | [:frontend, :backend]
'public/foo' | [:frontend]
'scripts/frontend/foo' | [:frontend]
'spec/frontend/bar' | [:frontend]
@@ -58,7 +58,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'config/deep/foo.js' | [:frontend]
'ee/app/assets/foo' | [:frontend]
- 'ee/app/views/foo' | [:frontend]
+ 'ee/app/views/foo' | [:frontend, :backend]
'ee/spec/frontend/bar' | [:frontend]
'ee/spec/frontend_integration/bar' | [:frontend]
@@ -231,9 +231,12 @@ RSpec.describe Tooling::Danger::ProjectHelper do
'ee/app/assets/javascripts/integrations/zentao/issues_list/graphql/queries/get_zentao_issues.query.graphql' | [:integrations_fe, :frontend]
'app/assets/javascripts/pages/projects/settings/integrations/show/index.js' | [:integrations_fe, :frontend]
'ee/app/assets/javascripts/pages/groups/hooks/index.js' | [:integrations_fe, :frontend]
- 'app/views/clusters/clusters/_integrations_tab.html.haml' | [:frontend]
+ 'app/views/clusters/clusters/_integrations_tab.html.haml' | [:frontend, :backend]
'app/assets/javascripts/alerts_settings/graphql/fragments/integration_item.fragment.graphql' | [:frontend]
'app/assets/javascripts/filtered_search/droplab/hook_input.js' | [:frontend]
+
+ 'app/views/layouts/header/_default.html.haml' | [:frontend, :backend]
+ 'app/views/layouts/header/_default.html.erb' | [:frontend, :backend]
end
with_them do
@@ -274,7 +277,7 @@ RSpec.describe Tooling::Danger::ProjectHelper do
describe '.local_warning_message' do
it 'returns an informational message with rules that can run' do
- expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: changelog, ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation, datateam')
+ expect(described_class.local_warning_message).to eq('==> Only the following Danger rules can be run locally: ci_config, database, documentation, duplicate_yarn_dependencies, eslint, gitaly, pajamas, pipeline, prettier, product_intelligence, utility_css, vue_shared_documentation, datateam')
end
end
@@ -306,18 +309,6 @@ RSpec.describe Tooling::Danger::ProjectHelper do
end
end
- describe '#all_ee_changes' do
- subject { project_helper.all_ee_changes }
-
- it 'returns all changed files starting with ee/' do
- changes = double
- expect(fake_helper).to receive(:changes).and_return(changes)
- expect(changes).to receive(:files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k])
-
- is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb])
- end
- end
-
describe '#file_lines' do
let(:filename) { 'spec/foo_spec.rb' }
let(:file_spy) { spy }
diff --git a/spec/validators/array_members_validator_spec.rb b/spec/validators/array_members_validator_spec.rb
index c6960925487..0e3ca4b5b7b 100644
--- a/spec/validators/array_members_validator_spec.rb
+++ b/spec/validators/array_members_validator_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe ArrayMembersValidator do
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :children
+
validates :children, array_members: { member_class: child_class }
end
end
diff --git a/spec/validators/color_validator_spec.rb b/spec/validators/color_validator_spec.rb
index bd77b3df182..27acbe5e89d 100644
--- a/spec/validators/color_validator_spec.rb
+++ b/spec/validators/color_validator_spec.rb
@@ -10,6 +10,7 @@ RSpec.describe ColorValidator do
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :color
+
validates :color, color: true
end.new
end
diff --git a/spec/validators/cron_validator_spec.rb b/spec/validators/cron_validator_spec.rb
index dff3b506b89..bd7fe242957 100644
--- a/spec/validators/cron_validator_spec.rb
+++ b/spec/validators/cron_validator_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe CronValidator do
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :cron
+
validates :cron, cron: true
def cron_timezone
@@ -34,6 +35,7 @@ RSpec.describe CronValidator do
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :cron_partytime
+
validates :cron_partytime, cron: true
end.new
end
diff --git a/spec/validators/future_date_validator_spec.rb b/spec/validators/future_date_validator_spec.rb
index 6814ba7c820..7af3d473bd9 100644
--- a/spec/validators/future_date_validator_spec.rb
+++ b/spec/validators/future_date_validator_spec.rb
@@ -8,6 +8,7 @@ RSpec.describe FutureDateValidator do
include ActiveModel::Model
include ActiveModel::Validations
attr_accessor :expires_at
+
validates :expires_at, future_date: true
end.new
end