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-10 09:17:41 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-02-10 09:17:41 +0300
commitb4ea95860f6fa2621539940db6d3b4363f2c639b (patch)
tree6eaae2c497d2a4fd0008da48bb2a4c04c2de5e75 /spec
parent8e6b1dc7f7dfb9a7f8431f7c246415e34d31870a (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/groups/releases_controller_spec.rb8
-rw-r--r--spec/finders/releases_finder_spec.rb72
-rw-r--r--spec/frontend/issues/list/components/issues_list_app_spec.js12
-rw-r--r--spec/frontend/issues/list/utils_spec.js12
-rw-r--r--spec/lib/gitlab/background_migration/backfill_namespace_id_for_namespace_route_spec.rb50
-rw-r--r--spec/migrations/backfill_namespace_id_for_namespace_routes_spec.rb29
-rw-r--r--spec/spec_helper.rb14
-rw-r--r--spec/support/helpers/memory_usage_helper.rb37
-rw-r--r--spec/support/helpers/test_env.rb11
9 files changed, 131 insertions, 114 deletions
diff --git a/spec/controllers/groups/releases_controller_spec.rb b/spec/controllers/groups/releases_controller_spec.rb
index 50701382945..582a77b1c50 100644
--- a/spec/controllers/groups/releases_controller_spec.rb
+++ b/spec/controllers/groups/releases_controller_spec.rb
@@ -6,14 +6,14 @@ RSpec.describe Groups::ReleasesController do
let(:group) { create(:group) }
let!(:project) { create(:project, :repository, :public, namespace: group) }
let!(:private_project) { create(:project, :repository, :private, namespace: group) }
- let(:developer) { create(:user) }
+ let(:guest) { create(:user) }
let!(:release_1) { create(:release, project: project, tag: 'v1', released_at: Time.zone.parse('2020-02-15')) }
let!(:release_2) { create(:release, project: project, tag: 'v2', released_at: Time.zone.parse('2020-02-20')) }
let!(:private_release_1) { create(:release, project: private_project, tag: 'p1', released_at: Time.zone.parse('2020-03-01')) }
let!(:private_release_2) { create(:release, project: private_project, tag: 'p2', released_at: Time.zone.parse('2020-03-05')) }
before do
- private_project.add_developer(developer)
+ group.add_guest(guest)
end
describe 'GET #index' do
@@ -42,7 +42,7 @@ RSpec.describe Groups::ReleasesController do
end
it 'does not return any releases' do
- expect(json_response.map {|r| r['tag'] } ).to match_array(%w(v2 v1))
+ expect(json_response.map {|r| r['tag'] } ).to be_empty
end
it 'returns OK' do
@@ -52,7 +52,7 @@ RSpec.describe Groups::ReleasesController do
context 'the user is authorized' do
it "returns all group's public and private project's releases as JSON, ordered by released_at" do
- sign_in(developer)
+ sign_in(guest)
subject
diff --git a/spec/finders/releases_finder_spec.rb b/spec/finders/releases_finder_spec.rb
index 94b6fe53daa..5ddb5c33fad 100644
--- a/spec/finders/releases_finder_spec.rb
+++ b/spec/finders/releases_finder_spec.rb
@@ -23,6 +23,16 @@ RSpec.describe ReleasesFinder do
end
end
+ shared_examples_for 'when the user is not part of the group' do
+ before do
+ allow(Ability).to receive(:allowed?).with(user, :read_release, group).and_return(false)
+ end
+
+ it 'returns no releases' do
+ is_expected.to be_empty
+ end
+ end
+
# See https://gitlab.com/gitlab-org/gitlab/-/merge_requests/27716
shared_examples_for 'when tag is nil' do
before do
@@ -66,9 +76,9 @@ RSpec.describe ReleasesFinder do
it_behaves_like 'when the user is not part of the project'
- context 'when the user is a project developer' do
+ context 'when the user is a project guest' do
before do
- project.add_developer(user)
+ project.add_guest(user)
end
it 'sorts by release date' do
@@ -118,25 +128,24 @@ RSpec.describe ReleasesFinder do
subject { described_class.new(group, user, params).execute(**args) }
- it_behaves_like 'when the user is not part of the project'
+ it_behaves_like 'when the user is not part of the group'
- context 'when the user is a project developer on one sibling project' do
+ context 'when the user is a project guest on one sibling project' do
before do
- project.add_developer(user)
+ project.add_guest(user)
v1_0_0.update_attribute(:released_at, 3.days.ago)
v1_1_0.update_attribute(:released_at, 1.day.ago)
end
- it 'sorts by release date' do
- expect(subject.size).to eq(2)
- expect(subject).to eq([v1_1_0, v1_0_0])
+ it 'does not return any releases' do
+ expect(subject.size).to eq(0)
+ expect(subject).to eq([])
end
end
- context 'when the user is a project developer on all projects' do
+ context 'when the user is a guest on the group' do
before do
- project.add_developer(user)
- project2.add_developer(user)
+ group.add_guest(user)
v1_0_0.update_attribute(:released_at, 3.days.ago)
v6.update_attribute(:released_at, 2.days.ago)
v1_1_0.update_attribute(:released_at, 1.day.ago)
@@ -161,22 +170,21 @@ RSpec.describe ReleasesFinder do
let(:project2) { create(:project, :repository, namespace: subgroup) }
let!(:v6) { create(:release, project: project2, tag: 'v6') }
- it_behaves_like 'when the user is not part of the project'
+ it_behaves_like 'when the user is not part of the group'
- context 'when the user a project developer in the subgroup project' do
+ context 'when the user a project guest in the subgroup project' do
before do
- project2.add_developer(user)
+ project2.add_guest(user)
end
- it 'returns only the subgroup releases' do
- expect(subject).to match_array([v6])
+ it 'does not return any releases' do
+ expect(subject).to match_array([])
end
end
- context 'when the user a project developer in both projects' do
+ context 'when the user is a guest on the group' do
before do
- project.add_developer(user)
- project2.add_developer(user)
+ group.add_guest(user)
v6.update_attribute(:released_at, 2.days.ago)
end
@@ -201,34 +209,32 @@ RSpec.describe ReleasesFinder do
p3.update_attribute(:released_at, 3.days.ago)
end
- it_behaves_like 'when the user is not part of the project'
+ it_behaves_like 'when the user is not part of the group'
- context 'when the user a project developer in the subgroup and subsubgroup project' do
+ context 'when the user a project guest in the subgroup and subsubgroup project' do
before do
- project2.add_developer(user)
- project3.add_developer(user)
+ project2.add_guest(user)
+ project3.add_guest(user)
end
- it 'returns only the subgroup and subsubgroup releases' do
- expect(subject).to match_array([v6, p3])
+ it 'does not return any releases' do
+ expect(subject).to match_array([])
end
end
- context 'when the user a project developer in the subsubgroup project' do
+ context 'when the user a project guest in the subsubgroup project' do
before do
- project3.add_developer(user)
+ project3.add_guest(user)
end
- it 'returns only the subsubgroup releases' do
- expect(subject).to match_array([p3])
+ it 'does not return any releases' do
+ expect(subject).to match_array([])
end
end
- context 'when the user a project developer in all projects' do
+ context 'when the user a guest on the group' do
before do
- project.add_developer(user)
- project2.add_developer(user)
- project3.add_developer(user)
+ group.add_guest(user)
end
it 'returns all releases' do
diff --git a/spec/frontend/issues/list/components/issues_list_app_spec.js b/spec/frontend/issues/list/components/issues_list_app_spec.js
index 1f2b3ad4cb1..b7fb5bc7e61 100644
--- a/spec/frontend/issues/list/components/issues_list_app_spec.js
+++ b/spec/frontend/issues/list/components/issues_list_app_spec.js
@@ -30,8 +30,6 @@ import IssuesListApp from '~/issues/list/components/issues_list_app.vue';
import NewIssueDropdown from '~/issues/list/components/new_issue_dropdown.vue';
import {
CREATED_DESC,
- DUE_DATE_OVERDUE,
- PARAM_DUE_DATE,
RELATIVE_POSITION,
RELATIVE_POSITION_ASC,
TOKEN_TYPE_ASSIGNEE,
@@ -296,16 +294,6 @@ describe('CE IssuesListApp component', () => {
});
describe('initial url params', () => {
- describe('due_date', () => {
- it('is set from the url params', () => {
- setWindowLocation(`?${PARAM_DUE_DATE}=${DUE_DATE_OVERDUE}`);
-
- wrapper = mountComponent();
-
- expect(findIssuableList().props('urlParams')).toMatchObject({ due_date: DUE_DATE_OVERDUE });
- });
- });
-
describe('search', () => {
it('is set from the url params', () => {
setWindowLocation(locationSearch);
diff --git a/spec/frontend/issues/list/utils_spec.js b/spec/frontend/issues/list/utils_spec.js
index 487625bdc7c..1d3e94df897 100644
--- a/spec/frontend/issues/list/utils_spec.js
+++ b/spec/frontend/issues/list/utils_spec.js
@@ -10,7 +10,6 @@ import {
} from 'jest/issues/list/mock_data';
import {
defaultPageSizeParams,
- DUE_DATE_VALUES,
largePageSizeParams,
RELATIVE_POSITION_ASC,
urlSortParams,
@@ -19,7 +18,6 @@ import {
convertToApiParams,
convertToSearchQuery,
convertToUrlParams,
- getDueDateValue,
getFilterTokens,
getInitialPageParams,
getSortKey,
@@ -56,16 +54,6 @@ describe('isSortKey', () => {
});
});
-describe('getDueDateValue', () => {
- it.each(DUE_DATE_VALUES)('returns the argument when it is `%s`', (value) => {
- expect(getDueDateValue(value)).toBe(value);
- });
-
- it('returns undefined when the argument is invalid', () => {
- expect(getDueDateValue('invalid value')).toBeUndefined();
- });
-});
-
describe('getSortOptions', () => {
describe.each`
hasIssueWeightsFeature | hasBlockedIssuesFeature | length | containsWeight | containsBlocking
diff --git a/spec/lib/gitlab/background_migration/backfill_namespace_id_for_namespace_route_spec.rb b/spec/lib/gitlab/background_migration/backfill_namespace_id_for_namespace_route_spec.rb
new file mode 100644
index 00000000000..b821efcadb0
--- /dev/null
+++ b/spec/lib/gitlab/background_migration/backfill_namespace_id_for_namespace_route_spec.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Gitlab::BackgroundMigration::BackfillNamespaceIdForNamespaceRoute, :migration, schema: 20220120123800 do
+ let(:migration) { described_class.new }
+ let(:namespaces_table) { table(:namespaces) }
+ let(:projects_table) { table(:projects) }
+ let(:routes_table) { table(:routes) }
+
+ let(:table_name) { 'routes' }
+ let(:batch_column) { :id }
+ let(:sub_batch_size) { 200 }
+ let(:pause_ms) { 0 }
+
+ let(:namespace1) { namespaces_table.create!(name: 'namespace1', path: 'namespace1', type: 'User') }
+ let(:namespace2) { namespaces_table.create!(name: 'namespace2', path: 'namespace2', type: 'Group') }
+ let(:namespace3) { namespaces_table.create!(name: 'namespace3', path: 'namespace3', type: 'Group') }
+ let(:namespace4) { namespaces_table.create!(name: 'namespace4', path: 'namespace4', type: 'Group') }
+ let(:project1) { projects_table.create!(name: 'project1', namespace_id: namespace1.id) }
+
+ subject(:perform_migration) { migration.perform(1, 10, table_name, batch_column, sub_batch_size, pause_ms) }
+
+ before do
+ routes_table.create!(id: 1, name: 'test1', path: 'test1', source_id: namespace1.id,
+ source_type: namespace1.class.sti_name)
+ routes_table.create!(id: 2, name: 'test2', path: 'test2', source_id: namespace2.id,
+ source_type: namespace2.class.sti_name)
+ routes_table.create!(id: 5, name: 'test3', path: 'test3', source_id: project1.id,
+ source_type: project1.class.sti_name) # should be ignored - project route
+ routes_table.create!(id: 6, name: 'test4', path: 'test4', source_id: non_existing_record_id,
+ source_type: namespace3.class.sti_name) # should be ignored - invalid source_id
+ routes_table.create!(id: 10, name: 'test5', path: 'test5', source_id: namespace3.id,
+ source_type: namespace3.class.sti_name)
+ routes_table.create!(id: 11, name: 'test6', path: 'test6', source_id: namespace4.id,
+ source_type: namespace4.class.sti_name) # should be ignored - outside the scope
+ end
+
+ it 'backfills `type` for the selected records', :aggregate_failures do
+ perform_migration
+
+ expect(routes_table.where.not(namespace_id: nil).pluck(:id)).to match_array([1, 2, 10])
+ end
+
+ it 'tracks timings of queries' do
+ expect(migration.batch_metrics.timings).to be_empty
+
+ expect { perform_migration }.to change { migration.batch_metrics.timings }
+ end
+end
diff --git a/spec/migrations/backfill_namespace_id_for_namespace_routes_spec.rb b/spec/migrations/backfill_namespace_id_for_namespace_routes_spec.rb
new file mode 100644
index 00000000000..913ec404795
--- /dev/null
+++ b/spec/migrations/backfill_namespace_id_for_namespace_routes_spec.rb
@@ -0,0 +1,29 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe BackfillNamespaceIdForNamespaceRoutes do
+ let_it_be(:migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ it 'schedules background jobs for each batch of routes' do
+ migrate!
+
+ expect(migration).to have_scheduled_batched_migration(
+ table_name: :routes,
+ column_name: :id,
+ interval: described_class::INTERVAL
+ )
+ end
+ end
+
+ describe '#down' do
+ it 'deletes all batched migration records' do
+ migrate!
+ schema_migrate_down!
+
+ expect(migration).not_to have_scheduled_batched_migration
+ end
+ end
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
index 2b3b7b114c8..f823683c274 100644
--- a/spec/spec_helper.rb
+++ b/spec/spec_helper.rb
@@ -114,6 +114,15 @@ RSpec.configure do |config|
config.run_all_when_everything_filtered = true
end
+ # Attempt to troubleshoot https://gitlab.com/gitlab-org/gitlab/-/issues/351531
+ config.after do |example|
+ if example.exception.is_a?(Gitlab::Database::QueryAnalyzers::PreventCrossDatabaseModification::CrossDatabaseModificationAcrossUnsupportedTablesError)
+ ::CrossDatabaseModification::TransactionStackTrackRecord.log_gitlab_transactions_stack(action: :after_failure, example: example.description)
+ else
+ ::CrossDatabaseModification::TransactionStackTrackRecord.log_gitlab_transactions_stack(action: :after_example, example: example.description)
+ end
+ end
+
# Re-run failures locally with `--only-failures`
config.example_status_persistence_file_path = ENV.fetch('RSPEC_LAST_RUN_RESULTS_FILE', './spec/examples.txt')
@@ -184,7 +193,6 @@ RSpec.configure do |config|
config.include RedisHelpers
config.include Rails.application.routes.url_helpers, type: :routing
config.include PolicyHelpers, type: :policy
- config.include MemoryUsageHelper
config.include ExpectRequestWithStatus, type: :request
config.include IdempotentWorkerHelper, type: :worker
config.include RailsHelpers
@@ -244,10 +252,6 @@ RSpec.configure do |config|
::Ci::ApplicationRecord.set_open_transactions_baseline
end
- config.append_before do
- Thread.current[:current_example_group] = ::RSpec.current_example.metadata[:example_group]
- end
-
config.append_after do
ApplicationRecord.reset_open_transactions_baseline
::Ci::ApplicationRecord.reset_open_transactions_baseline
diff --git a/spec/support/helpers/memory_usage_helper.rb b/spec/support/helpers/memory_usage_helper.rb
deleted file mode 100644
index 02d1935921f..00000000000
--- a/spec/support/helpers/memory_usage_helper.rb
+++ /dev/null
@@ -1,37 +0,0 @@
-# frozen_string_literal: true
-
-module MemoryUsageHelper
- extend ActiveSupport::Concern
-
- def gather_memory_data(csv_path)
- write_csv_entry(csv_path,
- {
- example_group_path: TestEnv.topmost_example_group[:location],
- example_group_description: TestEnv.topmost_example_group[:description],
- time: Time.current,
- job_name: ENV['CI_JOB_NAME']
- }.merge(get_memory_usage))
- end
-
- def write_csv_entry(path, entry)
- CSV.open(path, "a", headers: entry.keys, write_headers: !File.exist?(path)) do |file|
- file << entry.values
- end
- end
-
- def get_memory_usage
- output, status = Gitlab::Popen.popen(%w(free -m))
- abort "`free -m` return code is #{status}: #{output}" unless status == 0
-
- result = output.split("\n")[1].split(" ")[1..]
- attrs = %i(m_total m_used m_free m_shared m_buffers_cache m_available).freeze
-
- attrs.zip(result).to_h
- end
-
- included do |config|
- config.after(:all) do
- gather_memory_data(ENV['MEMORY_TEST_PATH']) if ENV['MEMORY_TEST_PATH']
- end
- end
-end
diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb
index 5c3ca92c4d0..18c25f4b770 100644
--- a/spec/support/helpers/test_env.rb
+++ b/spec/support/helpers/test_env.rb
@@ -371,17 +371,6 @@ module TestEnv
FileUtils.rm_rf(path)
end
- def current_example_group
- Thread.current[:current_example_group]
- end
-
- # looking for a top-level `describe`
- def topmost_example_group
- example_group = current_example_group
- example_group = example_group[:parent_example_group] until example_group[:parent_example_group].nil?
- example_group
- end
-
def seed_db
Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.import
end