diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/support/shared_contexts | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/support/shared_contexts')
13 files changed, 127 insertions, 27 deletions
diff --git a/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb b/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb index b10844320d0..07012914a4d 100644 --- a/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb +++ b/spec/support/shared_contexts/features/integrations/project_integrations_shared_context.rb @@ -3,8 +3,8 @@ RSpec.shared_context 'project service activation' do include_context 'integration activation' - let(:project) { create(:project) } - let(:user) { create(:user) } + let_it_be(:project) { create(:project) } + let_it_be(:user) { create(:user) } before do project.add_maintainer(user) diff --git a/spec/support/shared_contexts/fixtures/analytics_shared_context.rb b/spec/support/shared_contexts/fixtures/analytics_shared_context.rb new file mode 100644 index 00000000000..13d3697a378 --- /dev/null +++ b/spec/support/shared_contexts/fixtures/analytics_shared_context.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +RSpec.shared_context 'Analytics fixtures shared context' do + include JavaScriptFixturesHelpers + + let_it_be(:group) { create(:group) } + let_it_be(:project) { create(:project, :repository, namespace: group) } + let_it_be(:user) { create(:user, :admin) } + let_it_be(:milestone) { create(:milestone, project: project) } + + let(:issue) { create(:issue, project: project, created_at: 4.days.ago) } + let(:issue_1) { create(:issue, project: project, created_at: 5.days.ago) } + let(:issue_2) { create(:issue, project: project, created_at: 4.days.ago, milestone: milestone) } + let(:issue_3) { create(:issue, project: project, created_at: 3.days.ago, milestone: milestone) } + + let(:mr_1) { create(:merge_request, source_project: project, allow_broken: true, created_at: 20.days.ago) } + let(:mr_2) { create(:merge_request, source_project: project, allow_broken: true, created_at: 19.days.ago) } + + let(:pipeline_1) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_1.source_branch, sha: mr_1.source_branch_sha, head_pipeline_of: mr_1) } + let(:pipeline_2) { create(:ci_empty_pipeline, status: 'created', project: project, ref: mr_2.source_branch, sha: mr_2.source_branch_sha, head_pipeline_of: mr_2) } + + let(:build_1) { create(:ci_build, :success, pipeline: pipeline_1, author: user) } + let(:build_2) { create(:ci_build, :success, pipeline: pipeline_2, author: user) } + + let(:params) { { created_after: 3.months.ago, created_before: Time.now, group_id: group.full_path } } + + def prepare_cycle_analytics_data + group.add_maintainer(user) + project.add_maintainer(user) + + create_commit_referencing_issue(issue_1) + create_commit_referencing_issue(issue_2) + + create_merge_request_closing_issue(user, project, issue_1) + create_merge_request_closing_issue(user, project, issue_2) + merge_merge_requests_closing_issue(user, project, issue_3) + end + + def create_deployment + deploy_master(user, project, environment: 'staging') + deploy_master(user, project) + end + + def update_metrics + issue_1.metrics.update!(first_added_to_board_at: 3.days.ago, first_mentioned_in_commit_at: 2.days.ago) + issue_2.metrics.update!(first_added_to_board_at: 2.days.ago, first_mentioned_in_commit_at: 1.day.ago) + + mr_1.metrics.update!({ + merged_at: 5.days.ago, + first_deployed_to_production_at: 1.day.ago, + latest_build_started_at: 5.days.ago, + latest_build_finished_at: 1.day.ago, + pipeline: build_1.pipeline + }) + + mr_2.metrics.update!({ + merged_at: 10.days.ago, + first_deployed_to_production_at: 5.days.ago, + latest_build_started_at: 9.days.ago, + latest_build_finished_at: 7.days.ago, + pipeline: build_2.pipeline + }) + end + + before do + stub_licensed_features(cycle_analytics_for_groups: true) + + prepare_cycle_analytics_data + end +end diff --git a/spec/support/shared_contexts/graphql/requests/packages_shared_context.rb b/spec/support/shared_contexts/graphql/requests/packages_shared_context.rb index 334b11c9f6e..645ea742f07 100644 --- a/spec/support/shared_contexts/graphql/requests/packages_shared_context.rb +++ b/spec/support/shared_contexts/graphql/requests/packages_shared_context.rb @@ -9,6 +9,7 @@ RSpec.shared_context 'package details setup' do let(:depth) { 3 } let(:excluded) { %w[metadata apiFuzzingCiConfiguration pipeline packageFiles] } let(:package_files) { all_graphql_fields_for('PackageFile') } + let(:dependency_links) { all_graphql_fields_for('PackageDependencyLink') } let(:user) { project.owner } let(:package_details) { graphql_data_at(:package) } let(:metadata_response) { graphql_data_at(:package, :metadata) } @@ -28,6 +29,11 @@ RSpec.shared_context 'package details setup' do #{package_files} } } + dependencyLinks { + nodes { + #{dependency_links} + } + } FIELDS end end diff --git a/spec/support/shared_contexts/issuable/merge_request_shared_context.rb b/spec/support/shared_contexts/issuable/merge_request_shared_context.rb index debcd9a3054..2c56411ca4c 100644 --- a/spec/support/shared_contexts/issuable/merge_request_shared_context.rb +++ b/spec/support/shared_contexts/issuable/merge_request_shared_context.rb @@ -11,6 +11,7 @@ RSpec.shared_context 'merge request show action' do before do allow(view).to receive(:experiment_enabled?).and_return(false) allow(view).to receive(:current_user).and_return(user) + allow(view).to receive(:can_admin_project_member?) assign(:project, project) assign(:merge_request, merge_request) assign(:note, note) diff --git a/spec/support/shared_contexts/issuable/project_shared_context.rb b/spec/support/shared_contexts/issuable/project_shared_context.rb index 5e5f6f2b7a6..b1bb9d80d78 100644 --- a/spec/support/shared_contexts/issuable/project_shared_context.rb +++ b/spec/support/shared_contexts/issuable/project_shared_context.rb @@ -12,5 +12,6 @@ RSpec.shared_context 'project show action' do stub_template 'shared/issuable/_sidebar' => '' stub_template 'projects/issues/_discussion' => '' allow(view).to receive(:user_status).and_return('') + allow(view).to receive(:can_admin_project_member?) end end diff --git a/spec/support/shared_contexts/lib/api/helpers/packages/dependency_proxy_helpers_shared_context.rb b/spec/support/shared_contexts/lib/api/helpers/packages/dependency_proxy_helpers_shared_context.rb new file mode 100644 index 00000000000..7c8b6250d24 --- /dev/null +++ b/spec/support/shared_contexts/lib/api/helpers/packages/dependency_proxy_helpers_shared_context.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +RSpec.shared_context 'dependency proxy helpers context' do + def allow_fetch_application_setting(attribute:, return_value:) + attributes = double + allow(::Gitlab::CurrentSettings.current_application_settings).to receive(:attributes).and_return(attributes) + allow(attributes).to receive(:fetch).with(attribute, false).and_return(return_value) + end +end diff --git a/spec/support/shared_contexts/lib/gitlab/database/background_migration_job_shared_context.rb b/spec/support/shared_contexts/lib/gitlab/database/background_migration_job_shared_context.rb new file mode 100644 index 00000000000..382eb796f8e --- /dev/null +++ b/spec/support/shared_contexts/lib/gitlab/database/background_migration_job_shared_context.rb @@ -0,0 +1,21 @@ +# frozen_string_literal: true + +RSpec.shared_context 'background migration job class' do + let!(:job_class_name) { 'TestJob' } + let!(:job_class) { Class.new } + let!(:job_perform_method) do + ->(*arguments) do + Gitlab::Database::BackgroundMigrationJob.mark_all_as_succeeded( + # Value is 'TestJob' defined by :job_class_name in the let! above. + # Scoping prohibits us from directly referencing job_class_name. + RSpec.current_example.example_group_instance.job_class_name, + arguments + ) + end + end + + before do + job_class.define_method(:perform, job_perform_method) + expect(Gitlab::BackgroundMigration).to receive(:migration_class_for).with(job_class_name).at_least(:once) { job_class } + end +end diff --git a/spec/support/shared_contexts/load_balancing_configuration_shared_context.rb b/spec/support/shared_contexts/load_balancing_configuration_shared_context.rb deleted file mode 100644 index a61b8e9a074..00000000000 --- a/spec/support/shared_contexts/load_balancing_configuration_shared_context.rb +++ /dev/null @@ -1,19 +0,0 @@ -# frozen_string_literal: true - -RSpec.shared_context 'clear DB Load Balancing configuration' do - def clear_load_balancing_configuration - proxy = ::Gitlab::Database::LoadBalancing.instance_variable_get(:@proxy) - proxy.load_balancer.release_host if proxy - ::Gitlab::Database::LoadBalancing.instance_variable_set(:@proxy, nil) - - ::Gitlab::Database::LoadBalancing::Session.clear_session - end - - around do |example| - clear_load_balancing_configuration - - example.run - - clear_load_balancing_configuration - end -end diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index b7eb03de8f0..8ae0885056e 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -176,6 +176,15 @@ RSpec.shared_context 'group navbar structure' do } end + let(:ci_cd_nav_item) do + { + nav_item: _('CI/CD'), + nav_sub_items: [ + s_('Runners|Runners') + ] + } + end + let(:issues_nav_items) do [ _('List'), diff --git a/spec/support/shared_contexts/policies/group_policy_shared_context.rb b/spec/support/shared_contexts/policies/group_policy_shared_context.rb index b0d7274269b..b432aa24bb8 100644 --- a/spec/support/shared_contexts/policies/group_policy_shared_context.rb +++ b/spec/support/shared_contexts/policies/group_policy_shared_context.rb @@ -38,12 +38,14 @@ RSpec.shared_context 'GroupPolicy context' do delete_metrics_dashboard_annotation update_metrics_dashboard_annotation create_custom_emoji + create_package create_package_settings ] end let(:maintainer_permissions) do %i[ + destroy_package create_projects read_cluster create_cluster update_cluster admin_cluster add_cluster ] diff --git a/spec/support/shared_contexts/requests/api/conan_packages_shared_context.rb b/spec/support/shared_contexts/requests/api/conan_packages_shared_context.rb index c69a987c00d..b90270356f8 100644 --- a/spec/support/shared_contexts/requests/api/conan_packages_shared_context.rb +++ b/spec/support/shared_contexts/requests/api/conan_packages_shared_context.rb @@ -11,7 +11,7 @@ RSpec.shared_context 'conan api setup' do let_it_be(:deploy_token) { create(:deploy_token, read_package_registry: true, write_package_registry: true) } let(:project) { package.project } - let(:job) { create(:ci_build, :running, user: user, project: project) } + let(:job) { create(:ci_build, :running, user: user) } let(:job_token) { job.token } let(:auth_token) { personal_access_token.token } let(:project_deploy_token) { create(:project_deploy_token, deploy_token: deploy_token, project: project) } diff --git a/spec/support/shared_contexts/requests/api/npm_packages_shared_context.rb b/spec/support/shared_contexts/requests/api/npm_packages_shared_context.rb index c737091df48..815108be447 100644 --- a/spec/support/shared_contexts/requests/api/npm_packages_shared_context.rb +++ b/spec/support/shared_contexts/requests/api/npm_packages_shared_context.rb @@ -11,7 +11,7 @@ RSpec.shared_context 'npm api setup' do let_it_be(:package, reload: true) { create(:npm_package, project: project, name: "@#{group.path}/scoped_package") } let_it_be(:token) { create(:oauth_access_token, scopes: 'api', resource_owner: user) } let_it_be(:personal_access_token) { create(:personal_access_token, user: user) } - let_it_be(:job, reload: true) { create(:ci_build, user: user, status: :running, project: project) } + let_it_be(:job, reload: true) { create(:ci_build, user: user, status: :running) } let_it_be(:deploy_token) { create(:deploy_token, read_package_registry: true, write_package_registry: true) } let_it_be(:project_deploy_token) { create(:project_deploy_token, deploy_token: deploy_token, project: project) } diff --git a/spec/support/shared_contexts/services/service_ping/stubbed_service_ping_metrics_definitions_shared_context.rb b/spec/support/shared_contexts/services/service_ping/stubbed_service_ping_metrics_definitions_shared_context.rb index ea72398010c..6b49a415889 100644 --- a/spec/support/shared_contexts/services/service_ping/stubbed_service_ping_metrics_definitions_shared_context.rb +++ b/spec/support/shared_contexts/services/service_ping/stubbed_service_ping_metrics_definitions_shared_context.rb @@ -6,20 +6,20 @@ RSpec.shared_context 'stubbed service ping metrics definitions' do let(:metrics_definitions) { standard_metrics + subscription_metrics + operational_metrics + optional_metrics } let(:standard_metrics) do [ - metric_attributes('uuid', "Standard") + metric_attributes('uuid', "standard") ] end let(:operational_metrics) do [ - metric_attributes('counts.merge_requests', "Operational"), - metric_attributes('counts.todos', "Operational") + metric_attributes('counts.merge_requests', "operational"), + metric_attributes('counts.todos', "operational") ] end let(:optional_metrics) do [ - metric_attributes('counts.boards', "Optional"), + metric_attributes('counts.boards', "optional"), metric_attributes('gitaly.filesystems', '').except('data_category') ] end |