diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-12 00:09:40 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-01-12 00:09:40 +0300 |
commit | 213f46f188c29e9c442df61530110e172a7e819e (patch) | |
tree | 8544300e523c4e8cc3955406fa58e2d4b8ded773 /spec | |
parent | 33f7ef81fd6bcab7bbdf0bc3f37d337256fb11fb (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
54 files changed, 643 insertions, 217 deletions
diff --git a/spec/commands/metrics_server/metrics_server_spec.rb b/spec/commands/metrics_server/metrics_server_spec.rb index f93be1d9f88..310e31da045 100644 --- a/spec/commands/metrics_server/metrics_server_spec.rb +++ b/spec/commands/metrics_server/metrics_server_spec.rb @@ -70,7 +70,8 @@ RSpec.describe 'GitLab metrics server', :aggregate_failures do before do if use_golang_server stub_env('GITLAB_GOLANG_METRICS_SERVER', '1') - allow(Settings).to receive(:monitoring).and_return(config.dig('test', 'monitoring')) + allow(Settings).to receive(:monitoring).and_return( + Settingslogic.new(config.dig('test', 'monitoring'))) else config_file.write(YAML.dump(config)) config_file.close diff --git a/spec/components/previews/pajamas/button_component_preview.rb b/spec/components/previews/pajamas/button_component_preview.rb index c07d898d9cd..13a04dc0d63 100644 --- a/spec/components/previews/pajamas/button_component_preview.rb +++ b/spec/components/previews/pajamas/button_component_preview.rb @@ -3,7 +3,7 @@ module Pajamas class ButtonComponentPreview < ViewComponent::Preview # Button # ---- - # See its design reference [here](https://design.gitlab.com/components/banner). + # See its design reference [here](https://design.gitlab.com/components/button). # # @param category select {{ Pajamas::ButtonComponent::CATEGORY_OPTIONS }} # @param variant select {{ Pajamas::ButtonComponent::VARIANT_OPTIONS }} @@ -13,7 +13,7 @@ module Pajamas # @param loading toggle # @param block toggle # @param selected toggle - # @param icon text + # @param icon select [~, star-o, issue-closed, tanuki] # @param text text def default( # rubocop:disable Metrics/ParameterLists category: :primary, @@ -24,7 +24,7 @@ module Pajamas loading: false, block: false, selected: false, - icon: "pencil", + icon: nil, text: "Edit" ) render(Pajamas::ButtonComponent.new( diff --git a/spec/controllers/import/available_namespaces_controller_spec.rb b/spec/controllers/import/available_namespaces_controller_spec.rb deleted file mode 100644 index 26ea1d92189..00000000000 --- a/spec/controllers/import/available_namespaces_controller_spec.rb +++ /dev/null @@ -1,109 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Import::AvailableNamespacesController do - let_it_be(:user) { create(:user) } - - before do - sign_in(user) - end - - describe "GET index" do - context "when having group with role never allowed to create projects" do - using RSpec::Parameterized::TableSyntax - - where( - role: [:guest, :reporter], - default_project_creation_access: [::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS], - group_project_creation_level: [nil, ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS]) - - with_them do - before do - stub_application_setting(default_project_creation: default_project_creation_access) - end - - it "does not include group with access level #{params[:role]} in list" do - group = create(:group, project_creation_level: group_project_creation_level) - group.add_member(user, role) - get :index - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).not_to include({ - 'id' => group.id, - 'full_path' => group.full_path - }) - end - end - end - - context "when having group with role always allowed to create projects" do - using RSpec::Parameterized::TableSyntax - - where( - role: [:maintainer, :owner], - default_project_creation_access: [::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS], - group_project_creation_level: [nil, ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS, ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS]) - - with_them do - before do - stub_application_setting(default_project_creation: default_project_creation_access) - end - - it "does not include group with access level #{params[:role]} in list" do - group = create(:group, project_creation_level: group_project_creation_level) - group.add_member(user, role) - get :index - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).to include({ - 'id' => group.id, - 'full_path' => group.full_path - }) - end - end - end - - context "when having developer role" do - using RSpec::Parameterized::TableSyntax - - where(:default_project_creation_access, :project_creation_level, :is_visible) do - ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | nil | false - ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | true - ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | nil | true - ::Gitlab::Access::DEVELOPER_MAINTAINER_PROJECT_ACCESS | ::Gitlab::Access::MAINTAINER_PROJECT_ACCESS | false - end - - with_them do - before do - stub_application_setting(default_project_creation: default_project_creation_access) - end - - it "#{params[:is_visible] ? 'includes' : 'does not include'} group with access level #{params[:role]} in list" do - group = create(:group, project_creation_level: project_creation_level) - group.add_member(user, :developer) - - get :index - - expect(response).to have_gitlab_http_status(:ok) - expect(json_response).send(is_visible ? 'to' : 'not_to', include({ - 'id' => group.id, - 'full_path' => group.full_path - })) - end - end - end - - context "with an anonymous user" do - before do - sign_out(user) - end - - it "redirects to sign-in page" do - get :index - - expect(response).to redirect_to(new_user_session_path) - end - end - end -end diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index 62e8c600e9f..dddefbac163 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -1010,7 +1010,7 @@ RSpec.describe Projects::EnvironmentsController do expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| method.call(payload) - expect(payload[:metadata]['meta.environment.search']).to be_nil + expect(payload[:metadata]).not_to have_key('meta.environment.search') expect(payload[:action]).to eq("search") expect(payload[:controller]).to eq("Projects::EnvironmentsController") end @@ -1022,13 +1022,25 @@ RSpec.describe Projects::EnvironmentsController do expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| method.call(payload) - expect(payload[:metadata]['meta.environment.search']).to be_nil + expect(payload[:metadata]).not_to have_key('meta.environment.search') expect(payload[:action]).to eq("search") expect(payload[:controller]).to eq("Projects::EnvironmentsController") end get :search, params: environment_params(format: :json) end + + it 'logs params correctly when search params is empty string' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: "") + end end context 'when search_environment_logging feature is enabled' do @@ -1052,13 +1064,25 @@ RSpec.describe Projects::EnvironmentsController do expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| method.call(payload) - expect(payload[:metadata]['meta.environment.search']).to be_nil + expect(payload[:metadata]).not_to have_key('meta.environment.search') expect(payload[:action]).to eq("search") expect(payload[:controller]).to eq("Projects::EnvironmentsController") end get :search, params: environment_params(format: :json) end + + it 'logs params correctly when search params is empty string' do + expect(controller).to receive(:append_info_to_payload).and_wrap_original do |method, payload| + method.call(payload) + + expect(payload[:metadata]).not_to have_key('meta.environment.search') + expect(payload[:action]).to eq("search") + expect(payload[:controller]).to eq("Projects::EnvironmentsController") + end + + get :search, params: environment_params(format: :json, search: "") + end end end diff --git a/spec/factories/wiki_pages.rb b/spec/factories/wiki_pages.rb index 6f912a183e8..9b4c8a4fced 100644 --- a/spec/factories/wiki_pages.rb +++ b/spec/factories/wiki_pages.rb @@ -28,7 +28,7 @@ FactoryBot.define do # Clear our default @page, except when using build_stubbed after(:build) do |page| - page.instance_variable_set('@page', nil) + page.instance_variable_set(:@page, nil) end to_create do |page, evaluator| diff --git a/spec/features/abuse_report_spec.rb b/spec/features/abuse_report_spec.rb index f9fa3e6e109..1dfc86be628 100644 --- a/spec/features/abuse_report_spec.rb +++ b/spec/features/abuse_report_spec.rb @@ -68,7 +68,7 @@ RSpec.describe 'Abuse reports', :js, feature_category: :insider_threat do fill_and_submit_form - expect(page).to have_content 'User has already been reported for abuse' + expect(page).to have_content 'You have already reported this user' end it 'allows multiple users to report a user' do diff --git a/spec/features/dashboard/groups_list_spec.rb b/spec/features/dashboard/groups_list_spec.rb index b28e2ccf787..a45e0a58ed6 100644 --- a/spec/features/dashboard/groups_list_spec.rb +++ b/spec/features/dashboard/groups_list_spec.rb @@ -19,6 +19,8 @@ RSpec.describe 'Dashboard Groups page', :js, feature_category: :subgroups do page.find("[data-testid='group-#{group.id}-dropdown-button'").click end + it_behaves_like 'a dashboard page with sidebar', :dashboard_groups_path, :groups + it 'shows groups user is member of' do group.add_owner(user) nested_group.add_owner(user) diff --git a/spec/features/groups/new_group_page_spec.rb b/spec/features/groups/new_group_page_spec.rb index 662ef734299..a07c27331d9 100644 --- a/spec/features/groups/new_group_page_spec.rb +++ b/spec/features/groups/new_group_page_spec.rb @@ -10,6 +10,8 @@ RSpec.describe 'New group page', :js, feature_category: :subgroups do sign_in(user) end + it_behaves_like 'a dashboard page with sidebar', :new_group_path, :groups + describe 'new top level group alert' do context 'when a user visits the new group page' do it 'shows the new top level group alert' do diff --git a/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js b/spec/frontend/ci/pipeline_new/components/pipeline_new_form_spec.js index 56940e43365..cd16045f92d 100644 --- a/spec/frontend/pipeline_new/components/pipeline_new_form_spec.js +++ b/spec/frontend/ci/pipeline_new/components/pipeline_new_form_spec.js @@ -14,10 +14,10 @@ import { HTTP_STATUS_OK, } from '~/lib/utils/http_status'; import { redirectTo } from '~/lib/utils/url_utility'; -import PipelineNewForm from '~/pipeline_new/components/pipeline_new_form.vue'; -import ciConfigVariablesQuery from '~/pipeline_new/graphql/queries/ci_config_variables.graphql'; -import { resolvers } from '~/pipeline_new/graphql/resolvers'; -import RefsDropdown from '~/pipeline_new/components/refs_dropdown.vue'; +import PipelineNewForm from '~/ci/pipeline_new/components/pipeline_new_form.vue'; +import ciConfigVariablesQuery from '~/ci/pipeline_new/graphql/queries/ci_config_variables.graphql'; +import { resolvers } from '~/ci/pipeline_new/graphql/resolvers'; +import RefsDropdown from '~/ci/pipeline_new/components/refs_dropdown.vue'; import { mockCreditCardValidationRequiredError, mockCiConfigVariablesResponse, diff --git a/spec/frontend/pipeline_new/components/refs_dropdown_spec.js b/spec/frontend/ci/pipeline_new/components/refs_dropdown_spec.js index 975f39562be..cf8009e388f 100644 --- a/spec/frontend/pipeline_new/components/refs_dropdown_spec.js +++ b/spec/frontend/ci/pipeline_new/components/refs_dropdown_spec.js @@ -5,7 +5,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; -import RefsDropdown from '~/pipeline_new/components/refs_dropdown.vue'; +import RefsDropdown from '~/ci/pipeline_new/components/refs_dropdown.vue'; import { mockBranches, mockRefs, mockFilteredRefs, mockTags } from '../mock_data'; diff --git a/spec/frontend/pipeline_new/mock_data.js b/spec/frontend/ci/pipeline_new/mock_data.js index dfb643a0ba4..dfb643a0ba4 100644 --- a/spec/frontend/pipeline_new/mock_data.js +++ b/spec/frontend/ci/pipeline_new/mock_data.js diff --git a/spec/frontend/pipeline_new/utils/filter_variables_spec.js b/spec/frontend/ci/pipeline_new/utils/filter_variables_spec.js index 42bc6244456..d1b89704b58 100644 --- a/spec/frontend/pipeline_new/utils/filter_variables_spec.js +++ b/spec/frontend/ci/pipeline_new/utils/filter_variables_spec.js @@ -1,4 +1,4 @@ -import filterVariables from '~/pipeline_new/utils/filter_variables'; +import filterVariables from '~/ci/pipeline_new/utils/filter_variables'; import { mockVariables } from '../mock_data'; describe('Filter variables utility function', () => { diff --git a/spec/frontend/pipeline_new/utils/format_refs_spec.js b/spec/frontend/ci/pipeline_new/utils/format_refs_spec.js index 26dfa002a91..137a9339649 100644 --- a/spec/frontend/pipeline_new/utils/format_refs_spec.js +++ b/spec/frontend/ci/pipeline_new/utils/format_refs_spec.js @@ -1,9 +1,9 @@ -import { BRANCH_REF_TYPE, TAG_REF_TYPE } from '~/pipeline_new/constants'; +import { BRANCH_REF_TYPE, TAG_REF_TYPE } from '~/ci/pipeline_new/constants'; import { formatRefs, formatListBoxItems, searchByFullNameInListboxOptions, -} from '~/pipeline_new/utils/format_refs'; +} from '~/ci/pipeline_new/utils/format_refs'; import { mockBranchRefs, mockTagRefs } from '../mock_data'; describe('Format refs util', () => { diff --git a/spec/helpers/groups/observability_helper_spec.rb b/spec/helpers/groups/observability_helper_spec.rb index 9a1e88f310b..ee33a853f9c 100644 --- a/spec/helpers/groups/observability_helper_spec.rb +++ b/spec/helpers/groups/observability_helper_spec.rb @@ -91,7 +91,7 @@ RSpec.describe Groups::ObservabilityHelper do it 'returns the title for action: explore' do allow(helper).to receive(:params).and_return({ action: 'explore' }) - expect(helper.observability_page_title).to eq("Explore") + expect(helper.observability_page_title).to eq("Explore telemetry data") end it 'returns the title for action: datasources' do diff --git a/spec/helpers/projects_helper_spec.rb b/spec/helpers/projects_helper_spec.rb index fd1ec766740..14378685be7 100644 --- a/spec/helpers/projects_helper_spec.rb +++ b/spec/helpers/projects_helper_spec.rb @@ -206,7 +206,7 @@ RSpec.describe ProjectsHelper do it 'loads the pipeline status in batch' do helper.load_pipeline_status([project]) # Skip lazy loading of the `pipeline_status` attribute - pipeline_status = project.instance_variable_get('@pipeline_status') + pipeline_status = project.instance_variable_get(:@pipeline_status) expect(pipeline_status).to be_a(Gitlab::Cache::Ci::ProjectPipelineStatus) end diff --git a/spec/lib/api/helpers/packages_helpers_spec.rb b/spec/lib/api/helpers/packages_helpers_spec.rb index a3b21059334..d49aec1650d 100644 --- a/spec/lib/api/helpers/packages_helpers_spec.rb +++ b/spec/lib/api/helpers/packages_helpers_spec.rb @@ -32,7 +32,7 @@ RSpec.describe API::Helpers::PackagesHelpers do it 'calls authorize! with correct subject' do expect(helper).to receive(:authorize!).with(:read_package, have_attributes(id: subject.id, class: expected_class)) - expect(helper.send('authorize_read_package!', subject)).to eq nil + expect(helper.send(:authorize_read_package!, subject)).to eq nil end end end diff --git a/spec/lib/banzai/filter/references/reference_filter_spec.rb b/spec/lib/banzai/filter/references/reference_filter_spec.rb index 6d7396ef216..88404f2039d 100644 --- a/spec/lib/banzai/filter/references/reference_filter_spec.rb +++ b/spec/lib/banzai/filter/references/reference_filter_spec.rb @@ -189,9 +189,9 @@ RSpec.describe Banzai::Filter::References::ReferenceFilter do let(:filter) { described_class.new(document, project: project) } it 'updates all new nodes', :aggregate_failures do - filter.instance_variable_set('@nodes', nodes) + filter.instance_variable_set(:@nodes, nodes) - expect(filter).to receive(:call) { filter.instance_variable_set('@new_nodes', new_nodes) } + expect(filter).to receive(:call) { filter.instance_variable_set(:@new_nodes, new_nodes) } expect(filter).to receive(:with_update_nodes).and_call_original expect(filter).to receive(:update_nodes!).and_call_original @@ -212,7 +212,7 @@ RSpec.describe Banzai::Filter::References::ReferenceFilter do expect_next_instance_of(described_class) do |filter| expect(filter).to receive(:call_and_update_nodes).and_call_original expect(filter).to receive(:with_update_nodes).and_call_original - expect(filter).to receive(:call) { filter.instance_variable_set('@new_nodes', new_nodes) } + expect(filter).to receive(:call) { filter.instance_variable_set(:@new_nodes, new_nodes) } expect(filter).to receive(:update_nodes!).and_call_original end diff --git a/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb b/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb index 7280ca0b58e..faaaccfdfaf 100644 --- a/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb +++ b/spec/lib/gitlab/background_migration/batched_migration_job_spec.rb @@ -14,7 +14,7 @@ RSpec.describe Gitlab::BackgroundMigration::BatchedMigrationJob do expect(generic_instance.send(:batch_table)).to eq('projects') expect(generic_instance.send(:batch_column)).to eq('id') - expect(generic_instance.instance_variable_get('@job_arguments')).to eq(%w(x y)) + expect(generic_instance.instance_variable_get(:@job_arguments)).to eq(%w(x y)) expect(generic_instance.send(:connection)).to eq(connection) %i(start_id end_id sub_batch_size pause_ms).each do |attr| diff --git a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb index c78140a70b3..2dea0aef4cf 100644 --- a/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb +++ b/spec/lib/gitlab/cache/ci/project_pipeline_status_spec.rb @@ -24,7 +24,7 @@ RSpec.describe Gitlab::Cache::Ci::ProjectPipelineStatus, :clean_gitlab_redis_cac described_class.load_in_batch_for_projects([project]) # Don't call the accessor that would lazy load the variable - project_pipeline_status = project.instance_variable_get('@pipeline_status') + project_pipeline_status = project.instance_variable_get(:@pipeline_status) expect(project_pipeline_status).to be_a(described_class) expect(project_pipeline_status).to be_loaded diff --git a/spec/lib/gitlab/database/partitioning_spec.rb b/spec/lib/gitlab/database/partitioning_spec.rb index db5ca890155..855d0bc46a4 100644 --- a/spec/lib/gitlab/database/partitioning_spec.rb +++ b/spec/lib/gitlab/database/partitioning_spec.rb @@ -10,15 +10,15 @@ RSpec.describe Gitlab::Database::Partitioning do around do |example| previously_registered_models = described_class.registered_models.dup - described_class.instance_variable_set('@registered_models', Set.new) + described_class.instance_variable_set(:@registered_models, Set.new) previously_registered_tables = described_class.registered_tables.dup - described_class.instance_variable_set('@registered_tables', Set.new) + described_class.instance_variable_set(:@registered_tables, Set.new) example.run - described_class.instance_variable_set('@registered_models', previously_registered_models) - described_class.instance_variable_set('@registered_tables', previously_registered_tables) + described_class.instance_variable_set(:@registered_models, previously_registered_models) + described_class.instance_variable_set(:@registered_tables, previously_registered_tables) end describe '.register_models' do diff --git a/spec/lib/gitlab/github_gists_import/importer/gist_importer_spec.rb b/spec/lib/gitlab/github_gists_import/importer/gist_importer_spec.rb index 69a4d646562..6bfbfbdeddf 100644 --- a/spec/lib/gitlab/github_gists_import/importer/gist_importer_spec.rb +++ b/spec/lib/gitlab/github_gists_import/importer/gist_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::Importer::GistImporter, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::Importer::GistImporter, feature_category: :importers do subject { described_class.new(gist_object, user.id).execute } let_it_be(:user) { create(:user) } @@ -63,7 +63,7 @@ RSpec.describe Gitlab::GithubGistsImport::Importer::GistImporter, feature_catego expect(user.snippets.count).to eq(0) expect(result.error?).to eq(true) - expect(result.errors).to match_array(['Snippet max file count exceeded']) + expect(result.errors).to match_array(['Snippet maximum file count exceeded']) end end diff --git a/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb b/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb index 704999a99a9..d555a847ea5 100644 --- a/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb +++ b/spec/lib/gitlab/github_gists_import/importer/gists_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::Importer::GistsImporter, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::Importer::GistsImporter, feature_category: :importers do subject(:result) { described_class.new(user, token).execute } let_it_be(:user) { create(:user) } diff --git a/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb b/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb index 480aefb2c74..d6b47a1e837 100644 --- a/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb +++ b/spec/lib/gitlab/github_gists_import/representation/gist_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::Representation::Gist, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::Representation::Gist, feature_category: :importers do shared_examples 'a Gist' do it 'returns an instance of Gist' do expect(gist).to be_an_instance_of(described_class) diff --git a/spec/lib/gitlab/github_gists_import/status_spec.rb b/spec/lib/gitlab/github_gists_import/status_spec.rb index 4cbbbd430eb..d2016ef0248 100644 --- a/spec/lib/gitlab/github_gists_import/status_spec.rb +++ b/spec/lib/gitlab/github_gists_import/status_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::Status, :clean_gitlab_redis_cache, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::Status, :clean_gitlab_redis_cache, feature_category: :importers do subject(:import_status) { described_class.new(user.id) } let_it_be(:user) { create(:user) } diff --git a/spec/lib/gitlab/github_import/bulk_importing_spec.rb b/spec/lib/gitlab/github_import/bulk_importing_spec.rb index af31cb6c873..136ddb566aa 100644 --- a/spec/lib/gitlab/github_import/bulk_importing_spec.rb +++ b/spec/lib/gitlab/github_import/bulk_importing_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::BulkImporting, feature_category: :importer do +RSpec.describe Gitlab::GithubImport::BulkImporting, feature_category: :importers do let(:project) { instance_double(Project, id: 1) } let(:importer) { MyImporter.new(project, double) } let(:importer_class) do diff --git a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb index ad9ef4afddd..9e295ab215a 100644 --- a/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/labels_importer_spec.rb @@ -2,7 +2,8 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cache, feature_category: :importer do +RSpec.describe Gitlab::GithubImport::Importer::LabelsImporter, :clean_gitlab_redis_cache, +feature_category: :importers do let(:project) { create(:project, import_source: 'foo/bar') } let(:client) { double(:client) } let(:importer) { described_class.new(project, client) } diff --git a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb index 8667729d79b..47b9a41c364 100644 --- a/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/milestones_importer_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Importer::MilestonesImporter, :clean_gitlab_redis_cache, - feature_category: :importer do + feature_category: :importers do let(:project) { create(:project, import_source: 'foo/bar') } let(:client) { double(:client) } let(:importer) { described_class.new(project, client) } diff --git a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb index ccbe5b5fc50..fe4d3e9d90b 100644 --- a/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb +++ b/spec/lib/gitlab/github_import/importer/releases_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter, feature_category: :importer do +RSpec.describe Gitlab::GithubImport::Importer::ReleasesImporter, feature_category: :importers do let(:project) { create(:project) } let(:client) { double(:client) } let(:importer) { described_class.new(project, client) } diff --git a/spec/lib/gitlab/github_import/page_counter_spec.rb b/spec/lib/gitlab/github_import/page_counter_spec.rb index 511b19c00e5..ddb62cc8fad 100644 --- a/spec/lib/gitlab/github_import/page_counter_spec.rb +++ b/spec/lib/gitlab/github_import/page_counter_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache, feature_category: :importer do +RSpec.describe Gitlab::GithubImport::PageCounter, :clean_gitlab_redis_cache, feature_category: :importers do let(:project) { double(:project, id: 1) } let(:counter) { described_class.new(project, :issues) } diff --git a/spec/lib/gitlab/http_spec.rb b/spec/lib/gitlab/http_spec.rb index 929fd37ee40..57e4b4fc74b 100644 --- a/spec/lib/gitlab/http_spec.rb +++ b/spec/lib/gitlab/http_spec.rb @@ -51,10 +51,10 @@ RSpec.describe Gitlab::HTTP do end @original_net_http = Net.send(:remove_const, :HTTP) - @webmock_net_http = WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get('@webMockNetHTTP') + @webmock_net_http = WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_get(:@webMockNetHTTP) Net.send(:const_set, :HTTP, mocked_http) - WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_set('@webMockNetHTTP', mocked_http) + WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_set(:@webMockNetHTTP, mocked_http) # Reload Gitlab::NetHttpAdapter Gitlab.send(:remove_const, :NetHttpAdapter) @@ -72,7 +72,7 @@ RSpec.describe Gitlab::HTTP do after(:all) do Net.send(:remove_const, :HTTP) Net.send(:const_set, :HTTP, @original_net_http) - WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_set('@webMockNetHTTP', @webmock_net_http) + WebMock::HttpLibAdapters::NetHttpAdapter.instance_variable_set(:@webMockNetHTTP, @webmock_net_http) # Reload Gitlab::NetHttpAdapter Gitlab.send(:remove_const, :NetHttpAdapter) diff --git a/spec/lib/gitlab/rack_attack_spec.rb b/spec/lib/gitlab/rack_attack_spec.rb index 7ba4eab50c7..960a81b8c9d 100644 --- a/spec/lib/gitlab/rack_attack_spec.rb +++ b/spec/lib/gitlab/rack_attack_spec.rb @@ -35,7 +35,7 @@ RSpec.describe Gitlab::RackAttack, :aggregate_failures do allow(fake_rack_attack).to receive(:cache).and_return(fake_cache) allow(fake_cache).to receive(:store=) - fake_rack_attack.const_set('Request', fake_rack_attack_request) + fake_rack_attack.const_set(:Request, fake_rack_attack_request) stub_const("Rack::Attack", fake_rack_attack) end diff --git a/spec/lib/gitlab/submodule_links_spec.rb b/spec/lib/gitlab/submodule_links_spec.rb index e2bbda81780..12c322ea914 100644 --- a/spec/lib/gitlab/submodule_links_spec.rb +++ b/spec/lib/gitlab/submodule_links_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Gitlab::SubmoduleLinks do expect(subject.compare).to be_nil end - cache_store = links.instance_variable_get("@cache_store") + cache_store = links.instance_variable_get(:@cache_store) expect(cache_store[ref]).to eq({ "gitlab-foss" => "git@gitlab.com:gitlab-org/gitlab-foss.git" }) end diff --git a/spec/lib/gitlab/tracking_spec.rb b/spec/lib/gitlab/tracking_spec.rb index 99ca402616a..e79bb2ef129 100644 --- a/spec/lib/gitlab/tracking_spec.rb +++ b/spec/lib/gitlab/tracking_spec.rb @@ -10,11 +10,11 @@ RSpec.describe Gitlab::Tracking do stub_application_setting(snowplow_cookie_domain: '.gitfoo.com') stub_application_setting(snowplow_app_id: '_abc123_') - described_class.instance_variable_set("@tracker", nil) + described_class.instance_variable_set(:@tracker, nil) end after do - described_class.instance_variable_set("@tracker", nil) + described_class.instance_variable_set(:@tracker, nil) end describe '.options' do diff --git a/spec/lib/gitlab/utils/lazy_attributes_spec.rb b/spec/lib/gitlab/utils/lazy_attributes_spec.rb index 1ebc9b0d711..430b79c3063 100644 --- a/spec/lib/gitlab/utils/lazy_attributes_spec.rb +++ b/spec/lib/gitlab/utils/lazy_attributes_spec.rb @@ -47,9 +47,9 @@ RSpec.describe Gitlab::Utils::LazyAttributes do end it 'only calls the block once even if it returned `nil`', :aggregate_failures do - expect(instance.instance_variable_get('@number')).to receive(:call).once.and_call_original - expect(instance.instance_variable_get('@accessor_2')).to receive(:call).once.and_call_original - expect(instance.instance_variable_get('@incorrect_type')).to receive(:call).once.and_call_original + expect(instance.instance_variable_get(:@number)).to receive(:call).once.and_call_original + expect(instance.instance_variable_get(:@accessor_2)).to receive(:call).once.and_call_original + expect(instance.instance_variable_get(:@incorrect_type)).to receive(:call).once.and_call_original 2.times do instance.number diff --git a/spec/mailers/emails/imports_spec.rb b/spec/mailers/emails/imports_spec.rb new file mode 100644 index 00000000000..039113d3098 --- /dev/null +++ b/spec/mailers/emails/imports_spec.rb @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +require 'spec_helper' +require 'email_spec' + +RSpec.describe Emails::Imports, feature_category: :importers do + include EmailSpec::Matchers + + let(:errors) { { 'gist_id1' => "Title can't be blank", 'gist_id2' => 'Snippet maximum file count exceeded' } } + let(:user) { build_stubbed(:user) } + + describe '#github_gists_import_errors_email' do + subject { Notify.github_gists_import_errors_email('user_id', errors) } + + before do + allow(User).to receive(:find).and_return(user) + end + + it 'sends success email' do + expect(subject).to have_subject('GitHub Gists import finished with errors') + expect(subject).to have_content('GitHub gists that were not imported:') + expect(subject).to have_content("Gist with id gist_id1 failed due to error: Title can't be blank.") + expect(subject).to have_content('Gist with id gist_id2 failed due to error: Snippet maximum file count exceeded.') + end + + it_behaves_like 'appearance header and footer enabled' + it_behaves_like 'appearance header and footer not enabled' + end +end diff --git a/spec/metrics_server/metrics_server_spec.rb b/spec/metrics_server/metrics_server_spec.rb index 76ea9cd66ba..efa716754f1 100644 --- a/spec/metrics_server/metrics_server_spec.rb +++ b/spec/metrics_server/metrics_server_spec.rb @@ -99,20 +99,22 @@ RSpec.describe MetricsServer, feature_category: :application_performance do # ru context 'for Golang server' do let(:log_enabled) { false } let(:settings) do - { - 'web_exporter' => { - 'enabled' => true, - 'address' => 'localhost', - 'port' => '8083', - 'log_enabled' => log_enabled - }, - 'sidekiq_exporter' => { - 'enabled' => true, - 'address' => 'localhost', - 'port' => '8082', - 'log_enabled' => log_enabled + Settingslogic.new( + { + 'web_exporter' => { + 'enabled' => true, + 'address' => 'localhost', + 'port' => '8083', + 'log_enabled' => log_enabled + }, + 'sidekiq_exporter' => { + 'enabled' => true, + 'address' => 'localhost', + 'port' => '8082', + 'log_enabled' => log_enabled + } } - } + ) end let(:expected_port) { target == 'puma' ? '8083' : '8082' } @@ -175,11 +177,13 @@ RSpec.describe MetricsServer, feature_category: :application_performance do # ru context 'when TLS settings are present' do before do - %w(web_exporter sidekiq_exporter).each do |key| - settings[key]['tls_enabled'] = true - settings[key]['tls_cert_path'] = '/path/to/cert.pem' - settings[key]['tls_key_path'] = '/path/to/key.pem' - end + settings.web_exporter['tls_enabled'] = true + settings.web_exporter['tls_cert_path'] = '/path/to/cert.pem' + settings.web_exporter['tls_key_path'] = '/path/to/key.pem' + + settings.sidekiq_exporter['tls_enabled'] = true + settings.sidekiq_exporter['tls_cert_path'] = '/path/to/cert.pem' + settings.sidekiq_exporter['tls_key_path'] = '/path/to/key.pem' end it 'sets the correct environment variables' do @@ -300,12 +304,12 @@ RSpec.describe MetricsServer, feature_category: :application_performance do # ru end context 'for sidekiq' do - let(:settings) { { "sidekiq_exporter" => { "enabled" => true } } } + let(:settings) { Settingslogic.new({ "sidekiq_exporter" => { "enabled" => true } }) } before do allow(::Settings).to receive(:monitoring).and_return(settings) allow(Gitlab::Metrics::Exporter::SidekiqExporter).to receive(:instance).with( - settings['sidekiq_exporter'], gc_requests: true, synchronous: true + settings.sidekiq_exporter, gc_requests: true, synchronous: true ).and_return(exporter_double) end @@ -358,4 +362,28 @@ RSpec.describe MetricsServer, feature_category: :application_performance do # ru end end end + + describe '.name' do + subject { described_class.name(target) } + + context 'for puma' do + let(:target) { 'puma' } + + it { is_expected.to eq 'web_exporter' } + end + + context 'for sidekiq' do + let(:target) { 'sidekiq' } + + it { is_expected.to eq 'sidekiq_exporter' } + end + + context 'for invalid target' do + let(:target) { 'invalid' } + + it 'raises error' do + expect { subject }.to raise_error(RuntimeError, "Target must be one of [puma,sidekiq]") + end + end + end end diff --git a/spec/models/abuse_report_spec.rb b/spec/models/abuse_report_spec.rb index 29baccfe0ee..b07fafabbb5 100644 --- a/spec/models/abuse_report_spec.rb +++ b/spec/models/abuse_report_spec.rb @@ -32,8 +32,8 @@ RSpec.describe AbuseReport, feature_category: :insider_threat do it do is_expected.to validate_uniqueness_of(:user_id) - .scoped_to(:reporter_id) - .with_message('has already been reported for abuse') + .scoped_to([:reporter_id, :category]) + .with_message('You have already reported this user') end it { is_expected.to validate_length_of(:reported_from_url).is_at_most(512).allow_blank } diff --git a/spec/requests/api/bulk_imports_spec.rb b/spec/requests/api/bulk_imports_spec.rb index f943df7a034..4b375fb68be 100644 --- a/spec/requests/api/bulk_imports_spec.rb +++ b/spec/requests/api/bulk_imports_spec.rb @@ -198,6 +198,17 @@ RSpec.describe API::BulkImports, feature_category: :importers do end end + context 'when the destination_namespace is an empty string' do + it 'accepts the param and starts a new migration' do + params[:entities][0][:destination_namespace] = '' + + request + expect(response).to have_gitlab_http_status(:created) + + expect(json_response['status']).to eq('created') + end + end + context 'when the destination_slug is invalid' do it 'returns invalid error' do params[:entities][0][:destination_slug] = 'des?tin?atoi-slugg' diff --git a/spec/requests/groups/observability_controller_spec.rb b/spec/requests/groups/observability_controller_spec.rb index 148cf7dac6a..471cad40c90 100644 --- a/spec/requests/groups/observability_controller_spec.rb +++ b/spec/requests/groups/observability_controller_spec.rb @@ -71,20 +71,6 @@ RSpec.describe Groups::ObservabilityController, feature_category: :tracing do end end - describe 'GET #dashboards' do - let(:path) { group_observability_dashboards_path(group) } - let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/" } - - it_behaves_like 'observability route request' - end - - describe 'GET #manage' do - let(:path) { group_observability_manage_path(group) } - let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/dashboards" } - - it_behaves_like 'observability route request' - end - describe 'GET #explore' do let(:path) { group_observability_explore_path(group) } let(:expected_observability_path) { "#{observability_url}/-/#{group.id}/explore" } diff --git a/spec/routing/group_routing_spec.rb b/spec/routing/group_routing_spec.rb index 9a3de7729e6..3ba7d5ad871 100644 --- a/spec/routing/group_routing_spec.rb +++ b/spec/routing/group_routing_spec.rb @@ -72,10 +72,6 @@ RSpec.shared_examples 'groups routing' do expect(get("groups/#{group_path}/-/harbor/repositories/test/artifacts/test/tags")).to route_to('groups/harbor/tags#index', group_id: group_path, repository_id: 'test', artifact_id: 'test') end - it 'routes to the observability controller dashboards method' do - expect(get("groups/#{group_path}/-/observability/dashboards")).to route_to('groups/observability#dashboards', group_id: group_path) - end - it 'routes to the observability controller explore method' do expect(get("groups/#{group_path}/-/observability/explore")).to route_to('groups/observability#explore', group_id: group_path) end @@ -84,10 +80,6 @@ RSpec.shared_examples 'groups routing' do expect(get("groups/#{group_path}/-/observability/datasources")).to route_to('groups/observability#datasources', group_id: group_path) end - it 'routes to the observability controller manage method' do - expect(get("groups/#{group_path}/-/observability/manage")).to route_to('groups/observability#manage', group_id: group_path) - end - it 'routes to the usage quotas controller' do expect(get("groups/#{group_path}/-/usage_quotas")).to route_to("groups/usage_quotas#index", group_id: group_path) end diff --git a/spec/services/import/github/gists_import_service_spec.rb b/spec/services/import/github/gists_import_service_spec.rb index 4edb38145ed..32d04a580da 100644 --- a/spec/services/import/github/gists_import_service_spec.rb +++ b/spec/services/import/github/gists_import_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Import::Github::GistsImportService, feature_category: :importer do +RSpec.describe Import::Github::GistsImportService, feature_category: :importers do subject(:import) { described_class.new(user, client, params) } let_it_be(:user) { create(:user) } diff --git a/spec/services/merge_requests/refresh_service_spec.rb b/spec/services/merge_requests/refresh_service_spec.rb index 5174ceaaa82..0427debb4d1 100644 --- a/spec/services/merge_requests/refresh_service_spec.rb +++ b/spec/services/merge_requests/refresh_service_spec.rb @@ -138,7 +138,7 @@ RSpec.describe MergeRequests::RefreshService do refresh_service.execute(@oldrev, @newrev, 'refs/heads/master') expect { refresh_service.execute(@oldrev, @newrev, 'refs/heads/master') }.to change { - refresh_service.instance_variable_get("@source_merge_requests").first.merge_request_diff + refresh_service.instance_variable_get(:@source_merge_requests).first.merge_request_diff } end @@ -799,7 +799,7 @@ RSpec.describe MergeRequests::RefreshService do it 'does not mark as draft based on commits that do not belong to an MR' do allow(refresh_service).to receive(:find_new_commits) - refresh_service.instance_variable_set("@commits", + refresh_service.instance_variable_set(:@commits, [ double( id: 'aaaaaaa', diff --git a/spec/services/security/ci_configuration/dependency_scanning_create_service_spec.rb b/spec/services/security/ci_configuration/dependency_scanning_create_service_spec.rb new file mode 100644 index 00000000000..719a2cf24e9 --- /dev/null +++ b/spec/services/security/ci_configuration/dependency_scanning_create_service_spec.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Security::CiConfiguration::DependencyScanningCreateService, :snowplow, + feature_category: :dependency_scanning do + subject(:result) { described_class.new(project, user).execute } + + let(:branch_name) { 'set-dependency-scanning-config-1' } + + let(:snowplow_event) do + { + category: 'Security::CiConfiguration::DependencyScanningCreateService', + action: 'create', + label: '' + } + end + + include_examples 'services security ci configuration create service', true +end diff --git a/spec/services/security/ci_configuration/sast_create_service_spec.rb b/spec/services/security/ci_configuration/sast_create_service_spec.rb index c7e732dc79a..1e6dc367146 100644 --- a/spec/services/security/ci_configuration/sast_create_service_spec.rb +++ b/spec/services/security/ci_configuration/sast_create_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow do +RSpec.describe Security::CiConfiguration::SastCreateService, :snowplow, feature_category: :sast do subject(:result) { described_class.new(project, user, params).execute } let(:branch_name) { 'set-sast-config-1' } diff --git a/spec/support/helpers/navbar_structure_helper.rb b/spec/support/helpers/navbar_structure_helper.rb index 4e77e292410..48c6e590e1b 100644 --- a/spec/support/helpers/navbar_structure_helper.rb +++ b/spec/support/helpers/navbar_structure_helper.rb @@ -91,10 +91,8 @@ module NavbarStructureHelper new_nav_item: { nav_item: _('Observability'), nav_sub_items: [ - _('Dashboards'), - _('Explore'), - _('Data sources'), - _('Manage dashboards') + _('Explore telemetry data'), + _('Data sources') ] } ) diff --git a/spec/support/rspec_order_todo.yml b/spec/support/rspec_order_todo.yml index 025435b7929..13cd4d5755d 100644 --- a/spec/support/rspec_order_todo.yml +++ b/spec/support/rspec_order_todo.yml @@ -3560,7 +3560,6 @@ - './spec/controllers/groups/variables_controller_spec.rb' - './spec/controllers/health_check_controller_spec.rb' - './spec/controllers/help_controller_spec.rb' -- './spec/controllers/import/available_namespaces_controller_spec.rb' - './spec/controllers/import/bitbucket_controller_spec.rb' - './spec/controllers/import/bitbucket_server_controller_spec.rb' - './spec/controllers/import/bulk_imports_controller_spec.rb' diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index c1ad062ea75..9c7cf831241 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -234,6 +234,10 @@ RSpec.shared_context 'dashboard navbar structure' do nav_sub_items: [] }, { + nav_item: _("Groups"), + nav_sub_items: [] + }, + { nav_item: _("Issues"), nav_sub_items: [] }, diff --git a/spec/support/shared_examples/models/concerns/integrations/reset_secret_fields_shared_examples.rb b/spec/support/shared_examples/models/concerns/integrations/reset_secret_fields_shared_examples.rb index 873f858e432..c51a6c4f6fd 100644 --- a/spec/support/shared_examples/models/concerns/integrations/reset_secret_fields_shared_examples.rb +++ b/spec/support/shared_examples/models/concerns/integrations/reset_secret_fields_shared_examples.rb @@ -42,7 +42,7 @@ RSpec.shared_examples Integrations::ResetSecretFields do # Treat values as persisted integration.reset_updated_properties - integration.instance_variable_set('@old_data_fields', nil) if integration.supports_data_fields? + integration.instance_variable_set(:@old_data_fields, nil) if integration.supports_data_fields? end context 'when an exposing field has changed' do diff --git a/spec/support/shared_examples/quick_actions/issuable/close_quick_action_shared_examples.rb b/spec/support/shared_examples/quick_actions/issuable/close_quick_action_shared_examples.rb index ca6536444fd..d8690356f81 100644 --- a/spec/support/shared_examples/quick_actions/issuable/close_quick_action_shared_examples.rb +++ b/spec/support/shared_examples/quick_actions/issuable/close_quick_action_shared_examples.rb @@ -12,10 +12,10 @@ RSpec.shared_examples 'close quick action' do |issuable_type| before do case issuable_type when :merge_request - visit public_send('namespace_project_new_merge_request_path', project.namespace, project, new_url_opts) + visit public_send(:namespace_project_new_merge_request_path, project.namespace, project, new_url_opts) wait_for_all_requests when :issue - visit public_send('new_namespace_project_issue_path', project.namespace, project, new_url_opts) + visit public_send(:new_namespace_project_issue_path, project.namespace, project, new_url_opts) wait_for_all_requests end end diff --git a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb index 105c4247ff7..716be8c6210 100644 --- a/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb +++ b/spec/support/shared_examples/services/security/ci_configuration/create_service_shared_examples.rb @@ -88,6 +88,68 @@ RSpec.shared_examples_for 'services security ci configuration create service' do end end + context 'when existing ci config contains anchors/aliases' do + let(:params) { {} } + let(:unsupported_yaml) do + <<-YAML + image: python:latest + + cache: &global_cache + key: 'common-cache' + paths: + - .cache/pip + - venv/ + + test: + cache: + <<: *global_cache + key: 'custom-cache' + script: + - python setup.py test + - pip install tox flake8 # you can also use tox + - tox -e py36,flake8 + YAML + end + + it 'fails with error' do + expect(project).to receive(:ci_config_for).and_return(unsupported_yaml) + + expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, '.gitlab-ci.yml with aliases/anchors is not supported. Please change the CI configuration manually.') + end + end + + context 'when parsing existing ci config gives a Psych error' do + let(:params) { {} } + let(:invalid_yaml) do + <<-YAML + image: python:latest + + test: + script: + - python setup.py test + - pip install tox flake8 # you can also use tox + - tox -e py36,flake8 + YAML + end + + it 'fails with error' do + expect(project).to receive(:ci_config_for).and_return(invalid_yaml) + expect(YAML).to receive(:safe_load).and_raise(Psych::Exception) + + expect { result }.to raise_error(Gitlab::Graphql::Errors::MutationError, /merge request creation mutation failed/) + end + end + + context 'when parsing existing ci config gives any other error' do + let(:params) { {} } + let_it_be(:repository) { project.repository } + + it 'is successful' do + expect(repository).to receive(:root_ref_sha).and_raise(StandardError) + expect(result.status).to eq(:success) + end + end + unless skip_w_params context 'with parameters' do let(:params) { non_empty_params } diff --git a/spec/tooling/lib/tooling/view_to_js_mappings_spec.rb b/spec/tooling/lib/tooling/view_to_js_mappings_spec.rb new file mode 100644 index 00000000000..e4c5737df54 --- /dev/null +++ b/spec/tooling/lib/tooling/view_to_js_mappings_spec.rb @@ -0,0 +1,343 @@ +# frozen_string_literal: true + +require 'tempfile' +require_relative '../../../../tooling/lib/tooling/view_to_js_mappings' + +RSpec.describe Tooling::ViewToJsMappings, feature_category: :tooling do + # We set temporary folders, and those readers give access to those folder paths + attr_accessor :view_base_folder, :js_base_folder + + around do |example| + Dir.mktmpdir do |tmp_js_base_folder| + Dir.mktmpdir do |tmp_views_base_folder| + self.js_base_folder = tmp_js_base_folder + self.view_base_folder = tmp_views_base_folder + + example.run + end + end + end + + describe '#execute' do + let(:instance) do + described_class.new( + view_base_folder: view_base_folder, + js_base_folder: js_base_folder + ) + end + + let(:changed_files) { %W[#{view_base_folder}/index.html] } + + subject { instance.execute(changed_files) } + + context 'when no view files have been changed' do + before do + allow(instance).to receive(:view_files).and_return([]) + end + + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when some view files have been changed' do + before do + File.write("#{view_base_folder}/index.html", index_html_content) + end + + context 'when they do not contain the HTML attribute value we search for' do + let(:index_html_content) do + <<~FILE + Beginning of file + End of file + FILE + end + + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when they contain the HTML attribute value we search for' do + let(:index_html_content) do + <<~FILE + Beginning of file + + <a id="js-some-id">A link</a> + + End of file + FILE + end + + context 'when no matching JS files are found' do + it 'returns nothing' do + expect(subject).to match_array([]) + end + end + + context 'when some matching JS files are found' do + let(:index_js_content) do + <<~FILE + Beginning of file + + const isMainAwardsBlock = votesBlock.closest('#js-some-id.some_class').length; + + End of file + FILE + end + + before do + File.write("#{js_base_folder}/index.js", index_js_content) + end + + it 'returns the matching JS files' do + expect(subject).to match_array(["#{js_base_folder}/index.js"]) + end + end + end + end + + context 'when rails partials are included in the file' do + before do + File.write("#{view_base_folder}/index.html", index_html_content) + File.write("#{view_base_folder}/_my-partial.html.haml", partial_file_content) + File.write("#{js_base_folder}/index.js", index_js_content) + end + + let(:index_html_content) do + <<~FILE + Beginning of file + + = render 'my-partial' + + End of file + FILE + end + + let(:partial_file_content) do + <<~FILE + Beginning of file + + <a class="js-some-class">A link with class</a> + + End of file + FILE + end + + let(:index_js_content) do + <<~FILE + Beginning of file + + const isMainAwardsBlock = votesBlock.closest('.js-some-class').length; + + End of file + FILE + end + + it 'scans those partials for the HTML attribute value' do + expect(subject).to match_array(["#{js_base_folder}/index.js"]) + end + end + end + + describe '#view_files' do + subject { described_class.new(view_base_folder: view_base_folder).view_files(changed_files) } + + context 'when no files were changed' do + let(:changed_files) { [] } + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + + context 'when no view files were changed' do + let(:changed_files) { ["#{js_base_folder}/index.js"] } + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + + context 'when view files were changed' do + let(:changed_files) { ["#{js_base_folder}/index.js", "#{view_base_folder}/index.html"] } + + it 'returns the path to the view files' do + expect(subject).to match_array(["#{view_base_folder}/index.html"]) + end + end + end + + describe '#folders_for_available_editions' do + let(:base_folder_path) { 'app/views' } + + subject { described_class.new.folders_for_available_editions(base_folder_path) } + + context 'when FOSS' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(false) + allow(GitlabEdition).to receive(:jh?).and_return(false) + end + + it 'returns the correct paths' do + expect(subject).to match_array([base_folder_path]) + end + end + + context 'when EE' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(true) + allow(GitlabEdition).to receive(:jh?).and_return(false) + end + + it 'returns the correct paths' do + expect(subject).to eq([base_folder_path, "ee/#{base_folder_path}"]) + end + end + + context 'when JiHu' do + before do + allow(GitlabEdition).to receive(:ee?).and_return(true) + allow(GitlabEdition).to receive(:jh?).and_return(true) + end + + it 'returns the correct paths' do + expect(subject).to eq([base_folder_path, "ee/#{base_folder_path}", "jh/#{base_folder_path}"]) + end + end + end + + describe '#find_partials' do + subject { described_class.new(view_base_folder: view_base_folder).find_partials(file_path) } + + let(:file_path) { "#{view_base_folder}/my_html_file.html" } + + before do + File.write(file_path, file_content) + end + + context 'when the file includes a partial' do + context 'when the partial is in the same folder as the view file' do + before do + File.write("#{view_base_folder}/_my-partial.html.haml", 'Hello from partial') + end + + let(:file_content) do + <<~FILE + Beginning of file + + = render "my-partial" + + End of file + FILE + end + + it "returns the partial file path" do + expect(subject).to match_array(["#{view_base_folder}/_my-partial.html.haml"]) + end + end + + context 'when the partial is in a subfolder' do + before do + FileUtils.mkdir_p("#{view_base_folder}/subfolder") + + (1..12).each do |i| + FileUtils.touch "#{view_base_folder}/subfolder/_my-partial#{i}.html.haml" + end + end + + let(:file_content) do + <<~FILE + Beginning of file + + = render("subfolder/my-partial1") + = render "subfolder/my-partial2" + = render(partial: "subfolder/my-partial3") + = render partial: "subfolder/my-partial4" + = render(partial:"subfolder/my-partial5", path: 'else') + = render partial:"subfolder/my-partial6" + = render_if_exist("subfolder/my-partial7", path: 'else') + = render_if_exist "subfolder/my-partial8" + = render_if_exist(partial: "subfolder/my-partial9", path: 'else') + = render_if_exist partial: "subfolder/my-partial10" + = render_if_exist(partial:"subfolder/my-partial11", path: 'else') + = render_if_exist partial:"subfolder/my-partial12" + + End of file + FILE + end + + it "returns the partials file path" do + expect(subject).to match_array([ + "#{view_base_folder}/subfolder/_my-partial1.html.haml", + "#{view_base_folder}/subfolder/_my-partial2.html.haml", + "#{view_base_folder}/subfolder/_my-partial3.html.haml", + "#{view_base_folder}/subfolder/_my-partial4.html.haml", + "#{view_base_folder}/subfolder/_my-partial5.html.haml", + "#{view_base_folder}/subfolder/_my-partial6.html.haml", + "#{view_base_folder}/subfolder/_my-partial7.html.haml", + "#{view_base_folder}/subfolder/_my-partial8.html.haml", + "#{view_base_folder}/subfolder/_my-partial9.html.haml", + "#{view_base_folder}/subfolder/_my-partial10.html.haml", + "#{view_base_folder}/subfolder/_my-partial11.html.haml", + "#{view_base_folder}/subfolder/_my-partial12.html.haml" + ]) + end + end + + context 'when the file does not include a partial' do + let(:file_content) do + <<~FILE + Beginning of file + End of file + FILE + end + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + end + end + + describe '#find_pattern_in_file' do + let(:subject) { described_class.new.find_pattern_in_file(file.path, /pattern/) } + let(:file) { Tempfile.new('find_pattern_in_file') } + + before do + file.write(file_content) + file.close + end + + context 'when the file contains the pattern' do + let(:file_content) do + <<~FILE + Beginning of file + + pattern + pattern + pattern + + End of file + FILE + end + + it 'returns the pattern once' do + expect(subject).to match_array(%w[pattern]) + end + end + + context 'when the file does not contain the pattern' do + let(:file_content) do + <<~FILE + Beginning of file + End of file + FILE + end + + it 'returns an empty array' do + expect(subject).to match_array([]) + end + end + end +end diff --git a/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb b/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb index c4c19f2f9c5..cba6c578d11 100644 --- a/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/finish_import_worker_spec.rb @@ -2,13 +2,17 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, :clean_gitlab_redis_cache, feature_category: :importers do subject(:worker) { described_class.new } let_it_be(:user) { create(:user) } describe '#perform', :aggregate_failures do context 'when there are no remaining jobs' do + before do + allow(Gitlab::Cache::Import::Caching).to receive(:values_from_hash).and_return(nil) + end + it 'marks import status as finished' do waiter = instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 0) expect(Gitlab::JobWaiter).to receive(:new).and_return(waiter) @@ -19,6 +23,8 @@ RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category: expect(Gitlab::GithubImport::Logger) .to receive(:info) .with(user_id: user.id, message: 'GitHub Gists import finished') + expect(Notify).not_to receive(:github_gists_import_errors_email) + expect(Gitlab::Cache::Import::Caching).to receive(:expire).and_call_original worker.perform(user.id, waiter.key, waiter.jobs_remaining) end @@ -35,6 +41,33 @@ RSpec.describe Gitlab::GithubGistsImport::FinishImportWorker, feature_category: worker.perform(user.id, waiter.key, waiter.jobs_remaining) end end + + context 'when some gists were failed to import' do + let(:errors) { { '12345' => 'Snippet maximum file count exceeded.' } } + let(:waiter) { instance_double(Gitlab::JobWaiter, key: :key, jobs_remaining: 0) } + let(:mail_instance) { instance_double(ActionMailer::MessageDelivery, deliver_now: true) } + + before do + allow(Gitlab::Cache::Import::Caching).to receive(:values_from_hash).and_return(errors) + allow(Gitlab::JobWaiter).to receive(:new).and_return(waiter) + allow(waiter).to receive(:wait).with(described_class::BLOCKING_WAIT_TIME) + end + + it 'sends an email to user' do + expect_next_instance_of(Gitlab::GithubGistsImport::Status) do |status| + expect(status).to receive(:finish!) + end + expect(Gitlab::GithubImport::Logger) + .to receive(:info) + .with(user_id: user.id, message: 'GitHub Gists import finished') + expect(Notify).to receive(:github_gists_import_errors_email) + .with(user.id, errors).once.and_return(mail_instance) + expect(mail_instance).to receive(:deliver_now) + expect(Gitlab::Cache::Import::Caching).to receive(:expire).and_call_original + + worker.perform(user.id, waiter.key, waiter.jobs_remaining) + end + end end describe '.sidekiq_retries_exhausted' do diff --git a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb index dfc5084bb10..1c24cdcccae 100644 --- a/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/import_gist_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::ImportGistWorker, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::ImportGistWorker, feature_category: :importers do subject { described_class.new } let_it_be(:user) { create(:user) } diff --git a/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb b/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb index 523b7463a9d..220f2bb0c75 100644 --- a/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb +++ b/spec/workers/gitlab/github_gists_import/start_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubGistsImport::StartImportWorker, feature_category: :importer do +RSpec.describe Gitlab::GithubGistsImport::StartImportWorker, feature_category: :importers do subject(:worker) { described_class.new } let_it_be(:user) { create(:user) } |