diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 21:09:38 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-04-30 21:09:38 +0300 |
commit | 028bb5dda7abc9ec76f21ae8e691825b4673f733 (patch) | |
tree | a41741811452f928c6f650451c69fc18e46b62a4 /spec | |
parent | 7f305b576b51c3503970ef224cf4b31e247a322d (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
38 files changed, 195 insertions, 173 deletions
diff --git a/spec/controllers/oauth/token_info_controller_spec.rb b/spec/controllers/oauth/token_info_controller_spec.rb index 4b3539879df..4658c2702ca 100644 --- a/spec/controllers/oauth/token_info_controller_spec.rb +++ b/spec/controllers/oauth/token_info_controller_spec.rb @@ -9,7 +9,7 @@ RSpec.describe Oauth::TokenInfoController do get :show expect(response).to have_gitlab_http_status(:unauthorized) - expect(JSON.parse(response.body)).to include('error' => 'invalid_request') + expect(Gitlab::Json.parse(response.body)).to include('error' => 'invalid_request') end end @@ -23,7 +23,7 @@ RSpec.describe Oauth::TokenInfoController do get :show, params: { access_token: access_token.token } expect(response).to have_gitlab_http_status(:ok) - expect(JSON.parse(response.body)).to eq( + expect(Gitlab::Json.parse(response.body)).to eq( 'scope' => %w[api], 'scopes' => %w[api], 'created_at' => access_token.created_at.to_i, @@ -40,7 +40,7 @@ RSpec.describe Oauth::TokenInfoController do get :show, params: { access_token: 'unknown_token' } expect(response).to have_gitlab_http_status(:unauthorized) - expect(JSON.parse(response.body)).to include('error' => 'invalid_request') + expect(Gitlab::Json.parse(response.body)).to include('error' => 'invalid_request') end end @@ -53,7 +53,7 @@ RSpec.describe Oauth::TokenInfoController do get :show, params: { access_token: access_token.token } expect(response).to have_gitlab_http_status(:unauthorized) - expect(JSON.parse(response.body)).to include('error' => 'invalid_request') + expect(Gitlab::Json.parse(response.body)).to include('error' => 'invalid_request') end end @@ -64,7 +64,7 @@ RSpec.describe Oauth::TokenInfoController do get :show, params: { access_token: access_token.token } expect(response).to have_gitlab_http_status(:unauthorized) - expect(JSON.parse(response.body)).to include('error' => 'invalid_request') + expect(Gitlab::Json.parse(response.body)).to include('error' => 'invalid_request') end end end diff --git a/spec/controllers/projects/artifacts_controller_spec.rb b/spec/controllers/projects/artifacts_controller_spec.rb index c59983d5138..aa3371f7ddf 100644 --- a/spec/controllers/projects/artifacts_controller_spec.rb +++ b/spec/controllers/projects/artifacts_controller_spec.rb @@ -334,7 +334,7 @@ describe Projects::ArtifactsController do def params @params ||= begin base64_params = send_data.sub(/\Aartifacts\-entry:/, '') - JSON.parse(Base64.urlsafe_decode64(base64_params)) + Gitlab::Json.parse(Base64.urlsafe_decode64(base64_params)) end end end diff --git a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb index b828c678d0c..942e095d669 100644 --- a/spec/controllers/projects/cycle_analytics/events_controller_spec.rb +++ b/spec/controllers/projects/cycle_analytics/events_controller_spec.rb @@ -17,7 +17,7 @@ describe Projects::CycleAnalytics::EventsController do get_issue expect(response).to be_successful - expect(JSON.parse(response.body)['events']).to be_empty + expect(Gitlab::Json.parse(response.body)['events']).to be_empty end end @@ -38,7 +38,7 @@ describe Projects::CycleAnalytics::EventsController do it 'contains event detais' do get_issue - events = JSON.parse(response.body)['events'] + events = Gitlab::Json.parse(response.body)['events'] expect(events).not_to be_empty expect(events.first).to include('title', 'author', 'iid', 'total_time', 'created_at', 'url') @@ -51,7 +51,7 @@ describe Projects::CycleAnalytics::EventsController do expect(response).to be_successful - expect(JSON.parse(response.body)['events']).to be_empty + expect(Gitlab::Json.parse(response.body)['events']).to be_empty end end end diff --git a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb b/spec/controllers/projects/environments/prometheus_api_controller_spec.rb index 793c10f0b21..fcb9293d4a9 100644 --- a/spec/controllers/projects/environments/prometheus_api_controller_spec.rb +++ b/spec/controllers/projects/environments/prometheus_api_controller_spec.rb @@ -38,7 +38,7 @@ describe Projects::Environments::PrometheusApiController do context 'with success result' do let(:service_result) { { status: :success, body: prometheus_body } } let(:prometheus_body) { '{"status":"success"}' } - let(:prometheus_json_body) { JSON.parse(prometheus_body) } + let(:prometheus_json_body) { Gitlab::Json.parse(prometheus_body) } it 'returns prometheus response' do get :proxy, params: environment_params diff --git a/spec/controllers/projects/logs_controller_spec.rb b/spec/controllers/projects/logs_controller_spec.rb index ea71dbe45aa..cc0690788c7 100644 --- a/spec/controllers/projects/logs_controller_spec.rb +++ b/spec/controllers/projects/logs_controller_spec.rb @@ -50,7 +50,7 @@ describe Projects::LogsController do container_name: container } end - let(:service_result_json) { JSON.parse(service_result.to_json) } + let(:service_result_json) { Gitlab::Json.parse(service_result.to_json) } let_it_be(:cluster) { create(:cluster, :provided_by_gcp, environment_scope: '*', projects: [project]) } diff --git a/spec/features/error_tracking/user_filters_errors_by_status_spec.rb b/spec/features/error_tracking/user_filters_errors_by_status_spec.rb index 51e29e2a5ec..4b5bc16c4db 100644 --- a/spec/features/error_tracking/user_filters_errors_by_status_spec.rb +++ b/spec/features/error_tracking/user_filters_errors_by_status_spec.rb @@ -6,7 +6,7 @@ describe 'When a user filters Sentry errors by status', :js, :use_clean_rails_me include_context 'sentry error tracking context feature' let_it_be(:issues_response_body) { fixture_file('sentry/issues_sample_response.json') } - let_it_be(:filtered_errors_by_status_response) { JSON.parse(issues_response_body).filter { |error| error['status'] == 'ignored' }.to_json } + let_it_be(:filtered_errors_by_status_response) { Gitlab::Json.parse(issues_response_body).filter { |error| error['status'] == 'ignored' }.to_json } let(:issues_api_url) { "#{sentry_api_urls.issues_url}?limit=20&query=is:unresolved" } let(:issues_api_url_filter) { "#{sentry_api_urls.issues_url}?limit=20&query=is:ignored" } let(:auth_token) {{ 'Authorization' => 'Bearer access_token_123' }} diff --git a/spec/features/error_tracking/user_sees_error_index_spec.rb b/spec/features/error_tracking/user_sees_error_index_spec.rb index 842e4a2e8b5..34a3a4b5a49 100644 --- a/spec/features/error_tracking/user_sees_error_index_spec.rb +++ b/spec/features/error_tracking/user_sees_error_index_spec.rb @@ -6,7 +6,7 @@ describe 'View error index page', :js, :use_clean_rails_memory_store_caching, :s include_context 'sentry error tracking context feature' let_it_be(:issues_response_body) { fixture_file('sentry/issues_sample_response.json') } - let_it_be(:issues_response) { JSON.parse(issues_response_body) } + let_it_be(:issues_response) { Gitlab::Json.parse(issues_response_body) } let(:issues_api_url) { "#{sentry_api_urls.issues_url}?limit=20&query=is:unresolved" } before do diff --git a/spec/features/projects/import_export/export_file_spec.rb b/spec/features/projects/import_export/export_file_spec.rb index 7ee8f42e6ef..1d6d5ae1b4d 100644 --- a/spec/features/projects/import_export/export_file_spec.rb +++ b/spec/features/projects/import_export/export_file_spec.rb @@ -52,7 +52,7 @@ describe 'Import/Export - project export integration test', :js do project_json_path = File.join(tmpdir, 'project.json') expect(File).to exist(project_json_path) - project_hash = JSON.parse(IO.read(project_json_path)) + project_hash = Gitlab::Json.parse(IO.read(project_json_path)) sensitive_words.each do |sensitive_word| found = find_sensitive_attributes(sensitive_word, project_hash) @@ -78,7 +78,7 @@ describe 'Import/Export - project export integration test', :js do expect(File).to exist(project_json_path) relations = [] - relations << JSON.parse(IO.read(project_json_path)) + relations << Gitlab::Json.parse(IO.read(project_json_path)) Dir.glob(File.join(tmpdir, 'tree/project', '*.ndjson')) do |rb_filename| File.foreach(rb_filename) do |line| json = ActiveSupport::JSON.decode(line) diff --git a/spec/features/projects/settings/operations_settings_spec.rb b/spec/features/projects/settings/operations_settings_spec.rb index 3c9102431e8..752353cf2f5 100644 --- a/spec/features/projects/settings/operations_settings_spec.rb +++ b/spec/features/projects/settings/operations_settings_spec.rb @@ -76,7 +76,7 @@ describe 'Projects > Settings > For a forked project', :js do context 'success path' do let(:projects_sample_response) do Gitlab::Utils.deep_indifferent_access( - JSON.parse(fixture_file('sentry/list_projects_sample_response.json')) + Gitlab::Json.parse(fixture_file('sentry/list_projects_sample_response.json')) ) end diff --git a/spec/features/projects/settings/registry_settings_spec.rb b/spec/features/projects/settings/registry_settings_spec.rb index 74d3544ce92..ba92e8bc516 100644 --- a/spec/features/projects/settings/registry_settings_spec.rb +++ b/spec/features/projects/settings/registry_settings_spec.rb @@ -29,7 +29,7 @@ describe 'Project > Settings > CI/CD > Container registry tag expiration policy' select('7 days until tags are automatically removed', from: 'Expiration interval:') select('Every day', from: 'Expiration schedule:') select('50 tags per image name', from: 'Number of tags to retain:') - fill_in('Docker tags with names matching this regex pattern will expire:', with: '*-production') + fill_in('Tags with names matching this regex pattern will expire:', with: '*-production') end submit_button = find('.card-footer .btn.btn-success') expect(submit_button).not_to be_disabled diff --git a/spec/javascripts/integrations/integration_settings_form_spec.js b/spec/frontend/integrations/integration_settings_form_spec.js index 72d04be822f..c117a37ff2f 100644 --- a/spec/javascripts/integrations/integration_settings_form_spec.js +++ b/spec/frontend/integrations/integration_settings_form_spec.js @@ -16,7 +16,7 @@ describe('IntegrationSettingsForm', () => { beforeEach(() => { integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); - spyOn(integrationSettingsForm, 'init'); + jest.spyOn(integrationSettingsForm, 'init').mockImplementation(() => {}); }); it('should initialize form element refs on class object', () => { @@ -130,7 +130,7 @@ describe('IntegrationSettingsForm', () => { beforeEach(() => { mock = new MockAdaptor(axios); - spyOn(axios, 'put').and.callThrough(); + jest.spyOn(axios, 'put'); integrationSettingsForm = new IntegrationSettingsForm('.js-integration-settings-form'); // eslint-disable-next-line no-jquery/no-serialize @@ -141,18 +141,13 @@ describe('IntegrationSettingsForm', () => { mock.restore(); }); - it('should make an ajax request with provided `formData`', done => { - integrationSettingsForm - .testSettings(formData) - .then(() => { - expect(axios.put).toHaveBeenCalledWith(integrationSettingsForm.testEndPoint, formData); - - done(); - }) - .catch(done.fail); + it('should make an ajax request with provided `formData`', () => { + return integrationSettingsForm.testSettings(formData).then(() => { + expect(axios.put).toHaveBeenCalledWith(integrationSettingsForm.testEndPoint, formData); + }); }); - it('should show error Flash with `Save anyway` action if ajax request responds with error in test', done => { + it('should show error Flash with `Save anyway` action if ajax request responds with error in test', () => { const errorMessage = 'Test failed.'; mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { error: true, @@ -161,32 +156,27 @@ describe('IntegrationSettingsForm', () => { test_failed: true, }); - integrationSettingsForm - .testSettings(formData) - .then(() => { - const $flashContainer = $('.flash-container'); - - expect( - $flashContainer - .find('.flash-text') - .text() - .trim(), - ).toEqual('Test failed. some error'); - - expect($flashContainer.find('.flash-action')).toBeDefined(); - expect( - $flashContainer - .find('.flash-action') - .text() - .trim(), - ).toEqual('Save anyway'); - - done(); - }) - .catch(done.fail); + return integrationSettingsForm.testSettings(formData).then(() => { + const $flashContainer = $('.flash-container'); + + expect( + $flashContainer + .find('.flash-text') + .text() + .trim(), + ).toEqual('Test failed. some error'); + + expect($flashContainer.find('.flash-action')).toBeDefined(); + expect( + $flashContainer + .find('.flash-action') + .text() + .trim(), + ).toEqual('Save anyway'); + }); }); - it('should not show error Flash with `Save anyway` action if ajax request responds with error in validation', done => { + it('should not show error Flash with `Save anyway` action if ajax request responds with error in validation', () => { const errorMessage = 'Validations failed.'; mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { error: true, @@ -195,50 +185,40 @@ describe('IntegrationSettingsForm', () => { test_failed: false, }); - integrationSettingsForm - .testSettings(formData) - .then(() => { - const $flashContainer = $('.flash-container'); - - expect( - $flashContainer - .find('.flash-text') - .text() - .trim(), - ).toEqual('Validations failed. some error'); - - expect($flashContainer.find('.flash-action')).toBeDefined(); - expect( - $flashContainer - .find('.flash-action') - .text() - .trim(), - ).toEqual(''); - - done(); - }) - .catch(done.fail); + return integrationSettingsForm.testSettings(formData).then(() => { + const $flashContainer = $('.flash-container'); + + expect( + $flashContainer + .find('.flash-text') + .text() + .trim(), + ).toEqual('Validations failed. some error'); + + expect($flashContainer.find('.flash-action')).toBeDefined(); + expect( + $flashContainer + .find('.flash-action') + .text() + .trim(), + ).toEqual(''); + }); }); - it('should submit form if ajax request responds without any error in test', done => { - spyOn(integrationSettingsForm.$form, 'submit'); + it('should submit form if ajax request responds without any error in test', () => { + jest.spyOn(integrationSettingsForm.$form, 'submit').mockImplementation(() => {}); mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { error: false, }); - integrationSettingsForm - .testSettings(formData) - .then(() => { - expect(integrationSettingsForm.$form.submit).toHaveBeenCalled(); - - done(); - }) - .catch(done.fail); + return integrationSettingsForm.testSettings(formData).then(() => { + expect(integrationSettingsForm.$form.submit).toHaveBeenCalled(); + }); }); - it('should submit form when clicked on `Save anyway` action of error Flash', done => { - spyOn(integrationSettingsForm.$form, 'submit'); + it('should submit form when clicked on `Save anyway` action of error Flash', () => { + jest.spyOn(integrationSettingsForm.$form, 'submit').mockImplementation(() => {}); const errorMessage = 'Test failed.'; mock.onPut(integrationSettingsForm.testEndPoint).reply(200, { @@ -247,7 +227,7 @@ describe('IntegrationSettingsForm', () => { test_failed: true, }); - integrationSettingsForm + return integrationSettingsForm .testSettings(formData) .then(() => { const $flashAction = $('.flash-container .flash-action'); @@ -258,44 +238,31 @@ describe('IntegrationSettingsForm', () => { }) .then(() => { expect(integrationSettingsForm.$form.submit).toHaveBeenCalled(); - - done(); - }) - .catch(done.fail); + }); }); - it('should show error Flash if ajax request failed', done => { + it('should show error Flash if ajax request failed', () => { const errorMessage = 'Something went wrong on our end.'; mock.onPut(integrationSettingsForm.testEndPoint).networkError(); - integrationSettingsForm - .testSettings(formData) - .then(() => { - expect( - $('.flash-container .flash-text') - .text() - .trim(), - ).toEqual(errorMessage); - - done(); - }) - .catch(done.fail); + return integrationSettingsForm.testSettings(formData).then(() => { + expect( + $('.flash-container .flash-text') + .text() + .trim(), + ).toEqual(errorMessage); + }); }); - it('should always call `toggleSubmitBtnState` with `false` once request is completed', done => { + it('should always call `toggleSubmitBtnState` with `false` once request is completed', () => { mock.onPut(integrationSettingsForm.testEndPoint).networkError(); - spyOn(integrationSettingsForm, 'toggleSubmitBtnState'); + jest.spyOn(integrationSettingsForm, 'toggleSubmitBtnState').mockImplementation(() => {}); - integrationSettingsForm - .testSettings(formData) - .then(() => { - expect(integrationSettingsForm.toggleSubmitBtnState).toHaveBeenCalledWith(false); - - done(); - }) - .catch(done.fail); + return integrationSettingsForm.testSettings(formData).then(() => { + expect(integrationSettingsForm.toggleSubmitBtnState).toHaveBeenCalledWith(false); + }); }); }); }); diff --git a/spec/frontend/registry/settings/store/getters_spec.js b/spec/frontend/registry/settings/store/getters_spec.js index 944057ebc9f..b781d09466c 100644 --- a/spec/frontend/registry/settings/store/getters_spec.js +++ b/spec/frontend/registry/settings/store/getters_spec.js @@ -4,9 +4,12 @@ import { formOptions } from '../../shared/mock_data'; describe('Getters registry settings store', () => { const settings = { + enabled: true, cadence: 'foo', keep_n: 'bar', older_than: 'baz', + name_regex: 'name-foo', + name_regex_keep: 'name-keep-bar', }; describe.each` @@ -29,6 +32,17 @@ describe('Getters registry settings store', () => { }); }); + describe('getSettings', () => { + it('returns the content of settings', () => { + const computedGetters = { + getCadence: settings.cadence, + getOlderThan: settings.older_than, + getKeepN: settings.keep_n, + }; + expect(getters.getSettings({ settings }, computedGetters)).toEqual(settings); + }); + }); + describe('getIsEdited', () => { it('returns false when original is equal to settings', () => { const same = { foo: 'bar' }; diff --git a/spec/frontend/registry/shared/components/__snapshots__/expiration_policy_fields_spec.js.snap b/spec/frontend/registry/shared/components/__snapshots__/expiration_policy_fields_spec.js.snap index 6e7bc0491ce..a9034b81d2f 100644 --- a/spec/frontend/registry/shared/components/__snapshots__/expiration_policy_fields_spec.js.snap +++ b/spec/frontend/registry/shared/components/__snapshots__/expiration_policy_fields_spec.js.snap @@ -117,11 +117,11 @@ exports[`Expiration Policy Form renders 1`] = ` <gl-form-group-stub id="expiration-policy-name-matching-group" invalid-feedback="The value of this input should be less than 255 characters" - label="Docker tags with names matching this regex pattern will expire:" label-align="right" label-cols="3" label-for="expiration-policy-name-matching" > + <gl-form-textarea-stub disabled="true" id="expiration-policy-name-matching" @@ -130,5 +130,21 @@ exports[`Expiration Policy Form renders 1`] = ` value="" /> </gl-form-group-stub> + <gl-form-group-stub + id="expiration-policy-keep-name-group" + invalid-feedback="The value of this input should be less than 255 characters" + label-align="right" + label-cols="3" + label-for="expiration-policy-keep-name" + > + + <gl-form-textarea-stub + disabled="true" + id="expiration-policy-keep-name" + placeholder="" + trim="" + value="" + /> + </gl-form-group-stub> </div> `; diff --git a/spec/frontend/registry/shared/components/expiration_policy_fields_spec.js b/spec/frontend/registry/shared/components/expiration_policy_fields_spec.js index 3782bfeaac4..4825351a6d3 100644 --- a/spec/frontend/registry/shared/components/expiration_policy_fields_spec.js +++ b/spec/frontend/registry/shared/components/expiration_policy_fields_spec.js @@ -40,12 +40,13 @@ describe('Expiration Policy Form', () => { }); describe.each` - elementName | modelName | value | disabledByToggle - ${'toggle'} | ${'enabled'} | ${true} | ${'not disabled'} - ${'interval'} | ${'older_than'} | ${'foo'} | ${'disabled'} - ${'schedule'} | ${'cadence'} | ${'foo'} | ${'disabled'} - ${'latest'} | ${'keep_n'} | ${'foo'} | ${'disabled'} - ${'name-matching'} | ${'name_regex'} | ${'foo'} | ${'disabled'} + elementName | modelName | value | disabledByToggle + ${'toggle'} | ${'enabled'} | ${true} | ${'not disabled'} + ${'interval'} | ${'older_than'} | ${'foo'} | ${'disabled'} + ${'schedule'} | ${'cadence'} | ${'foo'} | ${'disabled'} + ${'latest'} | ${'keep_n'} | ${'foo'} | ${'disabled'} + ${'name-matching'} | ${'name_regex'} | ${'foo'} | ${'disabled'} + ${'keep-name'} | ${'name_regex_keep'} | ${'bar'} | ${'disabled'} `( `${FORM_ELEMENTS_ID_PREFIX}-$elementName form element`, ({ elementName, modelName, value, disabledByToggle }) => { @@ -118,21 +119,26 @@ describe('Expiration Policy Form', () => { ${'schedule'} ${'latest'} ${'name-matching'} + ${'keep-name'} `(`${FORM_ELEMENTS_ID_PREFIX}-$elementName is disabled`, ({ elementName }) => { expect(findFormElements(elementName).attributes('disabled')).toBe('true'); }); }); - describe('form validation', () => { + describe.each` + modelName | elementName | stateVariable + ${'name_regex'} | ${'name-matching'} | ${'nameRegexState'} + ${'name_regex_keep'} | ${'keep-name'} | ${'nameKeepRegexState'} + `('regex textarea validation', ({ modelName, elementName, stateVariable }) => { describe(`when name regex is longer than ${NAME_REGEX_LENGTH}`, () => { const invalidString = new Array(NAME_REGEX_LENGTH + 2).join(','); beforeEach(() => { - mountComponent({ value: { name_regex: invalidString } }); + mountComponent({ value: { [modelName]: invalidString } }); }); - it('nameRegexState is false', () => { - expect(wrapper.vm.nameRegexState).toBe(false); + it(`${stateVariable} is false`, () => { + expect(wrapper.vm.textAreaState[stateVariable]).toBe(false); }); it('emit the @invalidated event', () => { @@ -141,17 +147,20 @@ describe('Expiration Policy Form', () => { }); it('if the user did not type validation is null', () => { - mountComponent({ value: { name_regex: '' } }); + mountComponent({ value: { [modelName]: '' } }); return wrapper.vm.$nextTick().then(() => { - expect(wrapper.vm.nameRegexState).toBe(null); + expect(wrapper.vm.textAreaState[stateVariable]).toBe(null); expect(wrapper.emitted('validated')).toBeTruthy(); }); }); it(`if the user typed and is less than ${NAME_REGEX_LENGTH} state is true`, () => { - mountComponent({ value: { name_regex: 'foo' } }); + mountComponent({ value: { [modelName]: 'foo' } }); return wrapper.vm.$nextTick().then(() => { - expect(wrapper.vm.nameRegexState).toBe(true); + const formGroup = findFormGroup(elementName); + const formElement = findFormElements(elementName, formGroup); + expect(formGroup.attributes('state')).toBeTruthy(); + expect(formElement.attributes('state')).toBeTruthy(); }); }); }); diff --git a/spec/frontend/static_site_editor/components/saved_changes_message_spec.js b/spec/frontend/static_site_editor/components/saved_changes_message_spec.js index 659e9be59d2..a63c3a83395 100644 --- a/spec/frontend/static_site_editor/components/saved_changes_message_spec.js +++ b/spec/frontend/static_site_editor/components/saved_changes_message_spec.js @@ -46,14 +46,11 @@ describe('~/static_site_editor/components/saved_changes_message.vue', () => { ${'branch'} | ${findBranchLink} | ${props.branch} ${'commit'} | ${findCommitLink} | ${props.commit} ${'merge request'} | ${findMergeRequestLink} | ${props.mergeRequest} - `('renders $desc link', ({ desc, findEl, prop }) => { + `('renders $desc link', ({ findEl, prop }) => { const el = findEl(); expect(el.exists()).toBe(true); expect(el.text()).toBe(prop.label); - - if (desc !== 'branch') { - expect(el.attributes('href')).toBe(prop.url); - } + expect(el.attributes('href')).toBe(prop.url); }); }); diff --git a/spec/frontend/static_site_editor/mock_data.js b/spec/frontend/static_site_editor/mock_data.js index 962047e6dd2..c90ecc96521 100644 --- a/spec/frontend/static_site_editor/mock_data.js +++ b/spec/frontend/static_site_editor/mock_data.js @@ -34,6 +34,9 @@ export const savedContentMeta = { }; export const submitChangesError = 'Could not save changes'; +export const commitBranchResponse = { + web_url: '/tree/root-master-patch-88195', +}; export const commitMultipleResponse = { short_id: 'ed899a2f4b5', web_url: '/commit/ed899a2f4b5', diff --git a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js index 9a0bd88b57d..962950ec96c 100644 --- a/spec/frontend/static_site_editor/services/submit_content_changes_spec.js +++ b/spec/frontend/static_site_editor/services/submit_content_changes_spec.js @@ -13,6 +13,7 @@ import submitContentChanges from '~/static_site_editor/services/submit_content_c import { username, projectId, + commitBranchResponse, commitMultipleResponse, createMergeRequestResponse, sourcePath, @@ -26,7 +27,7 @@ describe('submitContentChanges', () => { const branch = 'branch-name'; beforeEach(() => { - jest.spyOn(Api, 'createBranch').mockResolvedValue(); + jest.spyOn(Api, 'createBranch').mockResolvedValue({ data: commitBranchResponse }); jest.spyOn(Api, 'commitMultiple').mockResolvedValue({ data: commitMultipleResponse }); jest .spyOn(Api, 'createProjectMergeRequest') diff --git a/spec/helpers/todos_helper_spec.rb b/spec/helpers/todos_helper_spec.rb index 7c73b990338..69da5707b2a 100644 --- a/spec/helpers/todos_helper_spec.rb +++ b/spec/helpers/todos_helper_spec.rb @@ -32,7 +32,7 @@ describe TodosHelper do { 'id' => projects.first.id, 'text' => projects.first.full_name } ] - expect(JSON.parse(helper.todo_projects_options)).to match_array(expected_results) + expect(Gitlab::Json.parse(helper.todo_projects_options)).to match_array(expected_results) end end end diff --git a/spec/initializers/lograge_spec.rb b/spec/initializers/lograge_spec.rb index 48acdac74ac..c243217d2a2 100644 --- a/spec/initializers/lograge_spec.rb +++ b/spec/initializers/lograge_spec.rb @@ -123,7 +123,7 @@ describe 'lograge', type: :request do let(:logger) do Logger.new(log_output).tap { |logger| logger.formatter = ->(_, _, _, msg) { msg } } end - let(:log_data) { JSON.parse(log_output.string) } + let(:log_data) { Gitlab::Json.parse(log_output.string) } before do Lograge.logger = logger diff --git a/spec/lib/gitlab/database/with_lock_retries_spec.rb b/spec/lib/gitlab/database/with_lock_retries_spec.rb index b6321f2eab1..9c8c9749125 100644 --- a/spec/lib/gitlab/database/with_lock_retries_spec.rb +++ b/spec/lib/gitlab/database/with_lock_retries_spec.rb @@ -84,7 +84,7 @@ describe Gitlab::Database::WithLockRetries do subject.run do lock_attempts += 1 - if lock_attempts == retry_count # we reached the last retry iteration, if we kill the thread, the last try (no lock_timeout) will succeed) + if lock_attempts == retry_count # we reached the last retry iteration, if we kill the thread, the last try (no lock_timeout) will succeed lock_fiber.resume end @@ -106,9 +106,13 @@ describe Gitlab::Database::WithLockRetries do end context 'after the retries, without setting lock_timeout' do - let(:retry_count) { timing_configuration.size } + let(:retry_count) { timing_configuration.size + 1 } - it_behaves_like 'retriable exclusive lock on `projects`' + it_behaves_like 'retriable exclusive lock on `projects`' do + before do + expect(subject).to receive(:run_block_without_lock_timeout).and_call_original + end + end end context 'when statement timeout is reached' do @@ -129,11 +133,22 @@ describe Gitlab::Database::WithLockRetries do end end + context 'restore local database variables' do + it do + expect { subject.run {} }.not_to change { ActiveRecord::Base.connection.execute("SHOW lock_timeout").to_a } + end + + it do + expect { subject.run {} }.not_to change { ActiveRecord::Base.connection.execute("SHOW idle_in_transaction_session_timeout").to_a } + end + end + context 'casting durations correctly' do let(:timing_configuration) { [[0.015.seconds, 0.025.seconds], [0.015.seconds, 0.025.seconds]] } # 15ms, 25ms it 'executes `SET LOCAL lock_timeout` using the configured timeout value in milliseconds' do expect(ActiveRecord::Base.connection).to receive(:execute).with("SAVEPOINT active_record_1").and_call_original + expect(ActiveRecord::Base.connection).to receive(:execute).with('RESET idle_in_transaction_session_timeout; RESET lock_timeout').and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("SET LOCAL lock_timeout TO '15ms'").and_call_original expect(ActiveRecord::Base.connection).to receive(:execute).with("RELEASE SAVEPOINT active_record_1").and_call_original diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index cae81540cd0..3df87e5d2b4 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -2351,7 +2351,7 @@ describe Ci::Pipeline, :mailer do def have_requested_pipeline_hook(status) have_requested(:post, stubbed_hostname(hook.url)).with do |req| - json_body = JSON.parse(req.body) + json_body = Gitlab::Json.parse(req.body) json_body['object_attributes']['status'] == status && json_body['builds'].length == 2 end diff --git a/spec/models/clusters/applications/jupyter_spec.rb b/spec/models/clusters/applications/jupyter_spec.rb index 3bc5088d1ab..937db9217f3 100644 --- a/spec/models/clusters/applications/jupyter_spec.rb +++ b/spec/models/clusters/applications/jupyter_spec.rb @@ -57,7 +57,7 @@ describe Clusters::Applications::Jupyter do it 'is initialized with 4 arguments' do expect(subject.name).to eq('jupyter') expect(subject.chart).to eq('jupyter/jupyterhub') - expect(subject.version).to eq('0.9.0-beta.2') + expect(subject.version).to eq('0.9.0') expect(subject).to be_rbac expect(subject.repository).to eq('https://jupyterhub.github.io/helm-chart/') @@ -76,7 +76,7 @@ describe Clusters::Applications::Jupyter do let(:jupyter) { create(:clusters_applications_jupyter, :errored, version: '0.0.1') } it 'is initialized with the locked version' do - expect(subject.version).to eq('0.9.0-beta.2') + expect(subject.version).to eq('0.9.0') end end end diff --git a/spec/models/container_repository_spec.rb b/spec/models/container_repository_spec.rb index 59bade3c841..1eecefe5d4a 100644 --- a/spec/models/container_repository_spec.rb +++ b/spec/models/container_repository_spec.rb @@ -19,7 +19,7 @@ describe ContainerRepository do .with(headers: { 'Accept' => ContainerRegistry::Client::ACCEPTED_TYPES.join(', ') }) .to_return( status: 200, - body: JSON.dump(tags: ['test_tag']), + body: Gitlab::Json.dump(tags: ['test_tag']), headers: { 'Content-Type' => 'application/json' }) end diff --git a/spec/models/project_services/irker_service_spec.rb b/spec/models/project_services/irker_service_spec.rb index badc964db16..88a93eef214 100644 --- a/spec/models/project_services/irker_service_spec.rb +++ b/spec/models/project_services/irker_service_spec.rb @@ -65,7 +65,7 @@ describe IrkerService do conn = @irker_server.accept conn.each_line do |line| - msg = JSON.parse(line.chomp("\n")) + msg = Gitlab::Json.parse(line.chomp("\n")) expect(msg.keys).to match_array(%w(to privmsg)) expect(msg['to']).to match_array(["irc://chat.freenode.net/#commits", "irc://test.net/#test"]) diff --git a/spec/models/snippet_spec.rb b/spec/models/snippet_spec.rb index 9b37a2d9ad5..12c06feacf3 100644 --- a/spec/models/snippet_spec.rb +++ b/spec/models/snippet_spec.rb @@ -529,11 +529,11 @@ describe Snippet do let(:snippet) { build(:snippet) } it 'excludes secret_token from generated json' do - expect(JSON.parse(to_json).keys).not_to include("secret_token") + expect(Gitlab::Json.parse(to_json).keys).not_to include("secret_token") end it 'does not override existing exclude option value' do - expect(JSON.parse(to_json(except: [:id])).keys).not_to include("secret_token", "id") + expect(Gitlab::Json.parse(to_json(except: [:id])).keys).not_to include("secret_token", "id") end def to_json(params = {}) diff --git a/spec/requests/api/graphql/boards/board_lists_query_spec.rb b/spec/requests/api/graphql/boards/board_lists_query_spec.rb index 3d2f6cc9046..f0927487f85 100644 --- a/spec/requests/api/graphql/boards/board_lists_query_spec.rb +++ b/spec/requests/api/graphql/boards/board_lists_query_spec.rb @@ -132,6 +132,6 @@ describe 'get board lists' do end def grab_list_data(response_body) - JSON.parse(response_body)['data'][board_parent_type]['boards']['edges'][0]['node']['lists']['edges'] + Gitlab::Json.parse(response_body)['data'][board_parent_type]['boards']['edges'][0]['node']['lists']['edges'] end end diff --git a/spec/requests/api/graphql/project/issues_spec.rb b/spec/requests/api/graphql/project/issues_spec.rb index cb751f786a8..256b45498f6 100644 --- a/spec/requests/api/graphql/project/issues_spec.rb +++ b/spec/requests/api/graphql/project/issues_spec.rb @@ -171,7 +171,7 @@ describe 'getting an issue list for a project' do cursored_query = query("sort: DUE_DATE_ASC, after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges'] expect(grab_iids(response_data)).to eq([due_issue1.iid, due_issue4.iid, due_issue2.iid]) end @@ -193,7 +193,7 @@ describe 'getting an issue list for a project' do cursored_query = query("sort: DUE_DATE_DESC, after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges'] expect(grab_iids(response_data)).to eq([due_issue3.iid, due_issue4.iid, due_issue2.iid]) end @@ -239,7 +239,7 @@ describe 'getting an issue list for a project' do cursored_query = query("sort: RELATIVE_POSITION_ASC, after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges'] expect(grab_iids(response_data)).to eq([relative_issue1.iid, relative_issue4.iid, relative_issue2.iid]) end @@ -288,7 +288,7 @@ describe 'getting an issue list for a project' do cursored_query = query("sort: PRIORITY_ASC, after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges'] expect(grab_iids(response_data)).to eq([priority_issue2.iid, priority_issue4.iid]) end @@ -310,7 +310,7 @@ describe 'getting an issue list for a project' do cursored_query = query("sort: PRIORITY_DESC, after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data']['project']['issues']['edges'] + response_data = Gitlab::Json.parse(response.body)['data']['project']['issues']['edges'] expect(grab_iids(response_data)).to eq([priority_issue2.iid, priority_issue4.iid]) end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 853155cea7a..f776faf6458 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -24,7 +24,7 @@ shared_examples 'languages and percentages JSON response' do get api("/projects/#{project.id}/languages", user) expect(response).to have_gitlab_http_status(:ok) - expect(JSON.parse(response.body)).to eq(expected_languages) + expect(Gitlab::Json.parse(response.body)).to eq(expected_languages) end end @@ -672,7 +672,7 @@ describe API::Projects do match[1] end - ids += JSON.parse(response.body).map { |p| p['id'] } + ids += Gitlab::Json.parse(response.body).map { |p| p['id'] } end expect(ids).to contain_exactly(*projects.map(&:id)) diff --git a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb index 3eebbe98c9d..3547e1f0f8c 100644 --- a/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb +++ b/spec/services/metrics/dashboard/grafana_metric_embed_service_spec.rb @@ -217,7 +217,7 @@ describe Metrics::Dashboard::DatasourceNameParser do include GrafanaApiHelpers let(:grafana_url) { valid_grafana_dashboard_link('https://gitlab.grafana.net') } - let(:grafana_dashboard) { JSON.parse(fixture_file('grafana/dashboard_response.json'), symbolize_names: true) } + let(:grafana_dashboard) { Gitlab::Json.parse(fixture_file('grafana/dashboard_response.json'), symbolize_names: true) } subject { described_class.new(grafana_url, grafana_dashboard).parse } diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb index 40f4151c0fb..120d432655b 100644 --- a/spec/support/helpers/stub_gitlab_calls.rb +++ b/spec/support/helpers/stub_gitlab_calls.rb @@ -86,7 +86,7 @@ module StubGitlabCalls def stub_container_registry_tag_manifest_content fixture_path = 'spec/fixtures/container_registry/tag_manifest.json' - JSON.parse(File.read(Rails.root + fixture_path)) + Gitlab::Json.parse(File.read(Rails.root + fixture_path)) end def stub_container_registry_blob_content @@ -113,12 +113,12 @@ module StubGitlabCalls def stub_project_8 data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8.json')) - allow_any_instance_of(Network).to receive(:project).and_return(JSON.parse(data)) + allow_any_instance_of(Network).to receive(:project).and_return(Gitlab::Json.parse(data)) end def stub_project_8_hooks data = File.read(Rails.root.join('spec/support/gitlab_stubs/project_8_hooks.json')) - allow_any_instance_of(Network).to receive(:project_hooks).and_return(JSON.parse(data)) + allow_any_instance_of(Network).to receive(:project_hooks).and_return(Gitlab::Json.parse(data)) end def stub_projects @@ -143,7 +143,7 @@ module StubGitlabCalls def project_hash_array f = File.read(Rails.root.join('spec/support/gitlab_stubs/projects.json')) - JSON.parse f + Gitlab::Json.parse(f) end end diff --git a/spec/support/helpers/workhorse_helpers.rb b/spec/support/helpers/workhorse_helpers.rb index 53b36b3dd45..f16b6c1e910 100644 --- a/spec/support/helpers/workhorse_helpers.rb +++ b/spec/support/helpers/workhorse_helpers.rb @@ -11,7 +11,7 @@ module WorkhorseHelpers header = split_header.join(':') [ type, - JSON.parse(Base64.urlsafe_decode64(header)) + Gitlab::Json.parse(Base64.urlsafe_decode64(header)) ] end end diff --git a/spec/support/import_export/configuration_helper.rb b/spec/support/import_export/configuration_helper.rb index 4330c4314a8..6f67b0f3dd7 100644 --- a/spec/support/import_export/configuration_helper.rb +++ b/spec/support/import_export/configuration_helper.rb @@ -44,8 +44,8 @@ module ConfigurationHelper import_export_config = config_hash(config) excluded_attributes = import_export_config[:excluded_attributes][relation_name.to_sym] included_attributes = import_export_config[:included_attributes][relation_name.to_sym] - attributes = attributes - JSON.parse(excluded_attributes.to_json) if excluded_attributes - attributes = attributes & JSON.parse(included_attributes.to_json) if included_attributes + attributes = attributes - Gitlab::Json.parse(excluded_attributes.to_json) if excluded_attributes + attributes = attributes & Gitlab::Json.parse(included_attributes.to_json) if included_attributes attributes end diff --git a/spec/support/matchers/disallow_request_matchers.rb b/spec/support/matchers/disallow_request_matchers.rb index a161e3660cd..cb6f4bedbd5 100644 --- a/spec/support/matchers/disallow_request_matchers.rb +++ b/spec/support/matchers/disallow_request_matchers.rb @@ -11,7 +11,7 @@ end RSpec::Matchers.define :disallow_request_in_json do match do |response| - json_response = JSON.parse(response.body) + json_response = Gitlab::Json.parse(response.body) response.body.include?('You cannot perform write operations') && json_response.key?('message') end end diff --git a/spec/support/shared_contexts/features/error_tracking_shared_context.rb b/spec/support/shared_contexts/features/error_tracking_shared_context.rb index cbd33dd109b..102cf7c9b11 100644 --- a/spec/support/shared_contexts/features/error_tracking_shared_context.rb +++ b/spec/support/shared_contexts/features/error_tracking_shared_context.rb @@ -6,9 +6,9 @@ shared_context 'sentry error tracking context feature' do let_it_be(:project) { create(:project) } let_it_be(:project_error_tracking_settings) { create(:project_error_tracking_setting, project: project) } let_it_be(:issue_response_body) { fixture_file('sentry/issue_sample_response.json') } - let_it_be(:issue_response) { JSON.parse(issue_response_body) } + let_it_be(:issue_response) { Gitlab::Json.parse(issue_response_body) } let_it_be(:event_response_body) { fixture_file('sentry/issue_latest_event_sample_response.json') } - let_it_be(:event_response) { JSON.parse(event_response_body) } + let_it_be(:event_response) { Gitlab::Json.parse(event_response_body) } let(:sentry_api_urls) { Sentry::ApiUrls.new(project_error_tracking_settings.api_url) } let(:issue_id) { issue_response['id'] } let(:issue_seen) { 1.year.ago.utc } diff --git a/spec/support/shared_contexts/json_response_shared_context.rb b/spec/support/shared_contexts/json_response_shared_context.rb index 6a0734decd5..2f0a564d2bc 100644 --- a/spec/support/shared_contexts/json_response_shared_context.rb +++ b/spec/support/shared_contexts/json_response_shared_context.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true RSpec.shared_context 'JSON response' do - let(:json_response) { JSON.parse(response.body) } + let(:json_response) { Gitlab::Json.parse(response.body) } end diff --git a/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb index e530237b4e3..fb7e24eecf2 100644 --- a/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb +++ b/spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb @@ -82,7 +82,7 @@ RSpec.shared_examples 'sorted paginated query' do cursored_query = pagination_query("sort: #{sort_param}, after: \"#{end_cursor}\"", page_info) post_graphql(cursored_query, current_user: current_user) - response_data = graphql_dig_at(JSON.parse(response.body), :data, *data_path, :edges) + response_data = graphql_dig_at(Gitlab::Json.parse(response.body), :data, *data_path, :edges) expect(pagination_results_data(response_data)).to eq expected_results.drop(first_param) end diff --git a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb index 90ac60a6fe7..feb3ba46353 100644 --- a/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb +++ b/spec/support/shared_examples/requests/api/graphql/group_and_project_boards_query_shared_examples.rb @@ -80,7 +80,7 @@ RSpec.shared_examples 'group and project boards query' do cursored_query = query("after: \"#{end_cursor}\"") post_graphql(cursored_query, current_user: current_user) - response_data = JSON.parse(response.body)['data'][board_parent_type]['boards']['edges'] + response_data = Gitlab::Json.parse(response.body)['data'][board_parent_type]['boards']['edges'] expect(grab_names(response_data)).to eq expected_boards.drop(2).first(2).map(&:name) end diff --git a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb index 90fcac0e55c..5dd1badbefc 100644 --- a/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb +++ b/spec/support/shared_examples/services/metrics/dashboard_shared_examples.rb @@ -23,7 +23,7 @@ RSpec.shared_examples 'valid dashboard service response for schema' do end RSpec.shared_examples 'valid dashboard service response' do - let(:dashboard_schema) { JSON.parse(fixture_file('lib/gitlab/metrics/dashboard/schemas/dashboard.json')) } + let(:dashboard_schema) { Gitlab::Json.parse(fixture_file('lib/gitlab/metrics/dashboard/schemas/dashboard.json')) } it_behaves_like 'valid dashboard service response for schema' end @@ -38,7 +38,7 @@ RSpec.shared_examples 'caches the unprocessed dashboard for subsequent calls' do end RSpec.shared_examples 'valid embedded dashboard service response' do - let(:dashboard_schema) { JSON.parse(fixture_file('lib/gitlab/metrics/dashboard/schemas/embedded_dashboard.json')) } + let(:dashboard_schema) { Gitlab::Json.parse(fixture_file('lib/gitlab/metrics/dashboard/schemas/embedded_dashboard.json')) } it_behaves_like 'valid dashboard service response for schema' end |