diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-07 21:09:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-11-07 21:09:37 +0300 |
commit | fbe6bd7c6aae0beb81fa47d5834393ed92662885 (patch) | |
tree | e2713cbe36fd3d71933ab4c1056de10843e3d3fb /spec | |
parent | d4fcd1794ea9fc10d83cdc75490f76a418e59d52 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
13 files changed, 105 insertions, 53 deletions
diff --git a/spec/features/search/user_uses_header_search_field_spec.rb b/spec/features/search/user_uses_header_search_field_spec.rb index 8381642cd4d..1ab47f6fd59 100644 --- a/spec/features/search/user_uses_header_search_field_spec.rb +++ b/spec/features/search/user_uses_header_search_field_spec.rb @@ -31,12 +31,6 @@ RSpec.describe 'User uses header search field', :js, :disable_rate_limiter, feat submit_search('gitlab') end - it 'renders page title' do - page.within('.page-title') do - expect(page).to have_content('Search') - end - end - it 'renders breadcrumbs' do page.within('.breadcrumbs') do expect(page).to have_content('Search') diff --git a/spec/finders/personal_access_tokens_finder_spec.rb b/spec/finders/personal_access_tokens_finder_spec.rb index d91b2c8f599..d7cc72fe8ed 100644 --- a/spec/finders/personal_access_tokens_finder_spec.rb +++ b/spec/finders/personal_access_tokens_finder_spec.rb @@ -2,16 +2,16 @@ require 'spec_helper' -RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do +RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode, feature_category: :system_access do using RSpec::Parameterized::TableSyntax describe '#execute' do - let(:admin) { create(:admin) } - let(:user) { create(:user) } - let(:other_user) { create(:user) } - let(:project_bot) { create(:user, :project_bot) } + let_it_be(:admin) { create(:admin) } + let_it_be(:user) { create(:user) } + let_it_be(:other_user) { create(:user) } + let_it_be(:project_bot) { create(:user, :project_bot) } - let!(:tokens) do + let_it_be(:tokens) do { active: create(:personal_access_token, user: user, name: 'my_pat_1'), active_other: create(:personal_access_token, user: other_user, name: 'my_pat_2'), @@ -24,6 +24,8 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do } end + let(:tokens_keys) { tokens.keys } + let(:params) { {} } let(:current_user) { admin } @@ -89,7 +91,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by user' do where(:by_user, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) ref(:user) | [:active, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation] ref(:other_user) | [:active_other] ref(:admin) | [] @@ -106,7 +108,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by users' do where(:by_users, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) lazy { [user] } | [:active, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation] lazy { [other_user] } | [:active_other] lazy { [user, other_user] } | [:active, :active_other, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation] @@ -124,10 +126,10 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by impersonation' do where(:by_impersonation, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) true | [:active_impersonation, :expired_impersonation, :revoked_impersonation] false | [:active, :active_other, :expired, :revoked, :bot] - 'other' | tokens.keys + 'other' | ref(:tokens_keys) end with_them do @@ -141,10 +143,10 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by state' do where(:by_state, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) 'active' | [:active, :active_other, :active_impersonation, :bot] 'inactive' | [:expired, :revoked, :expired_impersonation, :revoked_impersonation] - 'other' | tokens.keys + 'other' | ref(:tokens_keys) end with_them do @@ -158,9 +160,9 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by owner type' do where(:by_owner_type, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) 'human' | [:active, :active_other, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation] - 'other' | tokens.keys + 'other' | ref(:tokens_keys) end with_them do @@ -197,7 +199,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do where(:by_created_before, :expected_tokens) do 6.days.ago | [] 2.days.ago | [:active_other] - 2.days.from_now | tokens.keys + 2.days.from_now | ref(:tokens_keys) end with_them do @@ -211,7 +213,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by created after' do where(:by_created_after, :expected_tokens) do - 6.days.ago | tokens.keys + 6.days.ago | ref(:tokens_keys) 2.days.ago | [:active, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation, :bot] 2.days.from_now | [] end @@ -236,7 +238,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do where(:by_last_used_before, :expected_tokens) do 6.days.ago | [] 2.days.ago | [:active_other] - 2.days.from_now | tokens.keys + 2.days.from_now | ref(:tokens_keys) end with_them do @@ -250,7 +252,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by last used after' do where(:by_last_used_after, :expected_tokens) do - 6.days.ago | tokens.keys + 6.days.ago | ref(:tokens_keys) 2.days.ago | [:active, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation, :bot] 2.days.from_now | [] end @@ -267,7 +269,7 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'by search' do where(:by_search, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) 'my_pat' | [:active, :active_other] 'other' | [] end @@ -283,10 +285,10 @@ RSpec.describe PersonalAccessTokensFinder, :enable_admin_mode do describe 'sort' do where(:sort, :expected_tokens) do - nil | tokens.keys + nil | ref(:tokens_keys) 'id_asc' | [:active, :active_other, :expired, :revoked, :active_impersonation, :expired_impersonation, :revoked_impersonation, :bot] 'id_desc' | [:bot, :revoked_impersonation, :expired_impersonation, :active_impersonation, :revoked, :expired, :active_other, :active] - 'other' | tokens.keys + 'other' | ref(:tokens_keys) end with_them do diff --git a/spec/lib/generators/batched_background_migration/batched_background_migration_generator_spec.rb b/spec/lib/generators/batched_background_migration/batched_background_migration_generator_spec.rb index 2d48b83be4c..893cf976074 100644 --- a/spec/lib/generators/batched_background_migration/batched_background_migration_generator_spec.rb +++ b/spec/lib/generators/batched_background_migration/batched_background_migration_generator_spec.rb @@ -14,6 +14,7 @@ RSpec.describe BatchedBackgroundMigration::BatchedBackgroundMigrationGenerator, before do prepare_destination + allow(Gitlab).to receive(:current_milestone).and_return('16.6') end after do diff --git a/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt b/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt index 84a3593b4e3..36f7885b591 100644 --- a/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt +++ b/spec/lib/generators/batched_background_migration/expected_files/queue_my_batched_migration.txt @@ -6,6 +6,8 @@ # Update below commented lines with appropriate values. class QueueMyBatchedMigration < Gitlab::Database::Migration[2.2] + milestone '16.6' + MIGRATION = "MyBatchedMigration" # DELAY_INTERVAL = 2.minutes # BATCH_SIZE = 1000 diff --git a/spec/lib/gitlab/other_markup_spec.rb b/spec/lib/gitlab/other_markup_spec.rb index cdeaed6d368..266cb75a8ac 100644 --- a/spec/lib/gitlab/other_markup_spec.rb +++ b/spec/lib/gitlab/other_markup_spec.rb @@ -122,7 +122,9 @@ RSpec.describe Gitlab::OtherMarkup, feature_category: :wiki do test_text = '<A' + ('A' * 54773) expect do - Timeout.timeout(3.seconds) { RedCloth.new(test_text, [:sanitize_html]).to_html } + Timeout.timeout(Gitlab::OtherMarkup::RENDER_TIMEOUT.seconds) do + RedCloth.new(test_text, [:sanitize_html]).to_html + end end.not_to raise_error end end diff --git a/spec/models/project_snippet_spec.rb b/spec/models/project_snippet_spec.rb index 3d1c87771f3..5ce9499c420 100644 --- a/spec/models/project_snippet_spec.rb +++ b/spec/models/project_snippet_spec.rb @@ -2,11 +2,24 @@ require 'spec_helper' -RSpec.describe ProjectSnippet do +RSpec.describe ProjectSnippet, feature_category: :source_code_management do describe "Associations" do it { is_expected.to belong_to(:project) } end + describe 'scopes' do + describe '.by_project' do + subject { described_class.by_project(project) } + + let_it_be(:project) { create(:project) } + let_it_be(:snippet1) { create(:project_snippet, project: project) } + let_it_be(:snippet2) { create(:project_snippet, project: build(:project)) } + let_it_be(:snippet3) { create(:personal_snippet) } + + it { is_expected.to contain_exactly(snippet1) } + end + end + describe "Validation" do it { is_expected.to validate_presence_of(:project) } it { is_expected.to validate_inclusion_of(:secret).in_array([false]) } diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 7eb1d9fda7b..ff1c5959cb0 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Snippet do +RSpec.describe Snippet, feature_category: :source_code_management do include FakeBlobHelpers describe 'modules' do @@ -26,6 +26,22 @@ RSpec.describe Snippet do it { is_expected.to have_many(:repository_storage_moves).class_name('Snippets::RepositoryStorageMove').inverse_of(:container) } end + describe 'scopes' do + describe '.with_repository_storage_moves' do + subject { described_class.with_repository_storage_moves } + + let_it_be(:snippet) { create(:project_snippet) } + + it { is_expected.to be_empty } + + context 'when associated repository storage move exists' do + let!(:snippet_repository_storage_move) { create(:snippet_repository_storage_move, container: snippet) } + + it { is_expected.to match_array([snippet]) } + end + end + end + describe 'validation' do it { is_expected.to validate_presence_of(:author) } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index cff98cdb9fb..1c4b0fafc94 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -3280,6 +3280,9 @@ RSpec.describe User, feature_category: :user_profile do end describe 'username matching' do + let_it_be(:named_john) { create(:user, name: 'John', username: 'abcd') } + let_it_be(:username_john) { create(:user, name: 'John Doe', username: 'john') } + it 'returns users with a matching username' do expect(described_class.search(user.username)).to eq([user, user2]) end @@ -3300,6 +3303,10 @@ RSpec.describe User, feature_category: :user_profile do expect(described_class.search(user2.username.upcase)).to eq([user2]) end + it 'returns users with an exact matching username first' do + expect(described_class.search('John')).to eq([username_john, named_john]) + end + it 'returns users with a exact matching username shorter than 3 chars' do expect(described_class.search(user3.username)).to eq([user3]) end diff --git a/spec/requests/projects/merge_requests_controller_spec.rb b/spec/requests/projects/merge_requests_controller_spec.rb index 4af8f4fac7f..1033a51cd80 100644 --- a/spec/requests/projects/merge_requests_controller_spec.rb +++ b/spec/requests/projects/merge_requests_controller_spec.rb @@ -187,21 +187,6 @@ RSpec.describe Projects::MergeRequestsController, feature_category: :source_code expect(response).to have_gitlab_http_status(:ok) expect(Gitlab::Json.parse(response.body)['count']['all']).to eq(2) end - - context 'when the FF ci_fix_performance_pipelines_json_endpoint is disabled' do - before do - stub_feature_flags(ci_fix_performance_pipelines_json_endpoint: false) - end - - it 'returns the failed builds' do - get pipelines_project_merge_request_path(project, merge_request, format: :json) - - expect(response).to have_gitlab_http_status(:ok) - expect(Gitlab::Json.parse(response.body)['pipelines'].size).to eq(1) - expect(Gitlab::Json.parse(response.body)['pipelines'][0]['failed_builds_count']).to eq(2) - expect(Gitlab::Json.parse(response.body)['pipelines'][0]['failed_builds'].size).to eq(2) - end - end end private diff --git a/spec/serializers/ci/pipeline_entity_spec.rb b/spec/serializers/ci/pipeline_entity_spec.rb index 0fd9a12440f..e4ac8488c8c 100644 --- a/spec/serializers/ci/pipeline_entity_spec.rb +++ b/spec/serializers/ci/pipeline_entity_spec.rb @@ -256,7 +256,6 @@ RSpec.describe Ci::PipelineEntity, feature_category: :continuous_integration do project.add_maintainer(user) end - # Remove with `ci_fix_performance_pipelines_json_endpoint`. context 'when disable_failed_builds is true' do let(:options) { { disable_failed_builds: true } } diff --git a/spec/services/projects/destroy_service_spec.rb b/spec/services/projects/destroy_service_spec.rb index 0210e101e5f..a0064eadf13 100644 --- a/spec/services/projects/destroy_service_spec.rb +++ b/spec/services/projects/destroy_service_spec.rb @@ -472,6 +472,31 @@ RSpec.describe Projects::DestroyService, :aggregate_failures, :event_store_publi end end + context 'with related storage move records' do + context 'when project has active repository storage move records' do + let!(:project_repository_storage_move) { create(:project_repository_storage_move, :scheduled, container: project) } + + it 'does not delete the project' do + expect(destroy_project(project, user)).to be_falsey + + expect(project.delete_error).to eq "Couldn't remove the project. A project repository storage move is in progress. Try again when it's complete." + expect(project.pending_delete).to be_falsey + end + end + + context 'when project has active snippet storage move records' do + let(:project_snippet) { create(:project_snippet, project: project) } + let!(:snippet_repository_storage_move) { create(:snippet_repository_storage_move, :started, container: project_snippet) } + + it 'does not delete the project' do + expect(destroy_project(project, user)).to be_falsey + + expect(project.delete_error).to eq "Couldn't remove the project. A related snippet repository storage move is in progress. Try again when it's complete." + expect(project.pending_delete).to be_falsey + end + end + end + context 'repository removal' do describe '.trash_project_repositories!' do let(:trash_project_repositories!) { described_class.new(project, user, {}).send(:trash_project_repositories!) } diff --git a/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb b/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb index a9a13ddcd60..bb382ec511c 100644 --- a/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/repository_storage_movable_shared_examples.rb @@ -5,6 +5,19 @@ RSpec.shared_examples 'handles repository moves' do it { is_expected.to belong_to(:container) } end + describe 'scopes' do + describe '.scheduled_or_started' do + subject { described_class.scheduled_or_started } + + let!(:initial) { create(repository_storage_factory_key, state: 1) } + let!(:scheduled) { create(repository_storage_factory_key, state: 2) } + let!(:started) { create(repository_storage_factory_key, state: 3) } + let!(:finished) { create(repository_storage_factory_key, state: 4) } + + it { is_expected.to contain_exactly(scheduled, started) } + end + end + describe 'validations' do it { is_expected.to validate_presence_of(:container) } it { is_expected.to validate_presence_of(:state) } diff --git a/spec/views/search/show.html.haml_spec.rb b/spec/views/search/show.html.haml_spec.rb index 0158a9049b9..e6d2ef02c9a 100644 --- a/spec/views/search/show.html.haml_spec.rb +++ b/spec/views/search/show.html.haml_spec.rb @@ -29,13 +29,6 @@ RSpec.describe 'search/show', feature_category: :global_search do end context 'when the search page is opened' do - it 'displays the title' do - render - - expect(rendered).to have_selector('h1.page-title', text: 'Search') - expect(rendered).not_to have_selector('h1.page-title code') - end - it 'does not render the results partial' do render |