diff options
Diffstat (limited to 'spec')
53 files changed, 458 insertions, 102 deletions
diff --git a/spec/components/projects/ml/show_ml_model_version_component_spec.rb b/spec/components/projects/ml/show_ml_model_version_component_spec.rb new file mode 100644 index 00000000000..973d8123c45 --- /dev/null +++ b/spec/components/projects/ml/show_ml_model_version_component_spec.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +require "spec_helper" + +RSpec.describe Projects::Ml::ShowMlModelVersionComponent, type: :component, feature_category: :mlops do + let_it_be(:project) { build_stubbed(:project) } + let_it_be(:model) { build_stubbed(:ml_models, project: project) } + let_it_be(:version) { build_stubbed(:ml_model_versions, model: model) } + + subject(:component) do + described_class.new(model_version: version) + end + + describe 'rendered' do + before do + render_inline component + end + + it 'renders element with view_model' do + element = page.find("#js-mount-show-ml-model-version") + + expect(Gitlab::Json.parse(element['data-view-model'])).to eq({ + 'modelVersion' => { + 'id' => version.id, + 'version' => version.version, + 'path' => "/#{project.full_path}/-/ml/models/#{model.id}/versions/#{version.id}", + 'model' => { + 'name' => model.name, + 'path' => "/#{project.full_path}/-/ml/models/#{model.id}" + } + } + }) + end + end +end diff --git a/spec/features/admin/admin_browse_spam_logs_spec.rb b/spec/features/admin/admin_browse_spam_logs_spec.rb index c272a8630b7..f781e2adf07 100644 --- a/spec/features/admin/admin_browse_spam_logs_spec.rb +++ b/spec/features/admin/admin_browse_spam_logs_spec.rb @@ -4,9 +4,9 @@ require 'spec_helper' RSpec.describe 'Admin browse spam logs', feature_category: :shared do let!(:spam_log) { create(:spam_log, description: 'abcde ' * 20) } + let(:admin) { create(:admin) } before do - admin = create(:admin) sign_in(admin) gitlab_enable_admin_mode_sign_in(admin) end @@ -22,6 +22,7 @@ RSpec.describe 'Admin browse spam logs', feature_category: :shared do expect(page).to have_content("#{spam_log.description[0...97]}...") expect(page).to have_link('Remove user') expect(page).to have_link('Block user') + expect(page).to have_link('Trust user') end it 'does not perform N+1 queries' do @@ -30,4 +31,15 @@ RSpec.describe 'Admin browse spam logs', feature_category: :shared do expect { visit admin_spam_logs_path }.not_to exceed_query_limit(control_queries) end + + context 'when user is trusted' do + before do + UserCustomAttribute.set_trusted_by(user: spam_log.user, trusted_by: admin) + end + + it 'allows admin to untrust the user' do + visit admin_spam_logs_path + expect(page).to have_link('Untrust user') + end + end end diff --git a/spec/fixtures/tooling/danger/rubocop_todo/cop1.yml b/spec/fixtures/tooling/danger/rubocop_todo/cop1.yml new file mode 100644 index 00000000000..8f240b92682 --- /dev/null +++ b/spec/fixtures/tooling/danger/rubocop_todo/cop1.yml @@ -0,0 +1,5 @@ +--- +Cop1: + Exclude: + - 'app/controllers/application_controller.rb' + - 'app/controllers/acme_challenges_controller.rb' diff --git a/spec/fixtures/tooling/danger/rubocop_todo/cop2.yml b/spec/fixtures/tooling/danger/rubocop_todo/cop2.yml new file mode 100644 index 00000000000..9ab2c0dabb9 --- /dev/null +++ b/spec/fixtures/tooling/danger/rubocop_todo/cop2.yml @@ -0,0 +1,4 @@ +--- +Cop2: + Exclude: + - 'app/controllers/application_controller.rb' diff --git a/spec/frontend/alert_spec.js b/spec/frontend/alert_spec.js index de3093c6c19..71c7dbe0cfd 100644 --- a/spec/frontend/alert_spec.js +++ b/spec/frontend/alert_spec.js @@ -1,8 +1,8 @@ -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import { createAlert, VARIANT_WARNING } from '~/alert'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('Flash', () => { const findTextContent = (containerSelector = '.flash-container') => diff --git a/spec/frontend/boards/cache_updates_spec.js b/spec/frontend/boards/cache_updates_spec.js index bc661f20451..07f5cef4a36 100644 --- a/spec/frontend/boards/cache_updates_spec.js +++ b/spec/frontend/boards/cache_updates_spec.js @@ -1,4 +1,4 @@ -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { setError } from '~/boards/graphql/cache_updates'; import { defaultClient } from '~/graphql_shared/issuable_client'; import setErrorMutation from '~/boards/graphql/client/set_error.mutation.graphql'; diff --git a/spec/frontend/boards/stores/actions_spec.js b/spec/frontend/boards/stores/actions_spec.js index 5b4b79c650a..358cb340802 100644 --- a/spec/frontend/boards/stores/actions_spec.js +++ b/spec/frontend/boards/stores/actions_spec.js @@ -1,8 +1,8 @@ -import * as Sentry from '@sentry/browser'; import { cloneDeep } from 'lodash'; import Vue from 'vue'; // eslint-disable-next-line no-restricted-imports import Vuex from 'vuex'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { inactiveId, ISSUABLE, ListType, DraggableItemTypes } from 'ee_else_ce/boards/constants'; import issueMoveListMutation from 'ee_else_ce/boards/graphql/issue_move_list.mutation.graphql'; import testAction from 'helpers/vuex_action_helper'; diff --git a/spec/frontend/ci/pipelines_page/pipelines_spec.js b/spec/frontend/ci/pipelines_page/pipelines_spec.js index fd95f98e7f8..3ce7960ed71 100644 --- a/spec/frontend/ci/pipelines_page/pipelines_spec.js +++ b/spec/frontend/ci/pipelines_page/pipelines_spec.js @@ -7,7 +7,6 @@ import { GlPagination, GlCollapsibleListbox, } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { mount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; import { chunk } from 'lodash'; @@ -19,6 +18,7 @@ import { mockTracking } from 'helpers/tracking_helper'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; import createMockApollo from 'helpers/mock_apollo_helper'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import Api from '~/api'; import { createAlert, VARIANT_WARNING } from '~/alert'; import setSortPreferenceMutation from '~/issues/list/queries/set_sort_preference.mutation.graphql'; @@ -40,7 +40,7 @@ import { import { stageReply } from 'jest/ci/pipeline_mini_graph/mock_data'; import { users, mockSearch, branches } from '../pipeline_details/mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/alert'); const mockProjectPath = 'twitter/flight'; diff --git a/spec/frontend/ci/runner/sentry_utils_spec.js b/spec/frontend/ci/runner/sentry_utils_spec.js index 59d386a5899..bb291557288 100644 --- a/spec/frontend/ci/runner/sentry_utils_spec.js +++ b/spec/frontend/ci/runner/sentry_utils_spec.js @@ -1,7 +1,7 @@ -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { captureException } from '~/ci/runner/sentry_utils'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('~/ci/runner/sentry_utils', () => { describe('captureException', () => { diff --git a/spec/frontend/clusters_list/components/clusters_spec.js b/spec/frontend/clusters_list/components/clusters_spec.js index d4474b1c643..a7ec32c4f32 100644 --- a/spec/frontend/clusters_list/components/clusters_spec.js +++ b/spec/frontend/clusters_list/components/clusters_spec.js @@ -1,8 +1,8 @@ import { GlLoadingIcon, GlPagination, GlSkeletonLoader, GlTableLite } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { mount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; import { nextTick } from 'vue'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import Clusters from '~/clusters_list/components/clusters.vue'; import ClustersEmptyState from '~/clusters_list/components/clusters_empty_state.vue'; import ClusterStore from '~/clusters_list/store'; @@ -15,7 +15,7 @@ import { } from '~/clusters_list/store/mutation_types'; import { apiData } from '../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('Clusters', () => { let mock; diff --git a/spec/frontend/clusters_list/store/actions_spec.js b/spec/frontend/clusters_list/store/actions_spec.js index 9e6da595a75..fda3fde6baa 100644 --- a/spec/frontend/clusters_list/store/actions_spec.js +++ b/spec/frontend/clusters_list/store/actions_spec.js @@ -1,5 +1,5 @@ -import * as Sentry from '@sentry/browser'; import MockAdapter from 'axios-mock-adapter'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import testAction from 'helpers/vuex_action_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { MAX_REQUESTS } from '~/clusters_list/constants'; diff --git a/spec/frontend/custom_emoji/components/delete_item_spec.js b/spec/frontend/custom_emoji/components/delete_item_spec.js index 06c4ca8d54b..2d5594b8a65 100644 --- a/spec/frontend/custom_emoji/components/delete_item_spec.js +++ b/spec/frontend/custom_emoji/components/delete_item_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; -import * as Sentry from '@sentry/browser'; import { GlModal } from '@gitlab/ui'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { mountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; @@ -11,7 +11,7 @@ import deleteCustomEmojiMutation from '~/custom_emoji/queries/delete_custom_emoj import { CUSTOM_EMOJI } from '../mock_data'; jest.mock('~/alert'); -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); let wrapper; let deleteMutationSpy; diff --git a/spec/frontend/design_management/components/design_notes/design_note_spec.js b/spec/frontend/design_management/components/design_notes/design_note_spec.js index 8795b089551..91c6acd8890 100644 --- a/spec/frontend/design_management/components/design_notes/design_note_spec.js +++ b/spec/frontend/design_management/components/design_notes/design_note_spec.js @@ -1,7 +1,7 @@ import { ApolloMutation } from 'vue-apollo'; import { nextTick } from 'vue'; import { GlAvatar, GlAvatarLink, GlDisclosureDropdown, GlDisclosureDropdownItem } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; diff --git a/spec/frontend/emoji/awards_app/store/actions_spec.js b/spec/frontend/emoji/awards_app/store/actions_spec.js index 65f2e813f19..23aa7bd5ad7 100644 --- a/spec/frontend/emoji/awards_app/store/actions_spec.js +++ b/spec/frontend/emoji/awards_app/store/actions_spec.js @@ -1,11 +1,11 @@ -import * as Sentry from '@sentry/browser'; import MockAdapter from 'axios-mock-adapter'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import testAction from 'helpers/vuex_action_helper'; import * as actions from '~/emoji/awards_app/store/actions'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/vue_shared/plugins/global_toast'); describe('Awards app actions', () => { diff --git a/spec/frontend/import_entities/import_projects/components/github_organizations_box_spec.js b/spec/frontend/import_entities/import_projects/components/github_organizations_box_spec.js index b6f96cd6a23..7b3758cbd25 100644 --- a/spec/frontend/import_entities/import_projects/components/github_organizations_box_spec.js +++ b/spec/frontend/import_entities/import_projects/components/github_organizations_box_spec.js @@ -1,8 +1,8 @@ import { GlCollapsibleListbox } from '@gitlab/ui'; import MockAdapter from 'axios-mock-adapter'; import { mount } from '@vue/test-utils'; -import { captureException } from '@sentry/browser'; import { nextTick } from 'vue'; +import { captureException } from '~/sentry/sentry_browser_wrapper'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; @@ -10,7 +10,7 @@ import { createAlert } from '~/alert'; import GithubOrganizationsBox from '~/import_entities/import_projects/components/github_organizations_box.vue'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/alert'); const MOCK_RESPONSE = { diff --git a/spec/frontend/integrations/edit/components/integration_form_spec.js b/spec/frontend/integrations/edit/components/integration_form_spec.js index 5aa3ee35379..cef8fb0b720 100644 --- a/spec/frontend/integrations/edit/components/integration_form_spec.js +++ b/spec/frontend/integrations/edit/components/integration_form_spec.js @@ -2,7 +2,7 @@ import { GlAlert, GlForm } from '@gitlab/ui'; import axios from 'axios'; import MockAdapter from 'axios-mock-adapter'; import { nextTick } from 'vue'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { setHTMLFixture } from 'helpers/fixtures'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; import waitForPromises from 'helpers/wait_for_promises'; @@ -29,7 +29,7 @@ import { mockSectionJiraIssues, } from '../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/lib/utils/url_utility'); describe('IntegrationForm', () => { diff --git a/spec/frontend/integrations/overrides/components/integration_overrides_spec.js b/spec/frontend/integrations/overrides/components/integration_overrides_spec.js index 9e863eaecfd..ac67d53e00d 100644 --- a/spec/frontend/integrations/overrides/components/integration_overrides_spec.js +++ b/spec/frontend/integrations/overrides/components/integration_overrides_spec.js @@ -1,7 +1,7 @@ import { GlTable, GlLink, GlPagination, GlAlert } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { shallowMount, mount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import waitForPromises from 'helpers/wait_for_promises'; import { DEFAULT_PER_PAGE } from '~/api'; import IntegrationOverrides from '~/integrations/overrides/components/integration_overrides.vue'; diff --git a/spec/frontend/issues/dashboard/components/issues_dashboard_app_spec.js b/spec/frontend/issues/dashboard/components/issues_dashboard_app_spec.js index f6c9fab76d1..35699568793 100644 --- a/spec/frontend/issues/dashboard/components/issues_dashboard_app_spec.js +++ b/spec/frontend/issues/dashboard/components/issues_dashboard_app_spec.js @@ -1,9 +1,9 @@ import { GlDisclosureDropdown, GlEmptyState } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import AxiosMockAdapter from 'axios-mock-adapter'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import { cloneDeep } from 'lodash'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import getIssuesQuery from 'ee_else_ce/issues/dashboard/queries/get_issues.query.graphql'; import IssueCardStatistics from 'ee_else_ce/issues/list/components/issue_card_statistics.vue'; import IssueCardTimeInfo from 'ee_else_ce/issues/list/components/issue_card_time_info.vue'; @@ -45,7 +45,7 @@ import { issuesQueryResponse, } from '../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/lib/utils/scroll_utils', () => ({ scrollUp: jest.fn() })); describe('IssuesDashboardApp component', () => { diff --git a/spec/frontend/issues/list/components/issues_list_app_spec.js b/spec/frontend/issues/list/components/issues_list_app_spec.js index f830168ce5d..6bd952cd215 100644 --- a/spec/frontend/issues/list/components/issues_list_app_spec.js +++ b/spec/frontend/issues/list/components/issues_list_app_spec.js @@ -1,11 +1,11 @@ import { GlButton, GlDisclosureDropdown, GlDrawer } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { mount, shallowMount } from '@vue/test-utils'; import AxiosMockAdapter from 'axios-mock-adapter'; import { cloneDeep } from 'lodash'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import VueRouter from 'vue-router'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import getIssuesQuery from 'ee_else_ce/issues/list/queries/get_issues.query.graphql'; import getIssuesCountsQuery from 'ee_else_ce/issues/list/queries/get_issues_counts.query.graphql'; import createMockApollo from 'helpers/mock_apollo_helper'; @@ -87,7 +87,7 @@ import { import('~/issuable'); import('~/users_select'); -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/alert'); jest.mock('~/lib/utils/scroll_utils', () => ({ scrollUp: jest.fn() })); diff --git a/spec/frontend/issues/service_desk/components/service_desk_list_app_spec.js b/spec/frontend/issues/service_desk/components/service_desk_list_app_spec.js index d28b4f2fe76..bb388cefa95 100644 --- a/spec/frontend/issues/service_desk/components/service_desk_list_app_spec.js +++ b/spec/frontend/issues/service_desk/components/service_desk_list_app_spec.js @@ -3,8 +3,8 @@ import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import { cloneDeep } from 'lodash'; import VueRouter from 'vue-router'; -import * as Sentry from '@sentry/browser'; import AxiosMockAdapter from 'axios-mock-adapter'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import axios from '~/lib/utils/axios_utils'; import createMockApollo from 'helpers/mock_apollo_helper'; import setWindowLocation from 'helpers/set_window_location_helper'; @@ -55,7 +55,7 @@ import { locationSearch, } from '../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/alert'); jest.mock('~/lib/utils/scroll_utils', () => ({ scrollUp: jest.fn() })); diff --git a/spec/frontend/members/components/table/role_dropdown_spec.js b/spec/frontend/members/components/table/role_dropdown_spec.js index 5204ac2fdbe..915b2ae17ae 100644 --- a/spec/frontend/members/components/table/role_dropdown_spec.js +++ b/spec/frontend/members/components/table/role_dropdown_spec.js @@ -1,10 +1,10 @@ import { GlCollapsibleListbox, GlListboxItem } from '@gitlab/ui'; import { GlBreakpointInstance as bp } from '@gitlab/ui/dist/utils'; -import * as Sentry from '@sentry/browser'; import { mount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; // eslint-disable-next-line no-restricted-imports import Vuex from 'vuex'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import waitForPromises from 'helpers/wait_for_promises'; import RoleDropdown from '~/members/components/table/role_dropdown.vue'; import { MEMBER_TYPES } from '~/members/constants'; @@ -13,7 +13,7 @@ import { member } from '../../mock_data'; Vue.use(Vuex); jest.mock('ee_else_ce/members/guest_overage_confirm_action'); -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('RoleDropdown', () => { let wrapper; diff --git a/spec/frontend/ml/model_registry/apps/show_ml_model_version_spec.js b/spec/frontend/ml/model_registry/apps/show_ml_model_version_spec.js new file mode 100644 index 00000000000..77fca53c00e --- /dev/null +++ b/spec/frontend/ml/model_registry/apps/show_ml_model_version_spec.js @@ -0,0 +1,15 @@ +import { shallowMount } from '@vue/test-utils'; +import { ShowMlModelVersion } from '~/ml/model_registry/apps'; +import { MODEL_VERSION } from '../mock_data'; + +let wrapper; +const createWrapper = () => { + wrapper = shallowMount(ShowMlModelVersion, { propsData: { modelVersion: MODEL_VERSION } }); +}; + +describe('ShowMlModelVersion', () => { + beforeEach(() => createWrapper()); + it('renders the app', () => { + expect(wrapper.text()).toContain(`${MODEL_VERSION.model.name} - ${MODEL_VERSION.version}`); + }); +}); diff --git a/spec/frontend/ml/model_registry/mock_data.js b/spec/frontend/ml/model_registry/mock_data.js index 18b2b32e069..35a2c3bec01 100644 --- a/spec/frontend/ml/model_registry/mock_data.js +++ b/spec/frontend/ml/model_registry/mock_data.js @@ -1 +1,3 @@ export const MODEL = { name: 'blah' }; + +export const MODEL_VERSION = { version: '1.2.3', model: MODEL }; diff --git a/spec/frontend/observability/client_spec.js b/spec/frontend/observability/client_spec.js index 68a53131539..e61153fb5e5 100644 --- a/spec/frontend/observability/client_spec.js +++ b/spec/frontend/observability/client_spec.js @@ -1,10 +1,10 @@ import MockAdapter from 'axios-mock-adapter'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { buildClient } from '~/observability/client'; import axios from '~/lib/utils/axios_utils'; jest.mock('~/lib/utils/axios_utils'); -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('buildClient', () => { let client; diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js b/spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js index 2e59c27cc1b..133941bbb2e 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/details/additional_metadata_spec.js @@ -1,7 +1,7 @@ import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import { GlAlert } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; import { diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/package_files_spec.js b/spec/frontend/packages_and_registries/package_registry/components/details/package_files_spec.js index 5ba4b1f687e..7823b146aba 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/package_files_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/details/package_files_spec.js @@ -6,9 +6,9 @@ import { GlModal, GlKeysetPagination, } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { stubComponent } from 'helpers/stub_component'; import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/package_history_spec.js b/spec/frontend/packages_and_registries/package_registry/components/details/package_history_spec.js index ed470f63b8a..d83d571872c 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/package_history_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/details/package_history_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; import { GlAlert, GlLink, GlSprintf } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { stubComponent } from 'helpers/stub_component'; import createMockApollo from 'helpers/mock_apollo_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; diff --git a/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js b/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js index e9f2a2c5095..8e22e9a3b0c 100644 --- a/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js +++ b/spec/frontend/packages_and_registries/package_registry/components/details/package_versions_list_spec.js @@ -1,7 +1,7 @@ import Vue from 'vue'; import VueApollo from 'vue-apollo'; import { GlAlert } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; import { stubComponent } from 'helpers/stub_component'; diff --git a/spec/frontend/security_configuration/components/training_provider_list_spec.js b/spec/frontend/security_configuration/components/training_provider_list_spec.js index 2982cef7c74..5b2b3f46df6 100644 --- a/spec/frontend/security_configuration/components/training_provider_list_spec.js +++ b/spec/frontend/security_configuration/components/training_provider_list_spec.js @@ -1,4 +1,3 @@ -import * as Sentry from '@sentry/browser'; import { GlAlert, GlLink, @@ -10,6 +9,7 @@ import { } from '@gitlab/ui'; import Vue from 'vue'; import VueApollo from 'vue-apollo'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; import { mockTracking, unmockTracking } from 'helpers/tracking_helper'; diff --git a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js index 27ab347775a..c1c3c1fea91 100644 --- a/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js +++ b/spec/frontend/sidebar/components/sidebar_dropdown_widget_spec.js @@ -1,8 +1,8 @@ import { GlLink, GlLoadingIcon, GlSearchBoxByType } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { shallowMount, mount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import createMockApollo from 'helpers/mock_apollo_helper'; import { createMockDirective, getBinding } from 'helpers/vue_mock_directive'; import { extendedWrapper } from 'helpers/vue_test_utils_helper'; diff --git a/spec/frontend/super_sidebar/utils_spec.js b/spec/frontend/super_sidebar/utils_spec.js index 85c13a4c892..43eb82f5928 100644 --- a/spec/frontend/super_sidebar/utils_spec.js +++ b/spec/frontend/super_sidebar/utils_spec.js @@ -1,5 +1,5 @@ -import * as Sentry from '@sentry/browser'; import MockAdapter from 'axios-mock-adapter'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { getTopFrequentItems, trackContextAccess, @@ -16,7 +16,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import { unsortedFrequentItems, sortedFrequentItems } from '../frequent_items/mock_data'; import { cachedFrequentProjects } from './mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); useLocalStorageSpy(); diff --git a/spec/frontend/time_tracking/components/timelogs_app_spec.js b/spec/frontend/time_tracking/components/timelogs_app_spec.js index 13188f3b937..4cc719ee09f 100644 --- a/spec/frontend/time_tracking/components/timelogs_app_spec.js +++ b/spec/frontend/time_tracking/components/timelogs_app_spec.js @@ -1,10 +1,10 @@ import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; -import * as Sentry from '@sentry/browser'; import { GlDatepicker, GlLoadingIcon, GlKeysetPagination } from '@gitlab/ui'; import getTimelogsEmptyResponse from 'test_fixtures/graphql/get_timelogs_empty_response.json'; import getPaginatedTimelogsResponse from 'test_fixtures/graphql/get_paginated_timelogs_response.json'; import getNonPaginatedTimelogsResponse from 'test_fixtures/graphql/get_non_paginated_timelogs_response.json'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { createAlert } from '~/alert'; import { mountExtended, extendedWrapper } from 'helpers/vue_test_utils_helper'; import createMockApollo from 'helpers/mock_apollo_helper'; @@ -14,7 +14,7 @@ import TimelogsApp from '~/time_tracking/components/timelogs_app.vue'; import TimelogsTable from '~/time_tracking/components/timelogs_table.vue'; jest.mock('~/alert'); -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('Timelogs app', () => { Vue.use(VueApollo); diff --git a/spec/frontend/tracking/dispatch_snowplow_event_spec.js b/spec/frontend/tracking/dispatch_snowplow_event_spec.js index 5f4d065d504..8297a7088f2 100644 --- a/spec/frontend/tracking/dispatch_snowplow_event_spec.js +++ b/spec/frontend/tracking/dispatch_snowplow_event_spec.js @@ -1,10 +1,10 @@ -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { dispatchSnowplowEvent } from '~/tracking/dispatch_snowplow_event'; import getStandardContext from '~/tracking/get_standard_context'; import { extraContext, servicePingContext } from './mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); jest.mock('~/tracking/get_standard_context'); const category = 'Incident Management'; diff --git a/spec/frontend/vue_merge_request_widget/components/widget/widget_spec.js b/spec/frontend/vue_merge_request_widget/components/widget/widget_spec.js index 18fdba32f52..87c1ad7947e 100644 --- a/spec/frontend/vue_merge_request_widget/components/widget/widget_spec.js +++ b/spec/frontend/vue_merge_request_widget/components/widget/widget_spec.js @@ -1,5 +1,5 @@ import { nextTick } from 'vue'; -import * as Sentry from '@sentry/browser'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import { shallowMountExtended, mountExtended } from 'helpers/vue_test_utils_helper'; import HelpPopover from '~/vue_shared/components/help_popover.vue'; import waitForPromises from 'helpers/wait_for_promises'; diff --git a/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js b/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js index eb3d624dc04..9296e548081 100644 --- a/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js +++ b/spec/frontend/vue_merge_request_widget/mr_widget_options_spec.js @@ -3,13 +3,13 @@ import MockAdapter from 'axios-mock-adapter'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import { createMockSubscription as createMockApolloSubscription } from 'mock-apollo-client'; -import * as Sentry from '@sentry/browser'; import approvedByCurrentUser from 'test_fixtures/graphql/merge_requests/approvals/approvals.query.graphql.json'; import getStateQueryResponse from 'test_fixtures/graphql/merge_requests/get_state.query.graphql.json'; import readyToMergeResponse from 'test_fixtures/graphql/merge_requests/states/ready_to_merge.query.graphql.json'; import createMockApollo from 'helpers/mock_apollo_helper'; import waitForPromises from 'helpers/wait_for_promises'; import { mountExtended, shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import api from '~/api'; import axios from '~/lib/utils/axios_utils'; import { HTTP_STATUS_OK, HTTP_STATUS_NO_CONTENT } from '~/lib/utils/http_status'; @@ -63,8 +63,8 @@ jest.mock('~/smart_interval'); jest.mock('~/lib/utils/favicon'); -jest.mock('@sentry/browser', () => ({ - ...jest.requireActual('@sentry/browser'), +jest.mock('~/sentry/sentry_browser_wrapper', () => ({ + ...jest.requireActual('~/sentry/sentry_browser_wrapper'), captureException: jest.fn(), })); diff --git a/spec/frontend/vue_shared/components/ensure_data_spec.js b/spec/frontend/vue_shared/components/ensure_data_spec.js index 217e795bc64..399fe19ea3f 100644 --- a/spec/frontend/vue_shared/components/ensure_data_spec.js +++ b/spec/frontend/vue_shared/components/ensure_data_spec.js @@ -1,6 +1,6 @@ import { GlEmptyState } from '@gitlab/ui'; -import * as Sentry from '@sentry/browser'; import { mount } from '@vue/test-utils'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import ensureData from '~/ensure_data'; const mockData = { message: 'Hello there' }; diff --git a/spec/frontend/work_items/components/work_item_parent_spec.js b/spec/frontend/work_items/components/work_item_parent_spec.js index a72eeabc43c..dcebfca7c68 100644 --- a/spec/frontend/work_items/components/work_item_parent_spec.js +++ b/spec/frontend/work_items/components/work_item_parent_spec.js @@ -1,12 +1,11 @@ -import * as Sentry from '@sentry/browser'; import { GlCollapsibleListbox, GlFormGroup } from '@gitlab/ui'; - import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; import waitForPromises from 'helpers/wait_for_promises'; import createMockApollo from 'helpers/mock_apollo_helper'; import { shallowMountExtended } from 'helpers/vue_test_utils_helper'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import WorkItemParent from '~/work_items/components/work_item_parent.vue'; import updateWorkItemMutation from '~/work_items/graphql/update_work_item.mutation.graphql'; import projectWorkItemsQuery from '~/work_items/graphql/project_work_items.query.graphql'; @@ -20,7 +19,7 @@ import { updateWorkItemMutationErrorResponse, } from '../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('WorkItemParent component', () => { Vue.use(VueApollo); diff --git a/spec/frontend/work_items/list/components/work_items_list_app_spec.js b/spec/frontend/work_items/list/components/work_items_list_app_spec.js index 96083478e77..401d7dcbbdb 100644 --- a/spec/frontend/work_items/list/components/work_items_list_app_spec.js +++ b/spec/frontend/work_items/list/components/work_items_list_app_spec.js @@ -1,7 +1,7 @@ -import * as Sentry from '@sentry/browser'; import { shallowMount } from '@vue/test-utils'; import Vue, { nextTick } from 'vue'; import VueApollo from 'vue-apollo'; +import * as Sentry from '~/sentry/sentry_browser_wrapper'; import IssueCardStatistics from 'ee_else_ce/issues/list/components/issue_card_statistics.vue'; import IssueCardTimeInfo from 'ee_else_ce/issues/list/components/issue_card_time_info.vue'; import createMockApollo from 'helpers/mock_apollo_helper'; @@ -12,7 +12,7 @@ import WorkItemsListApp from '~/work_items/list/components/work_items_list_app.v import getWorkItemsQuery from '~/work_items/list/queries/get_work_items.query.graphql'; import { groupWorkItemsQueryResponse } from '../../mock_data'; -jest.mock('@sentry/browser'); +jest.mock('~/sentry/sentry_browser_wrapper'); describe('WorkItemsListApp component', () => { let wrapper; diff --git a/spec/lib/gitlab/github_import/issuable_finder_spec.rb b/spec/lib/gitlab/github_import/issuable_finder_spec.rb index d3236994cef..977fef95d64 100644 --- a/spec/lib/gitlab/github_import/issuable_finder_spec.rb +++ b/spec/lib/gitlab/github_import/issuable_finder_spec.rb @@ -2,40 +2,80 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache do - let(:project) { double(:project, id: 4, import_data: import_data) } +RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache, feature_category: :importers do + let(:project) { build(:project, id: 20, import_data_attributes: import_data_attributes) } let(:single_endpoint_optional_stage) { false } - let(:import_data) do - instance_double( - ProjectImportData, + let(:import_data_attributes) do + { data: { optional_stages: { single_endpoint_notes_import: single_endpoint_optional_stage } - }.deep_stringify_keys - ) + } + } end - let(:issue) { double(:issue, issuable_type: MergeRequest, issuable_id: 1) } + let(:merge_request) { create(:merge_request, source_project: project) } + let(:issue) { double(:issue, issuable_type: 'MergeRequest', issuable_id: merge_request.iid) } let(:finder) { described_class.new(project, issue) } describe '#database_id' do - it 'returns nil when no cache is in place' do - expect(finder.database_id).to be_nil + it 'returns nil if object does not exist' do + missing_issue = double(:issue, issuable_type: 'MergeRequest', issuable_id: 999) + + expect(described_class.new(project, missing_issue).database_id).to be_nil + end + + it 'fetches object id from database if not in cache' do + expect(finder.database_id).to eq(merge_request.id) end - it 'returns the ID of an issuable when the cache is in place' do + it 'fetches object id from cache if present' do finder.cache_database_id(10) expect(finder.database_id).to eq(10) end + it 'returns nil and skips database read if cache has no record' do + finder.cache_database_id(-1) + + expect(finder.database_id).to be_nil + end + it 'raises TypeError when the object is not supported' do finder = described_class.new(project, double(:issue)) expect { finder.database_id }.to raise_error(TypeError) end + context 'with FF import_fallback_to_db_empty_cache disabled' do + before do + stub_feature_flags(import_fallback_to_db_empty_cache: false) + end + + it 'returns nil if object does not exist' do + missing_issue = double(:issue, issuable_type: 'MergeRequest', issuable_id: 999) + + expect(described_class.new(project, missing_issue).database_id).to be_nil + end + + it 'does not fetch object id from database if not in cache' do + expect(finder.database_id).to eq(nil) + end + + it 'fetches object id from cache if present' do + finder.cache_database_id(10) + + expect(finder.database_id).to eq(10) + end + + it 'returns -1 if cache is -1' do + finder.cache_database_id(-1) + + expect(finder.database_id).to eq(-1) + end + end + context 'when group is present' do context 'when settings single_endpoint_notes_import is enabled' do let(:single_endpoint_optional_stage) { true } @@ -65,7 +105,7 @@ RSpec.describe Gitlab::GithubImport::IssuableFinder, :clean_gitlab_redis_cache d it 'caches the ID of a database row' do expect(Gitlab::Cache::Import::Caching) .to receive(:write) - .with('github-import/issuable-finder/4/MergeRequest/1', 10, timeout: 86400) + .with("github-import/issuable-finder/20/MergeRequest/#{merge_request.iid}", 10, timeout: 86400) finder.cache_database_id(10) end diff --git a/spec/lib/gitlab/import/import_failure_service_spec.rb b/spec/lib/gitlab/import/import_failure_service_spec.rb index a4682a9495e..362d809bb56 100644 --- a/spec/lib/gitlab/import/import_failure_service_spec.rb +++ b/spec/lib/gitlab/import/import_failure_service_spec.rb @@ -10,7 +10,7 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures, featur let(:import_state) { nil } let(:fail_import) { false } let(:metrics) { false } - let(:external_identifiers) { {} } + let(:external_identifiers) { { foo: 'bar' } } let(:project_id) { project.id } let(:arguments) do @@ -90,13 +90,19 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures, featur ) service.execute - - expect(project.import_state.reload.status).to eq('failed') - - expect(project.import_failures).not_to be_empty - expect(project.import_failures.last.exception_class).to eq('StandardError') - expect(project.import_failures.last.exception_message).to eq('some error') - expect(project.import_failures.last.retry_count).to eq(0) + project.reload + + expect(project.import_state.status).to eq('failed') + expect(project.import_failures).to contain_exactly( + have_attributes( + retry_count: 0, + exception_class: 'StandardError', + exception_message: 'some error', + external_identifiers: external_identifiers.with_indifferent_access, + correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id, + source: 'SomeImporter' + ) + ) end end @@ -128,13 +134,19 @@ RSpec.describe Gitlab::Import::ImportFailureService, :aggregate_failures, featur ) service.execute + project.reload expect(project.import_state.reload.status).to eq('started') - - expect(project.import_failures).not_to be_empty - expect(project.import_failures.last.exception_class).to eq('StandardError') - expect(project.import_failures.last.exception_message).to eq('some error') - expect(project.import_failures.last.retry_count).to eq(nil) + expect(project.import_failures).to contain_exactly( + have_attributes( + retry_count: nil, + exception_class: 'StandardError', + exception_message: 'some error', + external_identifiers: external_identifiers.with_indifferent_access, + correlation_id_value: Labkit::Correlation::CorrelationId.current_or_new_id, + source: 'SomeImporter' + ) + ) end end diff --git a/spec/models/ml/model_version_spec.rb b/spec/models/ml/model_version_spec.rb index 83639fca9e1..5daf8b3e5e4 100644 --- a/spec/models/ml/model_version_spec.rb +++ b/spec/models/ml/model_version_spec.rb @@ -116,6 +116,29 @@ RSpec.describe Ml::ModelVersion, feature_category: :mlops do end end + describe '#by_project_id_and_id' do + let(:id) { model_version1.id } + let(:project_id) { model_version1.project.id } + + subject { described_class.by_project_id_and_id(project_id, id) } + + context 'if exists' do + it { is_expected.to eq(model_version1) } + end + + context 'if id has no match' do + let(:id) { non_existing_record_id } + + it { is_expected.to be(nil) } + end + + context 'if project id does not match' do + let(:project_id) { non_existing_record_id } + + it { is_expected.to be(nil) } + end + end + describe '.order_by_model_id_id_desc' do subject { described_class.order_by_model_id_id_desc } diff --git a/spec/presenters/ml/model_version_presenter_spec.rb b/spec/presenters/ml/model_version_presenter_spec.rb new file mode 100644 index 00000000000..4e88791f910 --- /dev/null +++ b/spec/presenters/ml/model_version_presenter_spec.rb @@ -0,0 +1,22 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Ml::ModelVersionPresenter, feature_category: :mlops do + let_it_be(:project) { build_stubbed(:project) } + let_it_be(:model) { build_stubbed(:ml_models, name: 'a_model', project: project) } + let_it_be(:model_version) { build_stubbed(:ml_model_versions, model: model, version: '1.1.1') } + let_it_be(:presenter) { model_version.present } + + describe '.display_name' do + subject { presenter.display_name } + + it { is_expected.to eq('a_model / 1.1.1') } + end + + describe '#path' do + subject { model_version.present.path } + + it { is_expected.to eq("/#{project.full_path}/-/ml/models/#{model.id}/versions/#{model_version.id}") } + end +end diff --git a/spec/requests/admin/users_controller_spec.rb b/spec/requests/admin/users_controller_spec.rb index e525d615b50..2f8025691f4 100644 --- a/spec/requests/admin/users_controller_spec.rb +++ b/spec/requests/admin/users_controller_spec.rb @@ -74,4 +74,54 @@ RSpec.describe Admin::UsersController, :enable_admin_mode, feature_category: :us expect { request }.to change { user.reload.access_locked? }.from(true).to(false) end end + + describe 'PUT #trust' do + subject(:request) { put trust_admin_user_path(user) } + + it 'trusts the user' do + expect { request }.to change { user.reload.trusted? }.from(false).to(true) + end + + context 'when setting trust fails' do + before do + allow_next_instance_of(Users::TrustService) do |instance| + allow(instance).to receive(:execute).and_return({ status: :failed }) + end + end + + it 'displays a flash alert' do + request + + expect(response).to redirect_to(admin_user_path(user)) + expect(flash[:alert]).to eq(s_('Error occurred. User was not updated')) + end + end + end + + describe 'PUT #untrust' do + before do + user.custom_attributes.create!(key: UserCustomAttribute::TRUSTED_BY, value: "placeholder") + end + + subject(:request) { put untrust_admin_user_path(user) } + + it 'trusts the user' do + expect { request }.to change { user.reload.trusted? }.from(true).to(false) + end + + context 'when untrusting fails' do + before do + allow_next_instance_of(Users::UntrustService) do |instance| + allow(instance).to receive(:execute).and_return({ status: :failed }) + end + end + + it 'displays a flash alert' do + request + + expect(response).to redirect_to(admin_user_path(user)) + expect(flash[:alert]).to eq(s_('Error occurred. User was not updated')) + end + end + end end diff --git a/spec/requests/projects/ml/model_versions_controller_spec.rb b/spec/requests/projects/ml/model_versions_controller_spec.rb new file mode 100644 index 00000000000..bd9d798c275 --- /dev/null +++ b/spec/requests/projects/ml/model_versions_controller_spec.rb @@ -0,0 +1,72 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Projects::Ml::ModelVersionsController, feature_category: :mlops do + let_it_be(:project) { create(:project) } + let_it_be(:another_project) { create(:project) } + let_it_be(:user) { project.first_owner } + let_it_be(:model) { create(:ml_models, :with_versions, project: project) } + let_it_be(:version) { model.versions.first } + + let(:model_registry_enabled) { true } + + before do + allow(Ability).to receive(:allowed?).and_call_original + allow(Ability).to receive(:allowed?) + .with(user, :read_model_registry, project) + .and_return(model_registry_enabled) + + sign_in(user) + end + + describe 'show' do + let(:model_id) { model.id } + let(:version_id) { version.id } + let(:request_project) { model.project } + + subject(:show_request) do + show_model_version + response + end + + before do + show_request + end + + it 'renders the template' do + is_expected.to render_template('projects/ml/model_versions/show') + end + + it 'fetches the correct model_version' do + show_request + + expect(assigns(:model)).to eq(model) + expect(assigns(:model_version)).to eq(version) + end + + context 'when version id does not exist' do + let(:version_id) { non_existing_record_id } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when version and model id are correct but project is not' do + let(:request_project) { another_project } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + + context 'when user does not have access' do + let(:model_registry_enabled) { false } + + it { is_expected.to have_gitlab_http_status(:not_found) } + end + end + + private + + def show_model_version + get project_ml_model_version_path(request_project, model_id, version_id) + end +end diff --git a/spec/tooling/danger/outdated_todo_spec.rb b/spec/tooling/danger/outdated_todo_spec.rb new file mode 100644 index 00000000000..3a3909c69ac --- /dev/null +++ b/spec/tooling/danger/outdated_todo_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'gitlab/dangerfiles/spec_helper' + +require_relative '../../../tooling/danger/outdated_todo' + +RSpec.describe Tooling::Danger::OutdatedTodo, feature_category: :tooling do + let(:fake_danger) { double } + let(:filenames) { ['app/controllers/application_controller.rb'] } + + let(:todos) do + [ + File.join('spec', 'fixtures', 'tooling', 'danger', 'rubocop_todo', '**', '*.yml') + ] + end + + subject(:plugin) { described_class.new(filenames, context: fake_danger, todos: todos) } + + context 'when the filenames are mentioned in single todo' do + let(:filenames) { ['app/controllers/acme_challenges_controller.rb'] } + + it 'warns about mentions' do + expect(fake_danger) + .to receive(:warn) + .with <<~MESSAGE + `app/controllers/acme_challenges_controller.rb` was removed but is mentioned in: + - `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5` + MESSAGE + + plugin.check + end + end + + context 'when the filenames are mentioned in multiple todos' do + let(:filenames) do + [ + 'app/controllers/application_controller.rb', + 'app/controllers/acme_challenges_controller.rb' + ] + end + + it 'warns about mentions' do + expect(fake_danger) + .to receive(:warn) + .with(<<~FIRSTMESSAGE) + `app/controllers/application_controller.rb` was removed but is mentioned in: + - `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:4` + - `spec/fixtures/tooling/danger/rubocop_todo/cop2.yml:4` + FIRSTMESSAGE + + expect(fake_danger) + .to receive(:warn) + .with(<<~SECONDMESSAGE) + `app/controllers/acme_challenges_controller.rb` was removed but is mentioned in: + - `spec/fixtures/tooling/danger/rubocop_todo/cop1.yml:5` + SECONDMESSAGE + + plugin.check + end + end + + context 'when the filenames are not mentioned in todos' do + let(:filenames) { ['any/inexisting/file.rb'] } + + it 'does not warn' do + expect(fake_danger).not_to receive(:warn) + + plugin.check + end + end + + context 'when there is no todos' do + let(:filenames) { ['app/controllers/acme_challenges_controller.rb'] } + let(:todos) { [] } + + it 'does not warn' do + expect(fake_danger).not_to receive(:warn) + + plugin.check + end + end +end diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb index c8f7427d5ae..898606845a2 100644 --- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb @@ -145,12 +145,16 @@ RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers .to receive(:import) .with(client, project) + expect(project.import_state).to receive(:refresh_jid_expiration) + worker.try_import(client, project) end it 'reschedules the worker if RateLimitError was raised' do client = double(:client, rate_limit_resets_in: 10) + expect(project.import_state).to receive(:refresh_jid_expiration) + expect(worker) .to receive(:import) .with(client, project) diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index f3b706361e3..b8f2db8e2d9 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -23,8 +23,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker, feature_catego expect(importer).to receive(:execute) end - expect(import_state).to receive(:refresh_jid_expiration) - expect(Gitlab::GithubImport::Stage::ImportPullRequestsWorker) .to receive(:perform_async) .with(project.id) diff --git a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb index fc38adb5447..71170718721 100644 --- a/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_collaborators_worker_spec.rb @@ -33,8 +33,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportCollaboratorsWorker, feature_c .and_return(importer) expect(importer).to receive(:execute).and_return(waiter) - expect(import_state).to receive(:refresh_jid_expiration) - expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) .with(project.id, { '123' => 2 }, :pull_requests_merged_by) diff --git a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb index 7ecce82dacb..0bfae640e23 100644 --- a/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_protected_branches_worker_spec.rb @@ -25,9 +25,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportProtectedBranchesWorker, featu .to receive(:execute) .and_return(waiter) - expect(import_state) - .to receive(:refresh_jid_expiration) - expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) .with(project.id, { '123' => 2 }, :lfs_objects) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb index 5917b827d65..158efce2a9e 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_merged_by_worker_spec.rb @@ -24,9 +24,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsMergedByWorker, fe .to receive(:execute) .and_return(waiter) - expect(import_state) - .to receive(:refresh_jid_expiration) - expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) .with(project.id, { '123' => 2 }, :pull_request_review_requests) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb index b473de73086..8f71a18036b 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_review_requests_worker_spec.rb @@ -6,7 +6,7 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWork subject(:worker) { described_class.new } let(:project) { instance_double(Project, id: 1, import_state: import_state) } - let(:import_state) { instance_double(ProjectImportState, refresh_jid_expiration: true) } + let(:import_state) { instance_double(ProjectImportState) } let(:client) { instance_double(Gitlab::GithubImport::Client) } let(:importer) { instance_double(Gitlab::GithubImport::Importer::PullRequests::ReviewRequestsImporter) } let(:waiter) { Gitlab::JobWaiter.new(2, '123') } @@ -21,7 +21,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewRequestsWork .and_return(importer) expect(importer).to receive(:execute).and_return(waiter) - expect(import_state).to receive(:refresh_jid_expiration) expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb index 34d3ce9fe95..f783baea349 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_reviews_worker_spec.rb @@ -25,8 +25,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsReviewsWorker, fea .to receive(:execute) .and_return(waiter) - expect(import_state).to receive(:refresh_jid_expiration) - expect(Gitlab::GithubImport::AdvanceStageWorker) .to receive(:perform_async) .with(project.id, { '123' => 2 }, :issues_and_diff_notes) diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index f9b4a8a99f0..c2b97335229 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -27,9 +27,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_ca .to receive(:execute) .and_return(waiter) - expect(import_state) - .to receive(:refresh_jid_expiration) - expect(InternalId).to receive(:exists?).and_return(false) expect(client).to receive(:each_object).with( @@ -59,9 +56,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_ca .to receive(:execute) .and_return(waiter) - expect(import_state) - .to receive(:refresh_jid_expiration) - expect(InternalId).to receive(:exists?).and_return(false) expect(client).to receive(:each_object).with( @@ -91,9 +85,6 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker, feature_ca .to receive(:execute) .and_return(waiter) - expect(import_state) - .to receive(:refresh_jid_expiration) - expect(InternalId).to receive(:exists?).and_return(true) expect(client).not_to receive(:each_object) |