diff options
Diffstat (limited to 'spec')
26 files changed, 307 insertions, 381 deletions
diff --git a/spec/controllers/groups_controller_spec.rb b/spec/controllers/groups_controller_spec.rb index b2e6df6060a..21e5122c06b 100644 --- a/spec/controllers/groups_controller_spec.rb +++ b/spec/controllers/groups_controller_spec.rb @@ -32,46 +32,21 @@ describe GroupsController do end end - shared_examples 'details view' do - it { is_expected.to render_template('groups/show') } - - context 'as atom' do - let!(:event) { create(:event, project: project) } - let(:format) { :atom } - - it { is_expected.to render_template('groups/show') } - - it 'assigns events for all the projects in the group' do - subject - expect(assigns(:events)).to contain_exactly(event) - end - end - end - describe 'GET #show' do before do sign_in(user) project end - let(:format) { :html } - - subject { get :show, params: { id: group.to_param }, format: format } + context 'as atom' do + it 'assigns events for all the projects in the group' do + create(:event, project: project) - it_behaves_like 'details view' - end + get :show, params: { id: group.to_param }, format: :atom - describe 'GET #details' do - before do - sign_in(user) - project + expect(assigns(:events)).not_to be_empty + end end - - let(:format) { :html } - - subject { get :details, params: { id: group.to_param }, format: format } - - it_behaves_like 'details view' end describe 'GET edit' do diff --git a/spec/features/projects/clusters/applications_spec.rb b/spec/features/projects/clusters/applications_spec.rb index aa1c3902f0f..4981bf794d9 100644 --- a/spec/features/projects/clusters/applications_spec.rb +++ b/spec/features/projects/clusters/applications_spec.rb @@ -227,7 +227,7 @@ describe 'Clusters Applications', :js do expect(page).to have_css('.js-cluster-application-install-button', exact_text: 'Installed') expect(page).to have_css('.js-cluster-application-install-button[disabled]') expect(page).to have_selector('.js-no-endpoint-message') - expect(page).to have_selector('.js-ingress-ip-loading-icon') + expect(page.find('.js-endpoint').value).to eq('?') # We receive the external IP address and display Clusters::Cluster.last.application_ingress.update!(external_ip: '192.168.1.100') diff --git a/spec/features/projects/show/user_sees_git_instructions_spec.rb b/spec/features/projects/show/user_sees_git_instructions_spec.rb index 0d59ef4a727..ffa80235083 100644 --- a/spec/features/projects/show/user_sees_git_instructions_spec.rb +++ b/spec/features/projects/show/user_sees_git_instructions_spec.rb @@ -13,7 +13,7 @@ describe 'Projects > Show > User sees Git instructions' do it 'shows Git command line instructions' do click_link 'Create empty repository' - page.within '.empty-wrapper' do + page.within '.empty_wrapper' do expect(page).to have_content('Command line instructions') end end diff --git a/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb b/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb index 58bd20d7551..dcca1d388c7 100644 --- a/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb +++ b/spec/features/projects/show/user_sees_setup_shortcut_buttons_spec.rb @@ -20,18 +20,18 @@ describe 'Projects > Show > User sees setup shortcut buttons' do visit project_path(project) end - it 'Project buttons are not visible' do - visit project_path(project) - + it 'no Auto DevOps button if can not manage pipelines' do page.within('.project-buttons') do - expect(page).not_to have_link('New file') - expect(page).not_to have_link('Add README') - expect(page).not_to have_link('Add CHANGELOG') - expect(page).not_to have_link('Add CONTRIBUTING') expect(page).not_to have_link('Enable Auto DevOps') expect(page).not_to have_link('Auto DevOps enabled') - expect(page).not_to have_link('Add Kubernetes cluster') - expect(page).not_to have_link('Kubernetes configured') + end + end + + it '"Auto DevOps enabled" button not linked' do + visit project_path(project) + + page.within('.project-buttons') do + expect(page).to have_text('Auto DevOps enabled') end end end @@ -61,6 +61,46 @@ describe 'Projects > Show > User sees setup shortcut buttons' do expect(page).to have_link('Add license', href: presenter.add_license_path) end end + + describe 'Auto DevOps button' do + context 'when Auto DevOps is enabled' do + it '"Auto DevOps enabled" anchor linked to settings page' do + visit project_path(project) + + page.within('.project-buttons') do + expect(page).to have_link('Auto DevOps enabled', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings')) + end + end + end + + context 'when Auto DevOps is not enabled' do + let(:project) { create(:project, :public, :empty_repo, auto_devops_attributes: { enabled: false }) } + + it '"Enable Auto DevOps" button linked to settings page' do + page.within('.project-buttons') do + expect(page).to have_link('Enable Auto DevOps', href: project_settings_ci_cd_path(project, anchor: 'autodevops-settings')) + end + end + end + end + + describe 'Kubernetes cluster button' do + it '"Add Kubernetes cluster" button linked to clusters page' do + page.within('.project-buttons') do + expect(page).to have_link('Add Kubernetes cluster', href: new_project_cluster_path(project)) + end + end + + it '"Kubernetes cluster" anchor linked to cluster page' do + cluster = create(:cluster, :provided_by_gcp, projects: [project]) + + visit project_path(project) + + page.within('.project-buttons') do + expect(page).to have_link('Kubernetes configured', href: project_cluster_path(project, cluster)) + end + end + end end end diff --git a/spec/fixtures/api/schemas/board.json b/spec/fixtures/api/schemas/board.json index 7c146647948..03aca4a3cc0 100644 --- a/spec/fixtures/api/schemas/board.json +++ b/spec/fixtures/api/schemas/board.json @@ -6,5 +6,6 @@ "properties" : { "id": { "type": "integer" }, "name": { "type": "string" } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/entities/issue.json b/spec/fixtures/api/schemas/entities/issue.json index 162fb9c8108..00abe73ec8a 100644 --- a/spec/fixtures/api/schemas/entities/issue.json +++ b/spec/fixtures/api/schemas/entities/issue.json @@ -38,5 +38,6 @@ "items": { "$ref": "label.json" } }, "assignees": { "type": ["array", "null"] } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/entities/issue_boards.json b/spec/fixtures/api/schemas/entities/issue_boards.json index 742f7be5485..0ac1d9468c8 100644 --- a/spec/fixtures/api/schemas/entities/issue_boards.json +++ b/spec/fixtures/api/schemas/entities/issue_boards.json @@ -10,5 +10,6 @@ "items": { "$ref": "issue_board.json" } }, "size": { "type": "integer" } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/entities/merge_request_widget.json b/spec/fixtures/api/schemas/entities/merge_request_widget.json index 6b1cd60c25d..67c209f3fc3 100644 --- a/spec/fixtures/api/schemas/entities/merge_request_widget.json +++ b/spec/fixtures/api/schemas/entities/merge_request_widget.json @@ -52,7 +52,6 @@ "mergeable_discussions_state": { "type": "boolean" }, "conflicts_can_be_resolved_in_ui": { "type": "boolean" }, "branch_missing": { "type": "boolean" }, - "commits_count": { "type": ["integer", "null"] }, "has_conflicts": { "type": "boolean" }, "can_be_merged": { "type": "boolean" }, "mergeable": { "type": "boolean" }, @@ -126,5 +125,6 @@ "can_receive_suggestion": { "type": "boolean" }, "source_branch_protected": { "type": "boolean" }, "conflicts_docs_path": { "type": ["string", "null"] } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/issue.json b/spec/fixtures/api/schemas/issue.json index 77de9ae4f9f..a83ec55cede 100644 --- a/spec/fixtures/api/schemas/issue.json +++ b/spec/fixtures/api/schemas/issue.json @@ -28,7 +28,7 @@ "items": { "$ref": "entities/label.json" } }, "assignee": { - "id": { "type": "integer" }, + "id": { "type": "integet" }, "name": { "type": "string" }, "username": { "type": "string" }, "avatar_url": { "type": "uri" } @@ -52,5 +52,6 @@ } }, "subscribed": { "type": ["boolean", "null"] } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/issues.json b/spec/fixtures/api/schemas/issues.json index fbcd9eea389..70771b21c96 100644 --- a/spec/fixtures/api/schemas/issues.json +++ b/spec/fixtures/api/schemas/issues.json @@ -10,5 +10,6 @@ "items": { "$ref": "issue.json" } }, "size": { "type": "integer" } - } + }, + "additionalProperties": false } diff --git a/spec/fixtures/api/schemas/public_api/v4/merge_request.json b/spec/fixtures/api/schemas/public_api/v4/merge_request.json deleted file mode 100644 index cd50be00418..00000000000 --- a/spec/fixtures/api/schemas/public_api/v4/merge_request.json +++ /dev/null @@ -1,124 +0,0 @@ -{ - "type": "object", - "properties" : { - "properties" : { - "id": { "type": "integer" }, - "iid": { "type": "integer" }, - "project_id": { "type": "integer" }, - "title": { "type": "string" }, - "description": { "type": ["string", "null"] }, - "state": { "type": "string" }, - "merged_by": { - "type": ["object", "null"], - "properties": { - "name": { "type": "string" }, - "username": { "type": "string" }, - "id": { "type": "integer" }, - "state": { "type": "string" }, - "avatar_url": { "type": "uri" }, - "web_url": { "type": "uri" } - }, - "additionalProperties": false - }, - "merged_at": { "type": ["date", "null"] }, - "closed_by": { - "type": ["object", "null"], - "properties": { - "name": { "type": "string" }, - "username": { "type": "string" }, - "id": { "type": "integer" }, - "state": { "type": "string" }, - "avatar_url": { "type": "uri" }, - "web_url": { "type": "uri" } - }, - "additionalProperties": false - }, - "closed_at": { "type": ["date", "null"] }, - "created_at": { "type": "date" }, - "updated_at": { "type": "date" }, - "target_branch": { "type": "string" }, - "source_branch": { "type": "string" }, - "upvotes": { "type": "integer" }, - "downvotes": { "type": "integer" }, - "author": { - "type": "object", - "properties": { - "name": { "type": "string" }, - "username": { "type": "string" }, - "id": { "type": "integer" }, - "state": { "type": "string" }, - "avatar_url": { "type": "uri" }, - "web_url": { "type": "uri" } - }, - "additionalProperties": false - }, - "assignee": { - "type": ["object", "null"], - "properties": { - "name": { "type": "string" }, - "username": { "type": "string" }, - "id": { "type": "integer" }, - "state": { "type": "string" }, - "avatar_url": { "type": "uri" }, - "web_url": { "type": "uri" } - }, - "additionalProperties": false - }, - "source_project_id": { "type": "integer" }, - "target_project_id": { "type": "integer" }, - "labels": { - "type": "array", - "items": { - "type": "string" - } - }, - "work_in_progress": { "type": "boolean" }, - "milestone": { - "type": ["object", "null"], - "properties": { - "id": { "type": "integer" }, - "iid": { "type": "integer" }, - "project_id": { "type": ["integer", "null"] }, - "group_id": { "type": ["integer", "null"] }, - "title": { "type": "string" }, - "description": { "type": ["string", "null"] }, - "state": { "type": "string" }, - "created_at": { "type": "date" }, - "updated_at": { "type": "date" }, - "due_date": { "type": "date" }, - "start_date": { "type": "date" } - }, - "additionalProperties": false - }, - "merge_when_pipeline_succeeds": { "type": "boolean" }, - "merge_status": { "type": "string" }, - "sha": { "type": "string" }, - "merge_commit_sha": { "type": ["string", "null"] }, - "user_notes_count": { "type": "integer" }, - "changes_count": { "type": "string" }, - "should_remove_source_branch": { "type": ["boolean", "null"] }, - "force_remove_source_branch": { "type": ["boolean", "null"] }, - "discussion_locked": { "type": ["boolean", "null"] }, - "web_url": { "type": "uri" }, - "squash": { "type": "boolean" }, - "time_stats": { - "time_estimate": { "type": "integer" }, - "total_time_spent": { "type": "integer" }, - "human_time_estimate": { "type": ["string", "null"] }, - "human_total_time_spent": { "type": ["string", "null"] } - }, - "allow_collaboration": { "type": ["boolean", "null"] }, - "allow_maintainer_to_push": { "type": ["boolean", "null"] } - }, - "required": [ - "id", "iid", "project_id", "title", "description", - "state", "created_at", "updated_at", "target_branch", - "source_branch", "upvotes", "downvotes", "author", - "assignee", "source_project_id", "target_project_id", - "labels", "work_in_progress", "milestone", "merge_when_pipeline_succeeds", - "merge_status", "sha", "merge_commit_sha", "user_notes_count", - "should_remove_source_branch", "force_remove_source_branch", - "web_url", "squash" - ] - } -} diff --git a/spec/fixtures/api/schemas/public_api/v4/merge_requests.json b/spec/fixtures/api/schemas/public_api/v4/merge_requests.json index b35c83950e8..6df27bf32b9 100644 --- a/spec/fixtures/api/schemas/public_api/v4/merge_requests.json +++ b/spec/fixtures/api/schemas/public_api/v4/merge_requests.json @@ -1,6 +1,126 @@ { "type": "array", "items": { - "$ref": "./merge_request.json" + "type": "object", + "properties" : { + "id": { "type": "integer" }, + "iid": { "type": "integer" }, + "project_id": { "type": "integer" }, + "title": { "type": "string" }, + "description": { "type": ["string", "null"] }, + "state": { "type": "string" }, + "merged_by": { + "type": ["object", "null"], + "properties": { + "name": { "type": "string" }, + "username": { "type": "string" }, + "id": { "type": "integer" }, + "state": { "type": "string" }, + "avatar_url": { "type": "uri" }, + "web_url": { "type": "uri" } + }, + "additionalProperties": false + }, + "merged_at": { "type": ["date", "null"] }, + "closed_by": { + "type": ["object", "null"], + "properties": { + "name": { "type": "string" }, + "username": { "type": "string" }, + "id": { "type": "integer" }, + "state": { "type": "string" }, + "avatar_url": { "type": "uri" }, + "web_url": { "type": "uri" } + }, + "additionalProperties": false + }, + "closed_at": { "type": ["date", "null"] }, + "created_at": { "type": "date" }, + "updated_at": { "type": "date" }, + "target_branch": { "type": "string" }, + "source_branch": { "type": "string" }, + "upvotes": { "type": "integer" }, + "downvotes": { "type": "integer" }, + "author": { + "type": "object", + "properties": { + "name": { "type": "string" }, + "username": { "type": "string" }, + "id": { "type": "integer" }, + "state": { "type": "string" }, + "avatar_url": { "type": "uri" }, + "web_url": { "type": "uri" } + }, + "additionalProperties": false + }, + "assignee": { + "type": ["object", "null"], + "properties": { + "name": { "type": "string" }, + "username": { "type": "string" }, + "id": { "type": "integer" }, + "state": { "type": "string" }, + "avatar_url": { "type": "uri" }, + "web_url": { "type": "uri" } + }, + "additionalProperties": false + }, + "source_project_id": { "type": "integer" }, + "target_project_id": { "type": "integer" }, + "labels": { + "type": "array", + "items": { + "type": "string" + } + }, + "work_in_progress": { "type": "boolean" }, + "milestone": { + "type": ["object", "null"], + "properties": { + "id": { "type": "integer" }, + "iid": { "type": "integer" }, + "project_id": { "type": ["integer", "null"] }, + "group_id": { "type": ["integer", "null"] }, + "title": { "type": "string" }, + "description": { "type": ["string", "null"] }, + "state": { "type": "string" }, + "created_at": { "type": "date" }, + "updated_at": { "type": "date" }, + "due_date": { "type": "date" }, + "start_date": { "type": "date" } + }, + "additionalProperties": false + }, + "merge_when_pipeline_succeeds": { "type": "boolean" }, + "merge_status": { "type": "string" }, + "sha": { "type": "string" }, + "merge_commit_sha": { "type": ["string", "null"] }, + "user_notes_count": { "type": "integer" }, + "changes_count": { "type": "string" }, + "should_remove_source_branch": { "type": ["boolean", "null"] }, + "force_remove_source_branch": { "type": ["boolean", "null"] }, + "discussion_locked": { "type": ["boolean", "null"] }, + "web_url": { "type": "uri" }, + "squash": { "type": "boolean" }, + "time_stats": { + "time_estimate": { "type": "integer" }, + "total_time_spent": { "type": "integer" }, + "human_time_estimate": { "type": ["string", "null"] }, + "human_total_time_spent": { "type": ["string", "null"] } + }, + "allow_collaboration": { "type": ["boolean", "null"] }, + "allow_maintainer_to_push": { "type": ["boolean", "null"] } + }, + "required": [ + "id", "iid", "project_id", "title", "description", + "state", "created_at", "updated_at", "target_branch", + "source_branch", "upvotes", "downvotes", "author", + "assignee", "source_project_id", "target_project_id", + "labels", "work_in_progress", "milestone", "merge_when_pipeline_succeeds", + "merge_status", "sha", "merge_commit_sha", "user_notes_count", + "should_remove_source_branch", "force_remove_source_branch", + "web_url", "squash" + ], + "additionalProperties": false } } diff --git a/spec/javascripts/clusters/components/applications_spec.js b/spec/javascripts/clusters/components/applications_spec.js index 790e4b9602c..e2466bf326c 100644 --- a/spec/javascripts/clusters/components/applications_spec.js +++ b/spec/javascripts/clusters/components/applications_spec.js @@ -141,7 +141,7 @@ describe('Applications', () => { }); describe('without ip address', () => { - it('renders an input text with a loading icon and an alert text', () => { + it('renders an input text with a question mark and an alert text', () => { vm = mountComponent(Applications, { applications: { ...APPLICATIONS_MOCK_STATE, @@ -152,7 +152,8 @@ describe('Applications', () => { }, }); - expect(vm.$el.querySelector('.js-ingress-ip-loading-icon')).not.toBe(null); + expect(vm.$el.querySelector('.js-endpoint').value).toEqual('?'); + expect(vm.$el.querySelector('.js-no-endpoint-message')).not.toBe(null); }); }); @@ -329,7 +330,7 @@ describe('Applications', () => { }); describe('without ip address', () => { - it('renders an input text with a loading icon and an alert text', () => { + it('renders an input text with a question mark and an alert text', () => { vm = mountComponent(Applications, { applications: { ...APPLICATIONS_MOCK_STATE, @@ -341,7 +342,8 @@ describe('Applications', () => { }, }); - expect(vm.$el.querySelector('.js-knative-ip-loading-icon')).not.toBe(null); + expect(vm.$el.querySelector('.js-knative-endpoint').value).toEqual('?'); + expect(vm.$el.querySelector('.js-no-knative-endpoint-message')).not.toBe(null); }); }); diff --git a/spec/javascripts/environments/environments_store_spec.js b/spec/javascripts/environments/environments_store_spec.js index 8abdbcbbe54..c3d16f10d72 100644 --- a/spec/javascripts/environments/environments_store_spec.js +++ b/spec/javascripts/environments/environments_store_spec.js @@ -34,46 +34,54 @@ describe('Store', () => { expect(store.state.stoppedCounter).toEqual(2); }); - it('should add folder keys when environment is a folder', () => { - const environment = { - name: 'bar', - size: 3, - id: 2, - }; + describe('store environments', () => { + it('should store environments', () => { + store.storeEnvironments(serverData); - store.storeEnvironments([environment]); + expect(store.state.environments.length).toEqual(serverData.length); + }); - expect(store.state.environments[0].isFolder).toEqual(true); - expect(store.state.environments[0].folderName).toEqual('bar'); - }); + it('should add folder keys when environment is a folder', () => { + const environment = { + name: 'bar', + size: 3, + id: 2, + }; - it('should extract content of `latest` key when provided', () => { - const environment = { - name: 'bar', - size: 3, - id: 2, - latest: { - last_deployment: {}, - isStoppable: true, - }, - }; - - store.storeEnvironments([environment]); - - expect(store.state.environments[0].last_deployment).toEqual({}); - expect(store.state.environments[0].isStoppable).toEqual(true); - }); + store.storeEnvironments([environment]); - it('should store latest.name when the environment is not a folder', () => { - store.storeEnvironments(serverData); + expect(store.state.environments[0].isFolder).toEqual(true); + expect(store.state.environments[0].folderName).toEqual('bar'); + }); - expect(store.state.environments[0].name).toEqual(serverData[0].latest.name); - }); + it('should extract content of `latest` key when provided', () => { + const environment = { + name: 'bar', + size: 3, + id: 2, + latest: { + last_deployment: {}, + isStoppable: true, + }, + }; - it('should store root level name when environment is a folder', () => { - store.storeEnvironments(serverData); + store.storeEnvironments([environment]); - expect(store.state.environments[1].folderName).toEqual(serverData[1].name); + expect(store.state.environments[0].last_deployment).toEqual({}); + expect(store.state.environments[0].isStoppable).toEqual(true); + }); + + it('should store latest.name when the environment is not a folder', () => { + store.storeEnvironments(serverData); + + expect(store.state.environments[0].name).toEqual(serverData[0].latest.name); + }); + + it('should store root level name when environment is a folder', () => { + store.storeEnvironments(serverData); + + expect(store.state.environments[1].folderName).toEqual(serverData[1].name); + }); }); describe('toggleFolder', () => { diff --git a/spec/javascripts/test_bundle.js b/spec/javascripts/test_bundle.js index 235a17d13b0..5eef5682bbd 100644 --- a/spec/javascripts/test_bundle.js +++ b/spec/javascripts/test_bundle.js @@ -69,7 +69,7 @@ window.gl = window.gl || {}; window.gl.TEST_HOST = TEST_HOST; window.gon = window.gon || {}; window.gon.test_env = true; -window.gon.ee = process.env.EE; +window.gon.ee = false; gon.relative_url_root = ''; let hasUnhandledPromiseRejections = false; @@ -122,26 +122,19 @@ afterEach(() => { const axiosDefaultAdapter = getDefaultAdapter(); // render all of our tests -const testContexts = [require.context('spec', true, /_spec$/)]; - -if (process.env.EE) { - testContexts.push(require.context('ee_spec', true, /_spec$/)); -} - -testContexts.forEach(context => { - context.keys().forEach(path => { - try { - context(path); - } catch (err) { - console.log(err); - console.error('[GL SPEC RUNNER ERROR] Unable to load spec: ', path); - describe('Test bundle', function() { - it(`includes '${path}'`, function() { - expect(err).toBeNull(); - }); +const testsContext = require.context('.', true, /_spec$/); +testsContext.keys().forEach(function(path) { + try { + testsContext(path); + } catch (err) { + console.log(err); + console.error('[GL SPEC RUNNER ERROR] Unable to load spec: ', path); + describe('Test bundle', function() { + it(`includes '${path}'`, function() { + expect(err).toBeNull(); }); - } - }); + }); + } }); describe('test errors', () => { @@ -211,35 +204,24 @@ if (process.env.BABEL_ENV === 'coverage') { ]; describe('Uncovered files', function() { - const sourceFilesContexts = [require.context('~', true, /\.(js|vue)$/)]; - - if (process.env.EE) { - sourceFilesContexts.push(require.context('ee', true, /\.(js|vue)$/)); - } - - const allTestFiles = testContexts.reduce( - (accumulator, context) => accumulator.concat(context.keys()), - [], - ); + const sourceFiles = require.context('~', true, /\.(js|vue)$/); $.holdReady(true); - sourceFilesContexts.forEach(context => { - context.keys().forEach(path => { - // ignore if there is a matching spec file - if (allTestFiles.indexOf(`${path.replace(/\.(js|vue)$/, '')}_spec`) > -1) { - return; - } - - it(`includes '${path}'`, function() { - try { - context(path); - } catch (err) { - if (troubleMakers.indexOf(path) === -1) { - expect(err).toBeNull(); - } + sourceFiles.keys().forEach(function(path) { + // ignore if there is a matching spec file + if (testsContext.keys().indexOf(`${path.replace(/\.(js|vue)$/, '')}_spec`) > -1) { + return; + } + + it(`includes '${path}'`, function() { + try { + sourceFiles(path); + } catch (err) { + if (troubleMakers.indexOf(path) === -1) { + expect(err).toBeNull(); } - }); + } }); }); }); diff --git a/spec/lib/gitlab/bitbucket_import/importer_spec.rb b/spec/lib/gitlab/bitbucket_import/importer_spec.rb index e1a2bae5fe8..c432cc223b9 100644 --- a/spec/lib/gitlab/bitbucket_import/importer_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/importer_spec.rb @@ -95,9 +95,6 @@ describe Gitlab::BitbucketImport::Importer do subject { described_class.new(project) } describe '#import_pull_requests' do - let(:source_branch_sha) { sample.commits.last } - let(:target_branch_sha) { sample.commits.first } - before do allow(subject).to receive(:import_wiki) allow(subject).to receive(:import_issues) @@ -105,9 +102,9 @@ describe Gitlab::BitbucketImport::Importer do pull_request = instance_double( Bitbucket::Representation::PullRequest, iid: 10, - source_branch_sha: source_branch_sha, + source_branch_sha: sample.commits.last, source_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.source_branch, - target_branch_sha: target_branch_sha, + target_branch_sha: sample.commits.first, target_branch_name: Gitlab::Git::BRANCH_REF_PREFIX + sample.target_branch, title: 'This is a title', description: 'This is a test pull request', @@ -165,19 +162,6 @@ describe Gitlab::BitbucketImport::Importer do expect(reply_note).to be_a(DiffNote) expect(reply_note.note).to eq(@reply.note) end - - context "when branches' sha is not found in the repository" do - let(:source_branch_sha) { 'a' * Commit::MIN_SHA_LENGTH } - let(:target_branch_sha) { 'b' * Commit::MIN_SHA_LENGTH } - - it 'uses the pull request sha references' do - expect { subject.execute }.to change { MergeRequest.count }.by(1) - - merge_request_diff = MergeRequest.first.merge_request_diff - expect(merge_request_diff.head_commit_sha).to eq source_branch_sha - expect(merge_request_diff.start_commit_sha).to eq target_branch_sha - end - end end context 'issues statuses' do diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index ae50abd0e7a..60106ee3c0b 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -87,38 +87,6 @@ describe Gitlab::Database do end end - describe '.postgresql_minimum_supported_version?' do - it 'returns false when not using PostgreSQL' do - allow(described_class).to receive(:postgresql?).and_return(false) - - expect(described_class.postgresql_minimum_supported_version?).to eq(false) - end - - context 'when using PostgreSQL' do - before do - allow(described_class).to receive(:postgresql?).and_return(true) - end - - it 'returns false when using PostgreSQL 9.5' do - allow(described_class).to receive(:version).and_return('9.5') - - expect(described_class.postgresql_minimum_supported_version?).to eq(false) - end - - it 'returns true when using PostgreSQL 9.6' do - allow(described_class).to receive(:version).and_return('9.6') - - expect(described_class.postgresql_minimum_supported_version?).to eq(true) - end - - it 'returns true when using PostgreSQL 10 or newer' do - allow(described_class).to receive(:version).and_return('10') - - expect(described_class.postgresql_minimum_supported_version?).to eq(true) - end - end - end - describe '.join_lateral_supported?' do it 'returns false when using MySQL' do allow(described_class).to receive(:postgresql?).and_return(false) @@ -227,12 +195,6 @@ describe Gitlab::Database do end end - describe '.pg_last_xact_replay_timestamp' do - it 'returns pg_last_xact_replay_timestamp' do - expect(described_class.pg_last_xact_replay_timestamp).to eq('pg_last_xact_replay_timestamp') - end - end - describe '.nulls_last_order' do context 'when using PostgreSQL' do before do diff --git a/spec/lib/gitlab/request_context_spec.rb b/spec/lib/gitlab/request_context_spec.rb index 23e45aff1c5..3ed57c2c916 100644 --- a/spec/lib/gitlab/request_context_spec.rb +++ b/spec/lib/gitlab/request_context_spec.rb @@ -25,7 +25,7 @@ describe Gitlab::RequestContext do [200, {}, ["Hello"]] end - described_class.new(endpoint).call(env) + Rails.application.middleware.build(endpoint).call(env) expect(client_ip).to eq(load_balancer_ip) end diff --git a/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb b/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb index 13dc62595b5..d8dd7a2fb83 100644 --- a/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb +++ b/spec/migrations/add_head_pipeline_for_each_merge_request_spec.rb @@ -1,21 +1,23 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170508170547_add_head_pipeline_for_each_merge_request.rb') -describe AddHeadPipelineForEachMergeRequest, :migration do +describe AddHeadPipelineForEachMergeRequest, :delete do + include ProjectForksHelper + let(:migration) { described_class.new } - let!(:project) { table(:projects).create! } - let!(:other_project) { table(:projects).create! } + let!(:project) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:other_project) { fork_project(project) } - let!(:pipeline_1) { table(:ci_pipelines).create!(project_id: project.id, ref: "branch_1") } - let!(:pipeline_2) { table(:ci_pipelines).create!(project_id: other_project.id, ref: "branch_1") } - let!(:pipeline_3) { table(:ci_pipelines).create!(project_id: other_project.id, ref: "branch_1") } - let!(:pipeline_4) { table(:ci_pipelines).create!(project_id: project.id, ref: "branch_2") } + let!(:pipeline_1) { create(:ci_pipeline, project: project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:pipeline_2) { create(:ci_pipeline, project: other_project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:pipeline_3) { create(:ci_pipeline, project: other_project, ref: "branch_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:pipeline_4) { create(:ci_pipeline, project: project, ref: "branch_2") } # rubocop:disable RSpec/FactoriesInMigrationSpecs - let!(:mr_1) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_1", target_branch: "target_1") } - let!(:mr_2) { table(:merge_requests).create!(source_project_id: other_project.id, target_project_id: project.id, source_branch: "branch_1", target_branch: "target_2") } - let!(:mr_3) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_2", target_branch: "master") } - let!(:mr_4) { table(:merge_requests).create!(source_project_id: project.id, target_project_id: project.id, source_branch: "branch_3", target_branch: "master") } + let!(:mr_1) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_1", target_branch: "target_1") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:mr_2) { create(:merge_request, source_project: other_project, target_project: project, source_branch: "branch_1", target_branch: "target_2") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:mr_3) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_2", target_branch: "master") } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:mr_4) { create(:merge_request, source_project: project, target_project: project, source_branch: "branch_3", target_branch: "master") } # rubocop:disable RSpec/FactoriesInMigrationSpecs context "#up" do context "when source_project and source_branch of pipeline are the same of merge request" do diff --git a/spec/migrations/migrate_old_artifacts_spec.rb b/spec/migrations/migrate_old_artifacts_spec.rb index 79e21514506..af77d64fdbf 100644 --- a/spec/migrations/migrate_old_artifacts_spec.rb +++ b/spec/migrations/migrate_old_artifacts_spec.rb @@ -3,9 +3,7 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170523083112_migrate_old_artifacts.rb') -# Adding the ci_job_artifacts table (from the 20170918072948 schema) -# makes the use of model code below easier. -describe MigrateOldArtifacts, :migration, schema: 20170918072948 do +describe MigrateOldArtifacts do let(:migration) { described_class.new } let!(:directory) { Dir.mktmpdir } @@ -18,22 +16,18 @@ describe MigrateOldArtifacts, :migration, schema: 20170918072948 do end context 'with migratable data' do - let(:projects) { table(:projects) } - let(:ci_pipelines) { table(:ci_pipelines) } - let(:ci_builds) { table(:ci_builds) } - - let!(:project1) { projects.create!(ci_id: 2) } - let!(:project2) { projects.create!(ci_id: 3) } - let!(:project3) { projects.create! } - - let!(:pipeline1) { ci_pipelines.create!(project_id: project1.id) } - let!(:pipeline2) { ci_pipelines.create!(project_id: project2.id) } - let!(:pipeline3) { ci_pipelines.create!(project_id: project3.id) } - - let!(:build_with_legacy_artifacts) { ci_builds.create!(commit_id: pipeline1.id, project_id: project1.id, type: 'Ci::Build').becomes(Ci::Build) } - let!(:build_without_artifacts) { ci_builds.create!(commit_id: pipeline1.id, project_id: project1.id, type: 'Ci::Build').becomes(Ci::Build) } - let!(:build2) { ci_builds.create!(commit_id: pipeline2.id, project_id: project2.id, type: 'Ci::Build').becomes(Ci::Build) } - let!(:build3) { ci_builds.create!(commit_id: pipeline3.id, project_id: project3.id, type: 'Ci::Build').becomes(Ci::Build) } + set(:project1) { create(:project, ci_id: 2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + set(:project2) { create(:project, ci_id: 3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + set(:project3) { create(:project) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + + set(:pipeline1) { create(:ci_empty_pipeline, project: project1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + set(:pipeline2) { create(:ci_empty_pipeline, project: project2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + set(:pipeline3) { create(:ci_empty_pipeline, project: project3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + + let!(:build_with_legacy_artifacts) { create(:ci_build, pipeline: pipeline1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:build_without_artifacts) { create(:ci_build, pipeline: pipeline1) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:build2) { create(:ci_build, pipeline: pipeline2) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:build3) { create(:ci_build, pipeline: pipeline3) } # rubocop:disable RSpec/FactoriesInMigrationSpecs before do setup_builds(build2, build3) diff --git a/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb b/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb index 88aef3b70b4..99173708190 100644 --- a/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb +++ b/spec/migrations/migrate_user_activities_to_users_last_activity_on_spec.rb @@ -3,10 +3,10 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170324160416_migrate_user_activities_to_users_last_activity_on.rb') -describe MigrateUserActivitiesToUsersLastActivityOn, :clean_gitlab_redis_shared_state, :migration do +describe MigrateUserActivitiesToUsersLastActivityOn, :clean_gitlab_redis_shared_state, :delete do let(:migration) { described_class.new } - let!(:user_active_1) { table(:users).create!(email: 'test1', username: 'test1') } - let!(:user_active_2) { table(:users).create!(email: 'test2', username: 'test2') } + let!(:user_active_1) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs + let!(:user_active_2) { create(:user) } # rubocop:disable RSpec/FactoriesInMigrationSpecs def record_activity(user, time) Gitlab::Redis::SharedState.with do |redis| diff --git a/spec/migrations/migrate_user_project_view_spec.rb b/spec/migrations/migrate_user_project_view_spec.rb index a0179ab3ceb..80468b9d01e 100644 --- a/spec/migrations/migrate_user_project_view_spec.rb +++ b/spec/migrations/migrate_user_project_view_spec.rb @@ -3,15 +3,15 @@ require 'spec_helper' require Rails.root.join('db', 'post_migrate', '20170406142253_migrate_user_project_view.rb') -describe MigrateUserProjectView, :migration do +describe MigrateUserProjectView, :delete do let(:migration) { described_class.new } - let!(:user) { table(:users).create!(project_view: User.project_views['readme']) } + let!(:user) { create(:user, project_view: 'readme') } # rubocop:disable RSpec/FactoriesInMigrationSpecs describe '#up' do it 'updates project view setting with new value' do migration.up - expect(user.reload.project_view).to eq(User.project_views['files']) + expect(user.reload.project_view).to eq('files') end end end diff --git a/spec/routing/group_routing_spec.rb b/spec/routing/group_routing_spec.rb index 53271550e8b..71788028cbf 100644 --- a/spec/routing/group_routing_spec.rb +++ b/spec/routing/group_routing_spec.rb @@ -17,10 +17,6 @@ describe "Groups", "routing" do expect(get("/#{group_path}")).to route_to('groups#show', id: group_path) end - it "to #details" do - expect(get("/groups/#{group_path}/-/details")).to route_to('groups#details', id: group_path) - end - it "to #activity" do expect(get("/groups/#{group_path}/-/activity")).to route_to('groups#activity', id: group_path) end diff --git a/spec/support/api/schema_matcher.rb b/spec/support/api/schema_matcher.rb index 4cf34d43117..f7d74df0656 100644 --- a/spec/support/api/schema_matcher.rb +++ b/spec/support/api/schema_matcher.rb @@ -1,16 +1,10 @@ module SchemaPath - def self.expand(schema, dir = nil) - if Gitlab.ee? && dir.nil? - ee_path = expand(schema, 'ee') - - return ee_path if File.exist?(ee_path) - end - - Rails.root.join(dir.to_s, 'spec', "fixtures/api/schemas/#{schema}.json").to_s + def self.expand(schema, dir = '') + Rails.root.join(dir, 'spec', "fixtures/api/schemas/#{schema}.json").to_s end end -RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options| +RSpec::Matchers.define :match_response_schema do |schema, dir: '', **options| match do |response| @errors = JSON::Validator.fully_validate( SchemaPath.expand(schema, dir), response.body, options) @@ -24,16 +18,8 @@ RSpec::Matchers.define :match_response_schema do |schema, dir: nil, **options| end end -RSpec::Matchers.define :match_schema do |schema, dir: nil, **options| +RSpec::Matchers.define :match_schema do |schema, dir: '', **options| match do |data| - @errors = JSON::Validator.fully_validate( - SchemaPath.expand(schema, dir), data, options) - - @errors.empty? - end - - failure_message do |response| - "didn't match the schema defined by #{SchemaPath.expand(schema, dir)}" \ - " The validation errors were:\n#{@errors.join("\n")}" + JSON::Validator.validate!(SchemaPath.expand(schema, dir), data, options) end end diff --git a/spec/validators/sha_validator_spec.rb b/spec/validators/sha_validator_spec.rb index 0a76570f65e..dc1539cf318 100644 --- a/spec/validators/sha_validator_spec.rb +++ b/spec/validators/sha_validator_spec.rb @@ -4,7 +4,7 @@ require 'spec_helper' describe ShaValidator do let(:validator) { described_class.new(attributes: [:base_commit_sha]) } - let!(:merge_diff) { build(:merge_request_diff) } + let(:merge_diff) { build(:merge_request_diff) } subject { validator.validate_each(merge_diff, :base_commit_sha, value) } @@ -12,8 +12,6 @@ describe ShaValidator do let(:value) { nil } it 'does not add any error if value is empty' do - expect(Commit).not_to receive(:valid_hash?) - subject expect(merge_diff.errors).to be_empty @@ -23,9 +21,7 @@ describe ShaValidator do context 'with valid sha' do let(:value) { Digest::SHA1.hexdigest(SecureRandom.hex) } - it 'does not add any error' do - expect(Commit).to receive(:valid_hash?).and_call_original - + it 'does not add any error if value is empty' do subject expect(merge_diff.errors).to be_empty @@ -36,7 +32,6 @@ describe ShaValidator do let(:value) { 'foo' } it 'adds error to the record' do - expect(Commit).to receive(:valid_hash?).and_call_original expect(merge_diff.errors).to be_empty subject diff --git a/spec/views/projects/settings/operations/show.html.haml_spec.rb b/spec/views/projects/settings/operations/show.html.haml_spec.rb index 6762fe3759b..1bca8bba940 100644 --- a/spec/views/projects/settings/operations/show.html.haml_spec.rb +++ b/spec/views/projects/settings/operations/show.html.haml_spec.rb @@ -18,7 +18,6 @@ describe 'projects/settings/operations/show' do allow(view).to receive(:error_tracking_setting) .and_return(error_tracking_setting) allow(view).to receive(:current_user).and_return(user) - allow(view).to receive(:incident_management_available?) { false } end let!(:error_tracking_setting) do |