diff options
Diffstat (limited to 'spec/support/shared_contexts')
8 files changed, 67 insertions, 51 deletions
diff --git a/spec/support/shared_contexts/email_shared_context.rb b/spec/support/shared_contexts/email_shared_context.rb index 14c6c85cc43..0dc66eeb2ee 100644 --- a/spec/support/shared_contexts/email_shared_context.rb +++ b/spec/support/shared_contexts/email_shared_context.rb @@ -18,6 +18,15 @@ RSpec.shared_context :email_shared_context do end end +def email_fixture(path) + fixture_file(path).gsub('project_id', project.project_id.to_s) +end + +def service_desk_fixture(path, slug: nil, key: 'mykey') + slug ||= project.full_path_slug.to_s + fixture_file(path).gsub('project_slug', slug).gsub('project_key', key) +end + RSpec.shared_examples :reply_processing_shared_examples do context 'when the user could not be found' do before do diff --git a/spec/support/shared_contexts/finders/packages/npm/package_finder_shared_context.rb b/spec/support/shared_contexts/finders/packages/npm/package_finder_shared_context.rb new file mode 100644 index 00000000000..a2cb9d41f45 --- /dev/null +++ b/spec/support/shared_contexts/finders/packages/npm/package_finder_shared_context.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true + +RSpec.shared_context 'last_of_each_version setup context' do + let_it_be(:package1) { create(:npm_package, name: 'test', version: '1.2.3', project: project) } + let_it_be(:package2) { create(:npm_package, name: 'test2', version: '1.2.3', project: project) } + + let(:package_name) { 'test' } + let(:version) { '1.2.3' } + + before do + # create a duplicated package without triggering model validation errors + package2.update_column(:name, 'test') + end +end diff --git a/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb b/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb new file mode 100644 index 00000000000..aa857cfdb70 --- /dev/null +++ b/spec/support/shared_contexts/graphql/resolvers/runners_resolver_shared_context.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.shared_context 'runners resolver setup' do + let_it_be(:user) { create_default(:user, :admin) } + let_it_be(:group) { create(:group, :public) } + let_it_be(:subgroup) { create(:group, :public, parent: group) } + let_it_be(:project) { create(:project, :public, group: group) } + + let_it_be(:inactive_project_runner) do + create(:ci_runner, :project, projects: [project], description: 'inactive project runner', token: 'abcdef', active: false, contacted_at: 1.minute.ago, tag_list: %w(project_runner)) + end + + let_it_be(:offline_project_runner) do + create(:ci_runner, :project, projects: [project], description: 'offline project runner', token: 'defghi', contacted_at: 1.day.ago, tag_list: %w(project_runner active_runner)) + end + + let_it_be(:group_runner) { create(:ci_runner, :group, groups: [group], token: 'mnopqr', description: 'group runner', contacted_at: 2.seconds.ago) } + let_it_be(:subgroup_runner) { create(:ci_runner, :group, groups: [subgroup], token: 'mnopqr', description: 'subgroup runner', contacted_at: 1.second.ago) } + let_it_be(:instance_runner) { create(:ci_runner, :instance, description: 'shared runner', token: 'stuvxz', contacted_at: 2.minutes.ago, tag_list: %w(instance_runner active_runner)) } +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 2c56411ca4c..b9cde12c537 100644 --- a/spec/support/shared_contexts/issuable/merge_request_shared_context.rb +++ b/spec/support/shared_contexts/issuable/merge_request_shared_context.rb @@ -16,7 +16,7 @@ RSpec.shared_context 'merge request show action' do assign(:merge_request, merge_request) assign(:note, note) assign(:noteable, merge_request) - assign(:pipelines, []) + assign(:number_of_pipelines, 0) assign(:issuable_sidebar, serialize_issuable_sidebar(user, project, merge_request)) preload_view_requirements(merge_request, note) diff --git a/spec/support/shared_contexts/navbar_structure_context.rb b/spec/support/shared_contexts/navbar_structure_context.rb index 8ae0885056e..2abc52fce85 100644 --- a/spec/support/shared_contexts/navbar_structure_context.rb +++ b/spec/support/shared_contexts/navbar_structure_context.rb @@ -118,7 +118,8 @@ RSpec.shared_context 'project navbar structure' do _('Access Tokens'), _('Repository'), _('CI/CD'), - _('Monitor') + _('Monitor'), + (s_('UsageQuota|Usage Quotas') if Feature.enabled?(:project_storage_ui, default_enabled: :yaml)) ] } ].compact diff --git a/spec/support/shared_contexts/pages_zip_with_spoofed_size_shared_context.rb b/spec/support/shared_contexts/pages_zip_with_spoofed_size_shared_context.rb deleted file mode 100644 index 4cec5ab3b74..00000000000 --- a/spec/support/shared_contexts/pages_zip_with_spoofed_size_shared_context.rb +++ /dev/null @@ -1,41 +0,0 @@ -# frozen_string_literal: true - -# the idea of creating zip archive with spoofed size is borrowed from -# https://github.com/rubyzip/rubyzip/pull/403/files#diff-118213fb4baa6404a40f89e1147661ebR88 -RSpec.shared_context 'pages zip with spoofed size' do - let(:real_zip_path) { Tempfile.new(['real', '.zip']).path } - let(:fake_zip_path) { Tempfile.new(['fake', '.zip']).path } - - before do - full_file_name = 'public/index.html' - true_size = 500_000 - fake_size = 1 - - ::Zip::File.open(real_zip_path, ::Zip::File::CREATE) do |zf| - zf.get_output_stream(full_file_name) do |os| - os.write 'a' * true_size - end - end - - compressed_size = nil - ::Zip::File.open(real_zip_path) do |zf| - a_entry = zf.find_entry(full_file_name) - compressed_size = a_entry.compressed_size - end - - true_size_bytes = [compressed_size, true_size, full_file_name.size].pack('LLS') - fake_size_bytes = [compressed_size, fake_size, full_file_name.size].pack('LLS') - - data = File.binread(real_zip_path) - data.gsub! true_size_bytes, fake_size_bytes - - File.open(fake_zip_path, 'wb') do |file| - file.write data - end - end - - after do - File.delete(real_zip_path) if File.exist?(real_zip_path) - File.delete(fake_zip_path) if File.exist?(fake_zip_path) - end -end 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 815108be447..89f290d8d68 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 @@ -8,14 +8,20 @@ RSpec.shared_context 'npm api setup' do let_it_be(:group) { create(:group, name: 'test-group') } let_it_be(:namespace) { group } let_it_be(:project, reload: true) { create(:project, :public, namespace: namespace) } - let_it_be(:package, reload: true) { create(:npm_package, project: project, name: "@#{group.path}/scoped_package") } + let_it_be(:package1, reload: true) { create(:npm_package, project: project, name: "@#{group.path}/scoped_package", version: '1.2.4') } + let_it_be(:package, reload: true) { create(:npm_package, project: project, name: "@#{group.path}/scoped_package", version: '1.2.3') } 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) } + let_it_be(:job, reload: true) { create(:ci_build, user: user, status: :running, project: project) } 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) } let(:package_name) { package.name } + + before do + # create a duplicated package without triggering model validation errors + package1.update_column(:version, '1.2.3') + end end RSpec.shared_context 'set package name from package name type' do 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 6b49a415889..2b810e790f0 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,21 +6,25 @@ 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'), + metric_attributes('recorded_at', 'standard'), + metric_attributes('settings.collected_data_categories', 'standard', 'object') ] end let(:operational_metrics) do [ - metric_attributes('counts.merge_requests', "operational"), + metric_attributes('counts.merge_requests', 'operational'), metric_attributes('counts.todos', "operational") ] end let(:optional_metrics) do [ - metric_attributes('counts.boards', "optional"), - metric_attributes('gitaly.filesystems', '').except('data_category') + metric_attributes('counts.boards', 'optional', 'number'), + metric_attributes('gitaly.filesystems', '').except('data_category'), + metric_attributes('usage_activity_by_stage.monitor.projects_with_enabled_alert_integrations_histogram', 'optional', 'object'), + metric_attributes('topology', 'optional', 'object') ] end @@ -34,10 +38,11 @@ RSpec.shared_context 'stubbed service ping metrics definitions' do ) end - def metric_attributes(key_path, category) + def metric_attributes(key_path, category, value_type = 'string') { 'key_path' => key_path, - 'data_category' => category + 'data_category' => category, + 'value_type' => value_type } end end |