diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-12 15:08:30 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-05-12 15:08:30 +0300 |
commit | cb3b9f9243555b0c26145e2992a9f01f7fa47bf5 (patch) | |
tree | 5fea3438f0c21330e2fba8c958cbc505810ab990 /spec | |
parent | 71d34aac9a0fae0507c265929767422391816b01 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
17 files changed, 124 insertions, 123 deletions
diff --git a/spec/controllers/projects/releases_controller_spec.rb b/spec/controllers/projects/releases_controller_spec.rb index 9dd18e58109..0dba7dab643 100644 --- a/spec/controllers/projects/releases_controller_spec.rb +++ b/spec/controllers/projects/releases_controller_spec.rb @@ -78,14 +78,12 @@ RSpec.describe Projects::ReleasesController do end describe 'GET #index' do - before do - get_index - end - context 'as html' do let(:format) { :html } it 'returns a text/html content_type' do + get_index + expect(response.media_type).to eq 'text/html' end @@ -95,6 +93,8 @@ RSpec.describe Projects::ReleasesController do let(:project) { private_project } it 'returns a redirect' do + get_index + expect(response).to have_gitlab_http_status(:redirect) end end @@ -104,11 +104,24 @@ RSpec.describe Projects::ReleasesController do let(:format) { :json } it 'returns an application/json content_type' do + get_index + expect(response.media_type).to eq 'application/json' end it "returns the project's releases as JSON, ordered by released_at" do - expect(response.body).to eq([release_2, release_1].to_json) + get_index + + expect(json_response.map { |release| release["id"] } ).to eq([release_2.id, release_1.id]) + end + + # TODO: remove in https://gitlab.com/gitlab-org/gitlab/-/issues/360903 + it "returns release sha when remove_sha_from_releases_json is disabled" do + stub_feature_flags(remove_sha_from_releases_json: false) + + get_index + + expect(json_response).to eq([release_2, release_1].as_json) end it_behaves_like 'common access controls' @@ -117,6 +130,8 @@ RSpec.describe Projects::ReleasesController do let(:project) { private_project } it 'returns a redirect' do + get_index + expect(response).to have_gitlab_http_status(:redirect) end end diff --git a/spec/features/projects/settings/user_manages_merge_requests_settings_spec.rb b/spec/features/projects/settings/user_manages_merge_requests_settings_spec.rb index 77be351f3d8..6aa59f72d2a 100644 --- a/spec/features/projects/settings/user_manages_merge_requests_settings_spec.rb +++ b/spec/features/projects/settings/user_manages_merge_requests_settings_spec.rb @@ -50,7 +50,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do context 'when Pipelines are initially enabled' do it 'shows the Merge Requests settings' do expect(page).to have_content 'Pipelines must succeed' - expect(page).to have_content 'All discussions must be resolved' + expect(page).to have_content 'All threads must be resolved' within('.sharing-permissions-form') do find('.project-feature-controls[data-for="project[project_feature_attributes][merge_requests_access_level]"] .gl-toggle').click @@ -58,7 +58,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do end expect(page).not_to have_content 'Pipelines must succeed' - expect(page).not_to have_content 'All discussions must be resolved' + expect(page).not_to have_content 'All threads must be resolved' end end @@ -70,7 +70,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do it 'shows the Merge Requests settings that do not depend on Builds feature' do expect(page).to have_content 'Pipelines must succeed' - expect(page).to have_content 'All discussions must be resolved' + expect(page).to have_content 'All threads must be resolved' within('.sharing-permissions-form') do find('.project-feature-controls[data-for="project[project_feature_attributes][builds_access_level]"] .gl-toggle').click @@ -78,7 +78,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do end expect(page).to have_content 'Pipelines must succeed' - expect(page).to have_content 'All discussions must be resolved' + expect(page).to have_content 'All threads must be resolved' end end end @@ -91,7 +91,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do it 'does not show the Merge Requests settings' do expect(page).not_to have_content 'Pipelines must succeed' - expect(page).not_to have_content 'All discussions must be resolved' + expect(page).not_to have_content 'All threads must be resolved' within('.sharing-permissions-form') do find('.project-feature-controls[data-for="project[project_feature_attributes][merge_requests_access_level]"] .gl-toggle').click @@ -99,7 +99,7 @@ RSpec.describe 'Projects > Settings > User manages merge request settings' do end expect(page).to have_content 'Pipelines must succeed' - expect(page).to have_content 'All discussions must be resolved' + expect(page).to have_content 'All threads must be resolved' end end diff --git a/spec/frontend/ci_secure_files/components/secure_files_list_spec.js b/spec/frontend/ci_secure_files/components/secure_files_list_spec.js index 042376c71e8..ea4e17e43bd 100644 --- a/spec/frontend/ci_secure_files/components/secure_files_list_spec.js +++ b/spec/frontend/ci_secure_files/components/secure_files_list_spec.js @@ -57,7 +57,7 @@ describe('SecureFilesList', () => { }); it('displays a table with expected headers', () => { - const headers = ['Filename', 'Permissions', 'Uploaded']; + const headers = ['Filename', 'Uploaded']; headers.forEach((header, i) => { expect(findHeaderAt(i).text()).toBe(header); }); @@ -69,8 +69,7 @@ describe('SecureFilesList', () => { const [secureFile] = secureFiles; expect(findCell(0, 0).text()).toBe(secureFile.name); - expect(findCell(0, 1).text()).toBe(secureFile.permissions); - expect(findCell(0, 2).find(TimeAgoTooltip).props('time')).toBe(secureFile.created_at); + expect(findCell(0, 1).find(TimeAgoTooltip).props('time')).toBe(secureFile.created_at); }); }); @@ -84,7 +83,7 @@ describe('SecureFilesList', () => { }); it('displays a table with expected headers', () => { - const headers = ['Filename', 'Permissions', 'Uploaded']; + const headers = ['Filename', 'Uploaded']; headers.forEach((header, i) => { expect(findHeaderAt(i).text()).toBe(header); }); diff --git a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb index 8ea6ceb7619..25edc9feea8 100644 --- a/spec/lib/bulk_imports/ndjson_pipeline_spec.rb +++ b/spec/lib/bulk_imports/ndjson_pipeline_spec.rb @@ -29,7 +29,7 @@ RSpec.describe BulkImports::NdjsonPipeline do subject { NdjsonPipelineClass.new(group, user) } it 'marks pipeline as ndjson' do - expect(NdjsonPipelineClass.ndjson_pipeline?).to eq(true) + expect(NdjsonPipelineClass.file_extraction_pipeline?).to eq(true) end describe '#deep_transform_relation!' do diff --git a/spec/lib/bulk_imports/pipeline_spec.rb b/spec/lib/bulk_imports/pipeline_spec.rb index 48c265d6118..e4ecf99dab0 100644 --- a/spec/lib/bulk_imports/pipeline_spec.rb +++ b/spec/lib/bulk_imports/pipeline_spec.rb @@ -63,7 +63,7 @@ RSpec.describe BulkImports::Pipeline do BulkImports::MyPipeline.transformer(klass, options) BulkImports::MyPipeline.loader(klass, options) BulkImports::MyPipeline.abort_on_failure! - BulkImports::MyPipeline.ndjson_pipeline! + BulkImports::MyPipeline.file_extraction_pipeline! expect(BulkImports::MyPipeline.get_extractor).to eq({ klass: klass, options: options }) @@ -75,7 +75,7 @@ RSpec.describe BulkImports::Pipeline do expect(BulkImports::MyPipeline.get_loader).to eq({ klass: klass, options: options }) expect(BulkImports::MyPipeline.abort_on_failure?).to eq(true) - expect(BulkImports::MyPipeline.ndjson_pipeline?).to eq(true) + expect(BulkImports::MyPipeline.file_extraction_pipeline?).to eq(true) end end end diff --git a/spec/lib/gitlab/database_importers/work_items/base_type_importer_spec.rb b/spec/lib/gitlab/database_importers/work_items/base_type_importer_spec.rb index 8c3d372cc55..d044170dc75 100644 --- a/spec/lib/gitlab/database_importers/work_items/base_type_importer_spec.rb +++ b/spec/lib/gitlab/database_importers/work_items/base_type_importer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter do - subject { described_class.import } + subject { described_class.upsert_types } it_behaves_like 'work item base types importer' end diff --git a/spec/models/ci/secure_file_spec.rb b/spec/models/ci/secure_file_spec.rb index f92db3fe8db..40ddafad013 100644 --- a/spec/models/ci/secure_file_spec.rb +++ b/spec/models/ci/secure_file_spec.rb @@ -25,7 +25,6 @@ RSpec.describe Ci::SecureFile do it { is_expected.to validate_presence_of(:checksum) } it { is_expected.to validate_presence_of(:file_store) } it { is_expected.to validate_presence_of(:name) } - it { is_expected.to validate_presence_of(:permissions) } it { is_expected.to validate_presence_of(:project_id) } context 'unique filename' do let_it_be(:project1) { create(:project) } @@ -49,12 +48,6 @@ RSpec.describe Ci::SecureFile do end end - describe '#permissions' do - it 'defaults to read_only file permssions' do - expect(subject.permissions).to eq('read_only') - end - end - describe '#checksum' do it 'computes SHA256 checksum on the file before encrypted' do expect(subject.checksum).to eq(Digest::SHA256.hexdigest(sample_file)) diff --git a/spec/models/event_spec.rb b/spec/models/event_spec.rb index f099015e63e..26e86207fd6 100644 --- a/spec/models/event_spec.rb +++ b/spec/models/event_spec.rb @@ -1040,6 +1040,36 @@ RSpec.describe Event do end end + describe '#has_no_project_and_group' do + context 'with project event' do + it 'returns false when the event has project' do + event = build(:event, project: create(:project)) + + expect(event.has_no_project_and_group?).to be false + end + + it 'returns true when the event has no project' do + event = build(:event, project: nil) + + expect(event.has_no_project_and_group?).to be true + end + end + + context 'with group event' do + it 'returns false when the event has group' do + event = build(:event, group: create(:group)) + + expect(event.has_no_project_and_group?).to be false + end + + it 'returns true when the event has no group' do + event = build(:event, group: nil) + + expect(event.has_no_project_and_group?).to be true + end + end + end + def create_push_event(project, user) event = create(:push_event, project: project, author: user) diff --git a/spec/models/merge_request_spec.rb b/spec/models/merge_request_spec.rb index 14cad1174ef..d40c78b5b60 100644 --- a/spec/models/merge_request_spec.rb +++ b/spec/models/merge_request_spec.rb @@ -3540,50 +3540,6 @@ RSpec.describe MergeRequest, factory_default: :keep do end end - describe "#legacy_environments" do - subject { merge_request.legacy_environments } - - let(:merge_request) { create(:merge_request, source_branch: 'feature', target_branch: 'master') } - let(:project) { merge_request.project } - - let(:pipeline) do - create(:ci_pipeline, - source: :merge_request_event, - merge_request: merge_request, project: project, - sha: merge_request.diff_head_sha, - merge_requests_as_head_pipeline: [merge_request]) - end - - let!(:job) { create(:ci_build, :with_deployment, :start_review_app, pipeline: pipeline, project: project) } - - it 'returns environments' do - is_expected.to eq(pipeline.environments_in_self_and_descendants.to_a) - expect(subject.count).to be(1) - end - - context 'when pipeline is not associated with environments' do - let!(:job) { create(:ci_build, pipeline: pipeline, project: project) } - - it 'returns empty array' do - is_expected.to be_empty - end - end - - context 'when pipeline is not a pipeline for merge request' do - let(:pipeline) do - create(:ci_pipeline, - project: project, - ref: 'feature', - sha: merge_request.diff_head_sha, - merge_requests_as_head_pipeline: [merge_request]) - end - - it 'returns empty relation' do - is_expected.to be_empty - end - end - end - describe "#reload_diff" do it 'calls MergeRequests::ReloadDiffsService#execute with correct params' do user = create(:user) diff --git a/spec/requests/api/ci/secure_files_spec.rb b/spec/requests/api/ci/secure_files_spec.rb index 6de6d1ef222..6f16fe5460b 100644 --- a/spec/requests/api/ci/secure_files_spec.rb +++ b/spec/requests/api/ci/secure_files_spec.rb @@ -143,7 +143,6 @@ RSpec.describe API::Ci::SecureFiles do expect(response).to have_gitlab_http_status(:ok) expect(json_response['name']).to eq(secure_file.name) - expect(json_response['permissions']).to eq(secure_file.permissions) end it 'responds with 404 Not Found if requesting non-existing secure file' do @@ -159,7 +158,6 @@ RSpec.describe API::Ci::SecureFiles do expect(response).to have_gitlab_http_status(:ok) expect(json_response['name']).to eq(secure_file.name) - expect(json_response['permissions']).to eq(secure_file.permissions) end end @@ -250,12 +248,11 @@ RSpec.describe API::Ci::SecureFiles do context 'authenticated user with admin permissions' do it 'creates a secure file' do expect do - post api("/projects/#{project.id}/secure_files", maintainer), params: file_params.merge(permissions: 'execute') + post api("/projects/#{project.id}/secure_files", maintainer), params: file_params end.to change {project.secure_files.count}.by(1) expect(response).to have_gitlab_http_status(:created) expect(json_response['name']).to eq('upload-keystore.jks') - expect(json_response['permissions']).to eq('execute') expect(json_response['checksum']).to eq(secure_file.checksum) expect(json_response['checksum_algorithm']).to eq('sha256') @@ -267,14 +264,6 @@ RSpec.describe API::Ci::SecureFiles do expect(Time.parse(json_response['created_at'])).to be_like_time(secure_file.created_at) end - it 'creates a secure file with read_only permissions by default' do - expect do - post api("/projects/#{project.id}/secure_files", maintainer), params: file_params - end.to change {project.secure_files.count}.by(1) - - expect(json_response['permissions']).to eq('read_only') - end - it 'uploads and downloads a secure file' do post api("/projects/#{project.id}/secure_files", maintainer), params: file_params @@ -327,15 +316,6 @@ RSpec.describe API::Ci::SecureFiles do expect(json_response['message']['name']).to include('has already been taken') end - it 'returns an error when an unexpected permission is supplied' do - expect do - post api("/projects/#{project.id}/secure_files", maintainer), params: file_params.merge(permissions: 'foo') - end.not_to change { project.secure_files.count } - - expect(response).to have_gitlab_http_status(:bad_request) - expect(json_response['error']).to eq('permissions does not have a valid value') - end - it 'returns an error when an unexpected validation failure happens' do allow_next_instance_of(Ci::SecureFile) do |instance| allow(instance).to receive(:valid?).and_return(false) diff --git a/spec/serializers/release_serializer_spec.rb b/spec/serializers/release_serializer_spec.rb index 518d281f370..b31172c3a50 100644 --- a/spec/serializers/release_serializer_spec.rb +++ b/spec/serializers/release_serializer_spec.rb @@ -19,6 +19,10 @@ RSpec.describe ReleaseSerializer do it 'serializes the label object' do expect(subject[:tag]).to eq resource.tag end + + it 'does not expose git-sha as sensitive information' do + expect(subject[:sha]).to be_nil + end end context 'when multiple objects are being serialized' do diff --git a/spec/services/environments/stop_service_spec.rb b/spec/services/environments/stop_service_spec.rb index 6cfbd765785..afbc0ba70f9 100644 --- a/spec/services/environments/stop_service_spec.rb +++ b/spec/services/environments/stop_service_spec.rb @@ -223,18 +223,6 @@ RSpec.describe Environments::StopService do expect(prepare_staging_job.persisted_environment.state).to eq('available') end - - context 'when fix_related_environments_for_merge_requests feature flag is disabled' do - before do - stub_feature_flags(fix_related_environments_for_merge_requests: false) - end - - it 'stops unrelated environments too' do - subject - - expect(prepare_staging_job.persisted_environment.state).to eq('stopped') - end - end end end diff --git a/spec/services/issues/create_service_spec.rb b/spec/services/issues/create_service_spec.rb index 6b7b72d83fc..3934ca04a00 100644 --- a/spec/services/issues/create_service_spec.rb +++ b/spec/services/issues/create_service_spec.rb @@ -47,6 +47,14 @@ RSpec.describe Issues::CreateService do due_date: Date.tomorrow } end + it 'works if base work item types were not created yet' do + WorkItems::Type.delete_all + + expect do + issue + end.to change(Issue, :count).by(1) + end + it 'creates the issue with the given params' do expect(Issuable::CommonSystemNotesService).to receive_message_chain(:new, :execute) diff --git a/spec/support/helpers/test_env.rb b/spec/support/helpers/test_env.rb index d81d0d436a1..11f469c1d27 100644 --- a/spec/support/helpers/test_env.rb +++ b/spec/support/helpers/test_env.rb @@ -374,7 +374,7 @@ module TestEnv end def seed_db - Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.import + Gitlab::DatabaseImporters::WorkItems::BaseTypeImporter.upsert_types end private diff --git a/spec/support/shared_examples/models/wiki_shared_examples.rb b/spec/support/shared_examples/models/wiki_shared_examples.rb index 50062456d49..6f17231a040 100644 --- a/spec/support/shared_examples/models/wiki_shared_examples.rb +++ b/spec/support/shared_examples/models/wiki_shared_examples.rb @@ -676,16 +676,6 @@ RSpec.shared_examples 'wiki model' do end end end - - context 'when feature flag :gitaly_replace_wiki_update_page is disabled' do - before do - stub_feature_flags(gitaly_replace_wiki_update_page: false) - end - - it_behaves_like 'update_page tests' do - include_context 'common examples' - end - end end describe '#delete_page' do diff --git a/spec/support/shared_examples/work_item_base_types_importer.rb b/spec/support/shared_examples/work_item_base_types_importer.rb index 68e37171ea2..593670ac4b8 100644 --- a/spec/support/shared_examples/work_item_base_types_importer.rb +++ b/spec/support/shared_examples/work_item_base_types_importer.rb @@ -1,10 +1,48 @@ # frozen_string_literal: true RSpec.shared_examples 'work item base types importer' do - it 'creates all base work item types' do - # Fixtures need to run on a pristine DB, but the test suite preloads the base types before(:suite) + it "creates all base work item types if they don't exist" do WorkItems::Type.delete_all expect { subject }.to change(WorkItems::Type, :count).from(0).to(WorkItems::Type::BASE_TYPES.count) + + types_in_db = WorkItems::Type.all.map { |type| type.slice(:base_type, :icon_name, :name).symbolize_keys } + expected_types = WorkItems::Type::BASE_TYPES.map do |type, attributes| + attributes.slice(:icon_name, :name).merge(base_type: type.to_s) + end + + expect(types_in_db).to match_array(expected_types) + expect(WorkItems::Type.all).to all(be_valid) + end + + it 'upserts base work item types if they already exist' do + first_type = WorkItems::Type.first + original_name = first_type.name + + first_type.update!(name: original_name.upcase) + + expect do + subject + first_type.reload + end.to not_change(WorkItems::Type, :count).and( + change(first_type, :name).from(original_name.upcase).to(original_name) + ) + end + + it 'executes a single INSERT query' do + expect { subject }.to make_queries_matching(/INSERT/, 1) + end + + context 'when some base types exist' do + before do + WorkItems::Type.limit(1).delete_all + end + + it 'inserts all types and does nothing if some already existed' do + expect { subject }.to make_queries_matching(/INSERT/, 1).and( + change(WorkItems::Type, :count).by(1) + ) + expect(WorkItems::Type.count).to eq(WorkItems::Type::BASE_TYPES.count) + end end end diff --git a/spec/workers/bulk_imports/pipeline_worker_spec.rb b/spec/workers/bulk_imports/pipeline_worker_spec.rb index 3578fec5bc0..209ae8862b6 100644 --- a/spec/workers/bulk_imports/pipeline_worker_spec.rb +++ b/spec/workers/bulk_imports/pipeline_worker_spec.rb @@ -9,7 +9,7 @@ RSpec.describe BulkImports::PipelineWorker do def run; end - def self.ndjson_pipeline? + def self.file_extraction_pipeline? false end end @@ -222,14 +222,14 @@ RSpec.describe BulkImports::PipelineWorker do end end - context 'when ndjson pipeline' do - let(:ndjson_pipeline) do + context 'when file extraction pipeline' do + let(:file_extraction_pipeline) do Class.new do def initialize(_); end def run; end - def self.ndjson_pipeline? + def self.file_extraction_pipeline? true end @@ -249,11 +249,11 @@ RSpec.describe BulkImports::PipelineWorker do end before do - stub_const('NdjsonPipeline', ndjson_pipeline) + stub_const('NdjsonPipeline', file_extraction_pipeline) allow_next_instance_of(BulkImports::Groups::Stage) do |instance| allow(instance).to receive(:pipelines) - .and_return([[0, ndjson_pipeline]]) + .and_return([[0, file_extraction_pipeline]]) end end @@ -278,7 +278,7 @@ RSpec.describe BulkImports::PipelineWorker do expect(described_class) .to receive(:perform_in) .with( - described_class::NDJSON_PIPELINE_PERFORM_DELAY, + described_class::FILE_EXTRACTION_PIPELINE_PERFORM_DELAY, pipeline_tracker.id, pipeline_tracker.stage, entity.id |