diff options
Diffstat (limited to 'spec')
27 files changed, 793 insertions, 486 deletions
diff --git a/spec/controllers/projects/merge_requests_controller_spec.rb b/spec/controllers/projects/merge_requests_controller_spec.rb index 4519cd014a1..ef5f286502b 100644 --- a/spec/controllers/projects/merge_requests_controller_spec.rb +++ b/spec/controllers/projects/merge_requests_controller_spec.rb @@ -1073,7 +1073,7 @@ describe Projects::MergeRequestsController do end it 'renders MergeRequest as JSON' do - expect(json_response.keys).to include('id', 'iid', 'description') + expect(json_response.keys).to include('id', 'iid') end end @@ -1107,7 +1107,7 @@ describe Projects::MergeRequestsController do it 'renders MergeRequest as JSON' do subject - expect(json_response.keys).to include('id', 'iid', 'description') + expect(json_response.keys).to include('id', 'iid') end end diff --git a/spec/features/projects/pipelines/pipelines_spec.rb b/spec/features/projects/pipelines/pipelines_spec.rb index f6eeb8d7065..f5558a1f2ec 100644 --- a/spec/features/projects/pipelines/pipelines_spec.rb +++ b/spec/features/projects/pipelines/pipelines_spec.rb @@ -706,7 +706,7 @@ describe 'Pipelines', :js do click_on 'Run Pipeline' end - it { expect(page).to have_content('Missing .gitlab-ci.yml file') } + it { expect(page).to have_content('Missing CI config file') } it 'creates a pipeline after first request failed and a valid gitlab-ci.yml file is available when trying again' do click_button project.default_branch diff --git a/spec/features/projects/wiki/markdown_preview_spec.rb b/spec/features/projects/wiki/markdown_preview_spec.rb index 5c6b04a7141..331ba58d067 100644 --- a/spec/features/projects/wiki/markdown_preview_spec.rb +++ b/spec/features/projects/wiki/markdown_preview_spec.rb @@ -29,11 +29,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/c/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/c/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -43,11 +43,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -57,11 +57,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end end @@ -77,11 +77,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a/b/c/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/c/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a/b/c/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -95,11 +95,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end @@ -113,11 +113,11 @@ describe 'Projects > Wiki > User previews markdown changes', :js do expect(page).to have_content("regular link") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/regular\">regular link</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/relative\">relative link 1</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") - expect(page.html).to include("<a href=\"/#{project.full_path}/wikis/title%20with%20spaces\">spaced link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/regular\">regular link</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/relative\">relative link 1</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/relative\">relative link 2</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/a-page/b-page/c-page/e/f/relative\">relative link 3</a>") + expect(page.html).to include("<a href=\"/#{project.full_path}/-/wikis/title%20with%20spaces\">spaced link</a>") end end diff --git a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb index 56d0518015d..499c459621a 100644 --- a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb @@ -55,7 +55,7 @@ describe "User creates wiki page" do end expect(current_path).to include("one/two/three-test") - expect(page).to have_xpath("//a[@href='/#{project.full_path}/wikis/one/two/three-test']") + expect(page).to have_xpath("//a[@href='/#{project.full_path}/-/wikis/one/two/three-test']") end it "has `Create home` as a commit message", :js do diff --git a/spec/frontend/boards/services/board_service_spec.js b/spec/frontend/boards/boards_store_spec.js index 86f49f63f4e..f8e5873c87b 100644 --- a/spec/frontend/boards/services/board_service_spec.js +++ b/spec/frontend/boards/boards_store_spec.js @@ -1,10 +1,9 @@ -import BoardService from '~/boards/services/board_service'; import { TEST_HOST } from 'helpers/test_constants'; import AxiosMockAdapter from 'axios-mock-adapter'; import axios from '~/lib/utils/axios_utils'; import boardsStore from '~/boards/stores/boards_store'; -describe('BoardService', () => { +describe('boardsStore', () => { const dummyResponse = "without type checking this doesn't matter"; const boardId = 'dummy-board-id'; const endpoints = { @@ -14,7 +13,6 @@ describe('BoardService', () => { recentBoardsEndpoint: `${TEST_HOST}/recent/boards`, }; - let service; let axiosMock; beforeEach(() => { @@ -23,7 +21,6 @@ describe('BoardService', () => { ...endpoints, boardId, }); - service = new BoardService(); }); describe('all', () => { @@ -31,13 +28,13 @@ describe('BoardService', () => { axiosMock.onGet(endpoints.listsEndpoint).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.all()).resolves.toEqual(expectedResponse); + return expect(boardsStore.all()).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(endpoints.listsEndpoint).replyOnce(500); - return expect(service.all()).rejects.toThrow(); + return expect(boardsStore.all()).rejects.toThrow(); }); }); @@ -48,13 +45,13 @@ describe('BoardService', () => { axiosMock.onPost(listsEndpointGenerate).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.generateDefaultLists()).resolves.toEqual(expectedResponse); + return expect(boardsStore.generateDefaultLists()).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onPost(listsEndpointGenerate).replyOnce(500); - return expect(service.generateDefaultLists()).rejects.toThrow(); + return expect(boardsStore.generateDefaultLists()).rejects.toThrow(); }); }); @@ -76,7 +73,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.createList(entityId, entityType)) + return expect(boardsStore.createList(entityId, entityType)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -86,7 +83,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.createList(entityId, entityType)) + return expect(boardsStore.createList(entityId, entityType)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -113,7 +110,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.updateList(id, position, collapsed)) + return expect(boardsStore.updateList(id, position, collapsed)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -123,7 +120,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.updateList(id, position, collapsed)) + return expect(boardsStore.updateList(id, position, collapsed)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -147,7 +144,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.destroyList(id)) + return expect(boardsStore.destroyList(id)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalled(); @@ -157,7 +154,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.destroyList(id)) + return expect(boardsStore.destroyList(id)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalled(); @@ -173,7 +170,7 @@ describe('BoardService', () => { axiosMock.onGet(url).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.getIssuesForList(id)).resolves.toEqual(expectedResponse); + return expect(boardsStore.getIssuesForList(id)).resolves.toEqual(expectedResponse); }); it('makes a request to fetch list issues with filter', () => { @@ -181,13 +178,13 @@ describe('BoardService', () => { axiosMock.onGet(`${url}&algal=scrubber`).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.getIssuesForList(id, filter)).resolves.toEqual(expectedResponse); + return expect(boardsStore.getIssuesForList(id, filter)).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(url).replyOnce(500); - return expect(service.getIssuesForList(id)).rejects.toThrow(); + return expect(boardsStore.getIssuesForList(id)).rejects.toThrow(); }); }); @@ -228,7 +225,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.moveIssue(id, fromListId, toListId, moveBeforeId, moveAfterId)) + return expect(boardsStore.moveIssue(id, fromListId, toListId, moveBeforeId, moveAfterId)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -238,7 +235,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.moveIssue(id, fromListId, toListId, moveBeforeId, moveAfterId)) + return expect(boardsStore.moveIssue(id, fromListId, toListId, moveBeforeId, moveAfterId)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -267,7 +264,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.newIssue(id, issue)) + return expect(boardsStore.newIssue(id, issue)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -277,7 +274,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.newIssue(id, issue)) + return expect(boardsStore.newIssue(id, issue)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -304,13 +301,13 @@ describe('BoardService', () => { axiosMock.onGet(url).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.getBacklog(requestParams)).resolves.toEqual(expectedResponse); + return expect(boardsStore.getBacklog(requestParams)).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(url).replyOnce(500); - return expect(service.getBacklog(requestParams)).rejects.toThrow(); + return expect(boardsStore.getBacklog(requestParams)).rejects.toThrow(); }); }); @@ -337,7 +334,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.bulkUpdate(issueIds, extraData)) + return expect(boardsStore.bulkUpdate(issueIds, extraData)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -347,7 +344,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.bulkUpdate(issueIds, extraData)) + return expect(boardsStore.bulkUpdate(issueIds, extraData)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -362,13 +359,13 @@ describe('BoardService', () => { axiosMock.onGet(dummyEndpoint).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(BoardService.getIssueInfo(dummyEndpoint)).resolves.toEqual(expectedResponse); + return expect(boardsStore.getIssueInfo(dummyEndpoint)).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(dummyEndpoint).replyOnce(500); - return expect(BoardService.getIssueInfo(dummyEndpoint)).rejects.toThrow(); + return expect(boardsStore.getIssueInfo(dummyEndpoint)).rejects.toThrow(); }); }); @@ -379,7 +376,7 @@ describe('BoardService', () => { axiosMock.onPost(dummyEndpoint).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(BoardService.toggleIssueSubscription(dummyEndpoint)).resolves.toEqual( + return expect(boardsStore.toggleIssueSubscription(dummyEndpoint)).resolves.toEqual( expectedResponse, ); }); @@ -387,7 +384,7 @@ describe('BoardService', () => { it('fails for error response', () => { axiosMock.onPost(dummyEndpoint).replyOnce(500); - return expect(BoardService.toggleIssueSubscription(dummyEndpoint)).rejects.toThrow(); + return expect(boardsStore.toggleIssueSubscription(dummyEndpoint)).rejects.toThrow(); }); }); @@ -398,13 +395,13 @@ describe('BoardService', () => { axiosMock.onGet(url).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.allBoards()).resolves.toEqual(expectedResponse); + return expect(boardsStore.allBoards()).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(url).replyOnce(500); - return expect(service.allBoards()).rejects.toThrow(); + return expect(boardsStore.allBoards()).rejects.toThrow(); }); }); @@ -415,13 +412,13 @@ describe('BoardService', () => { axiosMock.onGet(url).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.recentBoards()).resolves.toEqual(expectedResponse); + return expect(boardsStore.recentBoards()).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onGet(url).replyOnce(500); - return expect(service.recentBoards()).rejects.toThrow(); + return expect(boardsStore.recentBoards()).rejects.toThrow(); }); }); @@ -462,7 +459,7 @@ describe('BoardService', () => { const expectedResponse = expect.objectContaining({ data: dummyResponse }); return expect( - service.createBoard({ + boardsStore.createBoard({ ...board, id, }), @@ -477,7 +474,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([500]); return expect( - service.createBoard({ + boardsStore.createBoard({ ...board, id, }), @@ -513,7 +510,7 @@ describe('BoardService', () => { requestSpy.mockReturnValue([200, dummyResponse]); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.createBoard(board)) + return expect(boardsStore.createBoard(board)) .resolves.toEqual(expectedResponse) .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -523,7 +520,7 @@ describe('BoardService', () => { it('fails for error response', () => { requestSpy.mockReturnValue([500]); - return expect(service.createBoard(board)) + return expect(boardsStore.createBoard(board)) .rejects.toThrow() .then(() => { expect(requestSpy).toHaveBeenCalledWith(expectedRequest); @@ -540,13 +537,13 @@ describe('BoardService', () => { axiosMock.onDelete(url).replyOnce(200, dummyResponse); const expectedResponse = expect.objectContaining({ data: dummyResponse }); - return expect(service.deleteBoard({ id })).resolves.toEqual(expectedResponse); + return expect(boardsStore.deleteBoard({ id })).resolves.toEqual(expectedResponse); }); it('fails for error response', () => { axiosMock.onDelete(url).replyOnce(500); - return expect(service.deleteBoard({ id })).rejects.toThrow(); + return expect(boardsStore.deleteBoard({ id })).rejects.toThrow(); }); }); }); diff --git a/spec/frontend/gfm_auto_complete_spec.js b/spec/frontend/gfm_auto_complete_spec.js index 28ab2f2d6c4..99869c46f3f 100644 --- a/spec/frontend/gfm_auto_complete_spec.js +++ b/spec/frontend/gfm_auto_complete_spec.js @@ -1,8 +1,7 @@ /* eslint no-param-reassign: "off" */ import $ from 'jquery'; -import { membersBeforeSave } from '~/gfm_auto_complete'; -import GfmAutoComplete from 'ee_else_ce/gfm_auto_complete'; +import GfmAutoComplete, { membersBeforeSave } from 'ee_else_ce/gfm_auto_complete'; import 'jquery.caret'; import 'at.js'; diff --git a/spec/frontend/notes/components/note_app_spec.js b/spec/frontend/notes/components/note_app_spec.js index 3716b349210..3c960adb698 100644 --- a/spec/frontend/notes/components/note_app_spec.js +++ b/spec/frontend/notes/components/note_app_spec.js @@ -1,13 +1,13 @@ import $ from 'helpers/jquery'; import AxiosMockAdapter from 'axios-mock-adapter'; -import axios from '~/lib/utils/axios_utils'; import Vue from 'vue'; import { mount, createLocalVue } from '@vue/test-utils'; +import { setTestTimeout } from 'helpers/timeout'; +import axios from '~/lib/utils/axios_utils'; import NotesApp from '~/notes/components/notes_app.vue'; import service from '~/notes/services/notes_service'; import createStore from '~/notes/stores'; import '~/behaviors/markdown/render_gfm'; -import { setTestTimeout } from 'helpers/timeout'; // TODO: use generated fixture (https://gitlab.com/gitlab-org/gitlab-foss/issues/62491) import * as mockData from '../../notes/mock_data'; import * as urlUtility from '~/lib/utils/url_utility'; @@ -77,6 +77,8 @@ describe('note_app', () => { describe('set data', () => { beforeEach(() => { + setFixtures('<div class="js-discussions-count"></div>'); + axiosMock.onAny().reply(200, []); wrapper = mountComponent(); return waitForDiscussionsRequest(); @@ -97,6 +99,10 @@ describe('note_app', () => { it('should fetch discussions', () => { expect(store.state.discussions).toEqual([]); }); + + it('updates discussions badge', () => { + expect(document.querySelector('.js-discussions-count').textContent).toEqual('0'); + }); }); describe('render', () => { @@ -161,6 +167,7 @@ describe('note_app', () => { describe('while fetching data', () => { beforeEach(() => { + setFixtures('<div class="js-discussions-count"></div>'); axiosMock.onAny().reply(200, []); wrapper = mountComponent(); }); @@ -177,6 +184,10 @@ describe('note_app', () => { 'Write a comment or drag your files here…', ); }); + + it('should not update discussions badge (it should be blank)', () => { + expect(document.querySelector('.js-discussions-count').textContent).toEqual(''); + }); }); describe('update note', () => { diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb index bef6fbe3d5f..18c94602596 100644 --- a/spec/helpers/search_helper_spec.rb +++ b/spec/helpers/search_helper_spec.rb @@ -122,13 +122,13 @@ describe SearchHelper do it 'uses the correct singular label' do collection = Kaminari.paginate_array([:foo]).page(1).per(10) - expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 #{label} for \"foo\"") + expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 #{label} for<span> <code>foo</code> </span>") end it 'uses the correct plural label' do collection = Kaminari.paginate_array([:foo] * 23).page(1).per(10) - expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 - 10 of 23 #{label.pluralize} for \"foo\"") + expect(search_entries_info(collection, scope, 'foo')).to eq("Showing 1 - 10 of 23 #{label.pluralize} for<span> <code>foo</code> </span>") end end diff --git a/spec/helpers/wiki_helper_spec.rb b/spec/helpers/wiki_helper_spec.rb index bcc2bd71da1..1aab01281c6 100644 --- a/spec/helpers/wiki_helper_spec.rb +++ b/spec/helpers/wiki_helper_spec.rb @@ -27,7 +27,7 @@ describe WikiHelper do let(:classes) { "btn btn-default has-tooltip reverse-sort-btn qa-reverse-sort rspec-reverse-sort" } def expected_link(sort, direction, icon_class) - path = "/#{project.full_path}/wikis/pages?direction=#{direction}&sort=#{sort}" + path = "/#{project.full_path}/-/wikis/pages?direction=#{direction}&sort=#{sort}" helper.link_to(path, type: 'button', class: classes, title: 'Sort direction') do helper.sprite_icon("sort-#{icon_class}", size: 16) diff --git a/spec/javascripts/boards/boards_store_spec.js b/spec/javascripts/boards/boards_store_spec.js index 292fa745fe8..278930789e1 100644 --- a/spec/javascripts/boards/boards_store_spec.js +++ b/spec/javascripts/boards/boards_store_spec.js @@ -8,7 +8,6 @@ import '~/boards/models/label'; import '~/boards/models/assignee'; import '~/boards/models/issue'; import '~/boards/models/list'; -import '~/boards/services/board_service'; import boardsStore from '~/boards/stores/boards_store'; import eventHub from '~/boards/eventhub'; import { listObj, listObjDuplicate, boardsMockInterceptor } from './mock_data'; diff --git a/spec/javascripts/boards/issue_spec.js b/spec/javascripts/boards/issue_spec.js index 890a47c189a..181e7af7451 100644 --- a/spec/javascripts/boards/issue_spec.js +++ b/spec/javascripts/boards/issue_spec.js @@ -5,7 +5,6 @@ import '~/boards/models/label'; import '~/boards/models/assignee'; import '~/boards/models/issue'; import '~/boards/models/list'; -import '~/boards/services/board_service'; import boardsStore from '~/boards/stores/boards_store'; import { setMockEndpoints } from './mock_data'; diff --git a/spec/javascripts/boards/list_spec.js b/spec/javascripts/boards/list_spec.js index 1fcd7958bc5..374e7d76b1c 100644 --- a/spec/javascripts/boards/list_spec.js +++ b/spec/javascripts/boards/list_spec.js @@ -10,7 +10,6 @@ import '~/boards/models/label'; import '~/boards/models/assignee'; import '~/boards/models/issue'; import '~/boards/models/list'; -import '~/boards/services/board_service'; import boardsStore from '~/boards/stores/boards_store'; import { listObj, listObjDuplicate, boardsMockInterceptor } from './mock_data'; diff --git a/spec/javascripts/vue_mr_widget/mock_data.js b/spec/javascripts/vue_mr_widget/mock_data.js index ff34dafa660..ba999adb2a9 100644 --- a/spec/javascripts/vue_mr_widget/mock_data.js +++ b/spec/javascripts/vue_mr_widget/mock_data.js @@ -222,6 +222,7 @@ export default { plain_diff_path: '/root/acets-app/merge_requests/22.diff', merge_request_basic_path: '/root/acets-app/merge_requests/22.json?serializer=basic', merge_request_widget_path: '/root/acets-app/merge_requests/22/widget.json', + merge_request_cached_widget_path: '/cached.json', merge_check_path: '/root/acets-app/merge_requests/22/merge_check', ci_environments_status_url: '/root/acets-app/merge_requests/22/ci_environments_status', project_archived: false, diff --git a/spec/javascripts/vue_mr_widget/mr_widget_options_spec.js b/spec/javascripts/vue_mr_widget/mr_widget_options_spec.js index 604b21e77fe..36e4ce7177f 100644 --- a/spec/javascripts/vue_mr_widget/mr_widget_options_spec.js +++ b/spec/javascripts/vue_mr_widget/mr_widget_options_spec.js @@ -1,4 +1,6 @@ import Vue from 'vue'; +import MockAdapter from 'axios-mock-adapter'; +import axios from '~/lib/utils/axios_utils'; import mrWidgetOptions from '~/vue_merge_request_widget/mr_widget_options.vue'; import eventHub from '~/vue_merge_request_widget/event_hub'; import notify from '~/lib/utils/notify'; @@ -17,6 +19,7 @@ const returnPromise = data => describe('mrWidgetOptions', () => { let vm; + let mock; let MrWidgetOptions; const COLLABORATION_MESSAGE = 'Allows commits from members who can merge to the target branch'; @@ -25,6 +28,13 @@ describe('mrWidgetOptions', () => { // Prevent component mounting delete mrWidgetOptions.el; + gl.mrWidgetData = { ...mockData }; + gon.features = { asyncMrWidget: true }; + + mock = new MockAdapter(axios); + mock.onGet(mockData.merge_request_widget_path).reply(() => [200, { ...mockData }]); + mock.onGet(mockData.merge_request_cached_widget_path).reply(() => [200, { ...mockData }]); + MrWidgetOptions = Vue.extend(mrWidgetOptions); vm = mountComponent(MrWidgetOptions, { mrData: { ...mockData }, @@ -33,6 +43,9 @@ describe('mrWidgetOptions', () => { afterEach(() => { vm.$destroy(); + mock.restore(); + gl.mrWidgetData = {}; + gon.features = {}; }); describe('data', () => { @@ -308,59 +321,61 @@ describe('mrWidgetOptions', () => { }); describe('bindEventHubListeners', () => { - it('should bind eventHub listeners', () => { + it('should bind eventHub listeners', done => { spyOn(vm, 'checkStatus').and.returnValue(() => {}); spyOn(vm.service, 'checkStatus').and.returnValue(returnPromise(mockData)); spyOn(vm, 'fetchActionsContent'); spyOn(vm.mr, 'setData'); spyOn(vm, 'resumePolling'); spyOn(vm, 'stopPolling'); - spyOn(eventHub, '$on'); + spyOn(eventHub, '$on').and.callThrough(); - vm.bindEventHubListeners(); + setTimeout(() => { + eventHub.$emit('SetBranchRemoveFlag', ['flag']); - eventHub.$emit('SetBranchRemoveFlag', ['flag']); + expect(vm.mr.isRemovingSourceBranch).toEqual('flag'); - expect(vm.mr.isRemovingSourceBranch).toEqual('flag'); + eventHub.$emit('FailedToMerge'); - eventHub.$emit('FailedToMerge'); + expect(vm.mr.state).toEqual('failedToMerge'); - expect(vm.mr.state).toEqual('failedToMerge'); + eventHub.$emit('UpdateWidgetData', mockData); - eventHub.$emit('UpdateWidgetData', mockData); + expect(vm.mr.setData).toHaveBeenCalledWith(mockData); - expect(vm.mr.setData).toHaveBeenCalledWith(mockData); + eventHub.$emit('EnablePolling'); - eventHub.$emit('EnablePolling'); + expect(vm.resumePolling).toHaveBeenCalled(); - expect(vm.resumePolling).toHaveBeenCalled(); + eventHub.$emit('DisablePolling'); - eventHub.$emit('DisablePolling'); + expect(vm.stopPolling).toHaveBeenCalled(); - expect(vm.stopPolling).toHaveBeenCalled(); + const listenersWithServiceRequest = { + MRWidgetUpdateRequested: true, + FetchActionsContent: true, + }; - const listenersWithServiceRequest = { - MRWidgetUpdateRequested: true, - FetchActionsContent: true, - }; + const allArgs = eventHub.$on.calls.allArgs(); + allArgs.forEach(params => { + const eventName = params[0]; + const callback = params[1]; - const allArgs = eventHub.$on.calls.allArgs(); - allArgs.forEach(params => { - const eventName = params[0]; - const callback = params[1]; + if (listenersWithServiceRequest[eventName]) { + listenersWithServiceRequest[eventName] = callback; + } + }); - if (listenersWithServiceRequest[eventName]) { - listenersWithServiceRequest[eventName] = callback; - } - }); + listenersWithServiceRequest.MRWidgetUpdateRequested(); - listenersWithServiceRequest.MRWidgetUpdateRequested(); + expect(vm.checkStatus).toHaveBeenCalled(); - expect(vm.checkStatus).toHaveBeenCalled(); + listenersWithServiceRequest.FetchActionsContent(); - listenersWithServiceRequest.FetchActionsContent(); + expect(vm.fetchActionsContent).toHaveBeenCalled(); - expect(vm.fetchActionsContent).toHaveBeenCalled(); + done(); + }); }); }); @@ -451,22 +466,30 @@ describe('mrWidgetOptions', () => { }); describe('resumePolling', () => { - it('should call stopTimer on pollingInterval', () => { - spyOn(vm.pollingInterval, 'resume'); + it('should call stopTimer on pollingInterval', done => { + setTimeout(() => { + spyOn(vm.pollingInterval, 'resume'); + + vm.resumePolling(); - vm.resumePolling(); + expect(vm.pollingInterval.resume).toHaveBeenCalled(); - expect(vm.pollingInterval.resume).toHaveBeenCalled(); + done(); + }); }); }); describe('stopPolling', () => { - it('should call stopTimer on pollingInterval', () => { - spyOn(vm.pollingInterval, 'stopTimer'); + it('should call stopTimer on pollingInterval', done => { + setTimeout(() => { + spyOn(vm.pollingInterval, 'stopTimer'); + + vm.stopPolling(); - vm.stopPolling(); + expect(vm.pollingInterval.stopTimer).toHaveBeenCalled(); - expect(vm.pollingInterval.stopTimer).toHaveBeenCalled(); + done(); + }); }); }); }); diff --git a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb index 26f2b0b0acf..e1814ea403e 100644 --- a/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb +++ b/spec/lib/banzai/pipeline/wiki_pipeline_spec.rb @@ -72,14 +72,14 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "[Page](./page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page\"") end it "rewrites file links to be at the scope of the current directory" do markdown = "[Link to Page](./page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"") end end @@ -88,14 +88,14 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "[Link to Page](../page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/page\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page\"") end it "rewrites file links to be at the scope of the parent directory" do markdown = "[Link to Page](../page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/page.md\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/page.md\"") end end @@ -104,14 +104,14 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "[Link to Page](./subdirectory/page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/subdirectory/page\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page\"") end it "rewrites file links to be at the scope of the sub-directory" do markdown = "[Link to Page](./subdirectory/page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/subdirectory/page.md\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/subdirectory/page.md\"") end end @@ -120,35 +120,35 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "[Link to Page](page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"") end it 'rewrites non-file links (with spaces) to be at the scope of the wiki root' do markdown = "[Link to Page](page slug)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page%20slug\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page%20slug\"") end it "rewrites file links to be at the scope of the current directory" do markdown = "[Link to Page](page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/nested/twice/page.md\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/page.md\"") end it 'rewrites links with anchor' do markdown = '[Link to Header](start-page#title)' output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start-page#title\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start-page#title\"") end it 'rewrites links (with spaces) with anchor' do markdown = '[Link to Header](start page#title)' output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/start%20page#title\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/start%20page#title\"") end end @@ -157,14 +157,14 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "[Link to Page](/page)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page\"") end it 'rewrites file links to be at the scope of the wiki root' do markdown = "[Link to Page](/page.md)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/wikis/page.md\"") + expect(output).to include("href=\"#{relative_url_root}/wiki_link_ns/wiki_link_project/-/wikis/page.md\"") end end end @@ -270,28 +270,28 @@ describe Banzai::Pipeline::WikiPipeline do markdown = "![video_file](video_file_name.mp4)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/video_file_name.mp4"') + expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video_file_name.mp4"') end it 'rewrites and replaces video links names with white spaces to %20' do markdown = "![video file](video file name.mp4)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/video%20file%20name.mp4"') + expect(output).to include('<video src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/video%20file%20name.mp4"') end it 'generates audio html structure' do markdown = "![audio_file](audio_file_name.wav)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/audio_file_name.wav"') + expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio_file_name.wav"') end it 'rewrites and replaces audio links names with white spaces to %20' do markdown = "![audio file](audio file name.wav)" output = described_class.to_html(markdown, project: project, project_wiki: project_wiki, page_slug: page.slug) - expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/wikis/nested/twice/audio%20file%20name.wav"') + expect(output).to include('<audio src="/wiki_link_ns/wiki_link_project/-/wikis/nested/twice/audio%20file%20name.wav"') end end end diff --git a/spec/lib/gitlab/chat/command_spec.rb b/spec/lib/gitlab/chat/command_spec.rb index 46d23ab2b62..f7f344bf786 100644 --- a/spec/lib/gitlab/chat/command_spec.rb +++ b/spec/lib/gitlab/chat/command_spec.rb @@ -44,7 +44,7 @@ describe Gitlab::Chat::Command do let(:pipeline) { command.create_pipeline } before do - stub_repository_ci_yaml_file(sha: project.commit.id) + stub_ci_pipeline_yaml_file(gitlab_ci_yaml) project.add_developer(chat_name.user) end diff --git a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb index a631cd2777b..b81094f8b4a 100644 --- a/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb +++ b/spec/lib/gitlab/ci/pipeline/chain/build_spec.rb @@ -30,7 +30,7 @@ describe Gitlab::Ci::Pipeline::Chain::Build do let(:step) { described_class.new(pipeline, command) } before do - stub_repository_ci_yaml_file(sha: anything) + stub_ci_pipeline_yaml_file(gitlab_ci_yaml) end it 'never breaks the chain' do diff --git a/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb new file mode 100644 index 00000000000..7ebe5842fd0 --- /dev/null +++ b/spec/lib/gitlab/ci/pipeline/chain/config/content_spec.rb @@ -0,0 +1,221 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::Ci::Pipeline::Chain::Config::Content do + let(:project) { create(:project, ci_config_path: ci_config_path) } + let(:pipeline) { build(:ci_pipeline, project: project) } + let(:command) { Gitlab::Ci::Pipeline::Chain::Command.new(project: project) } + + subject { described_class.new(pipeline, command) } + + describe '#perform!' do + context 'when feature flag is disabled' do + before do + stub_feature_flags(ci_root_config_content: false) + end + + context 'when config is defined in a custom path in the repository' do + let(:ci_config_path) { 'path/to/config.yml' } + + before do + expect(project.repository) + .to receive(:gitlab_ci_yml_for) + .with(pipeline.sha, ci_config_path) + .and_return('the-content') + end + + it 'returns the content of the YAML file' do + subject.perform! + + expect(pipeline.config_source).to eq 'repository_source' + expect(command.config_content).to eq('the-content') + end + end + + context 'when config is defined remotely' do + let(:ci_config_path) { 'http://example.com/path/to/ci/config.yml' } + + it 'does not support URLs and default to AutoDevops' do + subject.perform! + + expect(pipeline.config_source).to eq 'auto_devops_source' + template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') + expect(command.config_content).to eq(template.content) + end + end + + context 'when config is defined in a separate repository' do + let(:ci_config_path) { 'path/to/.gitlab-ci.yml@another-group/another-repo' } + + it 'does not support YAML from external repository and default to AutoDevops' do + subject.perform! + + expect(pipeline.config_source).to eq 'auto_devops_source' + template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') + expect(command.config_content).to eq(template.content) + end + end + + context 'when config is defined in the default .gitlab-ci.yml' do + let(:ci_config_path) { nil } + + before do + expect(project.repository) + .to receive(:gitlab_ci_yml_for) + .with(pipeline.sha, '.gitlab-ci.yml') + .and_return('the-content') + end + + it 'returns the content of the canonical config file' do + subject.perform! + + expect(pipeline.config_source).to eq 'repository_source' + expect(command.config_content).to eq('the-content') + end + end + + context 'when config is the Auto-Devops template' do + let(:ci_config_path) { nil } + + before do + expect(project).to receive(:auto_devops_enabled?).and_return(true) + end + + it 'returns the content of AutoDevops template' do + subject.perform! + + expect(pipeline.config_source).to eq 'auto_devops_source' + template = Gitlab::Template::GitlabCiYmlTemplate.find('Auto-DevOps') + expect(command.config_content).to eq(template.content) + end + end + + context 'when config is not defined anywhere' do + let(:ci_config_path) { nil } + + before do + expect(project).to receive(:auto_devops_enabled?).and_return(false) + end + + it 'builds root config including the auto-devops template' do + subject.perform! + + expect(pipeline.config_source).to eq('unknown_source') + expect(command.config_content).to be_nil + expect(pipeline.errors.full_messages).to include('Missing CI config file') + end + end + end + + context 'when config is defined in a custom path in the repository' do + let(:ci_config_path) { 'path/to/config.yml' } + + before do + expect(project.repository) + .to receive(:gitlab_ci_yml_for) + .with(pipeline.sha, ci_config_path) + .and_return('the-content') + end + + it 'builds root config including the local custom file' do + subject.perform! + + expect(pipeline.config_source).to eq 'repository_source' + expect(command.config_content).to eq(<<~EOY) + --- + include: + - local: #{ci_config_path} + EOY + end + end + + context 'when config is defined remotely' do + let(:ci_config_path) { 'http://example.com/path/to/ci/config.yml' } + + it 'builds root config including the remote config' do + subject.perform! + + expect(pipeline.config_source).to eq 'remote_source' + expect(command.config_content).to eq(<<~EOY) + --- + include: + - remote: #{ci_config_path} + EOY + end + end + + context 'when config is defined in a separate repository' do + let(:ci_config_path) { 'path/to/.gitlab-ci.yml@another-group/another-repo' } + + it 'builds root config including the path to another repository' do + subject.perform! + + expect(pipeline.config_source).to eq 'external_project_source' + expect(command.config_content).to eq(<<~EOY) + --- + include: + - project: another-group/another-repo + file: path/to/.gitlab-ci.yml + EOY + end + end + + context 'when config is defined in the default .gitlab-ci.yml' do + let(:ci_config_path) { nil } + + before do + expect(project.repository) + .to receive(:gitlab_ci_yml_for) + .with(pipeline.sha, '.gitlab-ci.yml') + .and_return('the-content') + end + + it 'builds root config including the canonical CI config file' do + subject.perform! + + expect(pipeline.config_source).to eq 'repository_source' + expect(command.config_content).to eq(<<~EOY) + --- + include: + - local: ".gitlab-ci.yml" + EOY + end + end + + context 'when config is the Auto-Devops template' do + let(:ci_config_path) { nil } + + before do + expect(project).to receive(:auto_devops_enabled?).and_return(true) + end + + it 'builds root config including the auto-devops template' do + subject.perform! + + expect(pipeline.config_source).to eq 'auto_devops_source' + expect(command.config_content).to eq(<<~EOY) + --- + include: + - template: Auto-DevOps.gitlab-ci.yml + EOY + end + end + + context 'when config is not defined anywhere' do + let(:ci_config_path) { nil } + + before do + expect(project).to receive(:auto_devops_enabled?).and_return(false) + end + + it 'builds root config including the auto-devops template' do + subject.perform! + + expect(pipeline.config_source).to eq('unknown_source') + expect(command.config_content).to be_nil + expect(pipeline.errors.full_messages).to include('Missing CI config file') + end + end + end +end diff --git a/spec/models/project_wiki_spec.rb b/spec/models/project_wiki_spec.rb index 31d1d1fd7d1..af23f121bdc 100644 --- a/spec/models/project_wiki_spec.rb +++ b/spec/models/project_wiki_spec.rb @@ -28,7 +28,7 @@ describe ProjectWiki do describe '#web_url' do it 'returns the full web URL to the wiki' do - expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}/wikis/home") + expect(subject.web_url).to eq("#{Gitlab.config.gitlab.url}/#{project.full_path}/-/wikis/home") end end @@ -71,7 +71,7 @@ describe ProjectWiki do describe "#wiki_base_path" do it "returns the wiki base path" do - wiki_base_path = "#{Gitlab.config.gitlab.relative_url_root}/#{project.full_path}/wikis" + wiki_base_path = "#{Gitlab.config.gitlab.relative_url_root}/#{project.full_path}/-/wikis" expect(subject.wiki_base_path).to eq(wiki_base_path) end diff --git a/spec/requests/api/pipelines_spec.rb b/spec/requests/api/pipelines_spec.rb index cce52cfc1ca..2b34b64812d 100644 --- a/spec/requests/api/pipelines_spec.rb +++ b/spec/requests/api/pipelines_spec.rb @@ -384,7 +384,7 @@ describe API::Pipelines do post api("/projects/#{project.id}/pipeline", user), params: { ref: project.default_branch } expect(response).to have_gitlab_http_status(400) - expect(json_response['message']['base'].first).to eq 'Missing .gitlab-ci.yml file' + expect(json_response['message']['base'].first).to eq 'Missing CI config file' expect(json_response).not_to be_an Array end end diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index fc562f93406..287db20448a 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -155,17 +155,21 @@ describe 'project routing' do # DELETE /:project_id/wikis/:id(.:format) projects/wikis#destroy describe Projects::WikisController, 'routing' do it 'to #pages' do - expect(get('/gitlab/gitlabhq/wikis/pages')).to route_to('projects/wikis#pages', namespace_id: 'gitlab', project_id: 'gitlabhq') + expect(get('/gitlab/gitlabhq/-/wikis/pages')).to route_to('projects/wikis#pages', namespace_id: 'gitlab', project_id: 'gitlabhq') end it 'to #history' do - expect(get('/gitlab/gitlabhq/wikis/1/history')).to route_to('projects/wikis#history', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') + expect(get('/gitlab/gitlabhq/-/wikis/1/history')).to route_to('projects/wikis#history', namespace_id: 'gitlab', project_id: 'gitlabhq', id: '1') end it_behaves_like 'RESTful project resources' do let(:actions) { [:create, :edit, :show, :destroy] } let(:controller) { 'wikis' } + let(:controller_path) { '/-/wikis' } end + + it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/wikis", "/gitlab/gitlabhq/-/wikis" + it_behaves_like 'redirecting a legacy project path', "/gitlab/gitlabhq/wikis/home/edit", "/gitlab/gitlabhq/-/wikis/home/edit" end # branches_project_repository GET /:project_id/repository/branches(.:format) projects/repositories#branches diff --git a/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb new file mode 100644 index 00000000000..685abbf7e6c --- /dev/null +++ b/spec/serializers/merge_request_poll_cached_widget_entity_spec.rb @@ -0,0 +1,202 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MergeRequestPollCachedWidgetEntity do + include ProjectForksHelper + + let(:project) { create :project, :repository } + let(:resource) { create(:merge_request, source_project: project, target_project: project) } + let(:user) { create(:user) } + + let(:request) { double('request', current_user: user, project: project) } + + subject do + described_class.new(resource, request: request).as_json + end + + it 'has the latest sha of the target branch' do + is_expected.to include(:target_branch_sha) + end + + describe 'diverged_commits_count' do + context 'when MR open and its diverging' do + it 'returns diverged commits count' do + allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: true, + diverged_commits_count: 10) + + expect(subject[:diverged_commits_count]).to eq(10) + end + end + + context 'when MR is not open' do + it 'returns 0' do + allow(resource).to receive_messages(open?: false) + + expect(subject[:diverged_commits_count]).to be_zero + end + end + + context 'when MR is not diverging' do + it 'returns 0' do + allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: false) + + expect(subject[:diverged_commits_count]).to be_zero + end + end + end + + describe 'diff_head_sha' do + before do + allow(resource).to receive(:diff_head_sha) { 'sha' } + end + + context 'when diff head commit is empty' do + it 'returns nil' do + allow(resource).to receive(:diff_head_sha) { '' } + + expect(subject[:diff_head_sha]).to be_nil + end + end + + context 'when diff head commit present' do + it 'returns diff head commit short id' do + expect(subject[:diff_head_sha]).to eq('sha') + end + end + end + + describe 'metrics' do + context 'when metrics record exists with merged data' do + before do + resource.mark_as_merged! + resource.metrics.update!(merged_by: user) + end + + it 'matches merge request metrics schema' do + expect(subject[:metrics].with_indifferent_access) + .to match_schema('entities/merge_request_metrics') + end + + it 'returns values from metrics record' do + expect(subject.dig(:metrics, :merged_by, :id)) + .to eq(resource.metrics.merged_by_id) + end + end + + context 'when metrics record exists with closed data' do + before do + resource.close! + resource.metrics.update!(latest_closed_by: user) + end + + it 'matches merge request metrics schema' do + expect(subject[:metrics].with_indifferent_access) + .to match_schema('entities/merge_request_metrics') + end + + it 'returns values from metrics record' do + expect(subject.dig(:metrics, :closed_by, :id)) + .to eq(resource.metrics.latest_closed_by_id) + end + end + + context 'when metrics does not exists' do + before do + resource.mark_as_merged! + resource.metrics.destroy! + resource.reload + end + + context 'when events exists' do + let!(:closed_event) { create(:event, :closed, project: project, target: resource) } + let!(:merge_event) { create(:event, :merged, project: project, target: resource) } + + it 'matches merge request metrics schema' do + expect(subject[:metrics].with_indifferent_access) + .to match_schema('entities/merge_request_metrics') + end + + it 'returns values from events record' do + expect(subject.dig(:metrics, :merged_by, :id)) + .to eq(merge_event.author_id) + + expect(subject.dig(:metrics, :closed_by, :id)) + .to eq(closed_event.author_id) + + expect(subject.dig(:metrics, :merged_at).to_s) + .to eq(merge_event.updated_at.to_s) + + expect(subject.dig(:metrics, :closed_at).to_s) + .to eq(closed_event.updated_at.to_s) + end + end + + context 'when events does not exists' do + it 'matches merge request metrics schema' do + expect(subject[:metrics].with_indifferent_access) + .to match_schema('entities/merge_request_metrics') + end + end + end + end + + describe 'commits_without_merge_commits' do + def find_matching_commit(short_id) + resource.commits.find { |c| c.short_id == short_id } + end + + it 'does not include merge commits' do + commits_in_widget = subject[:commits_without_merge_commits] + + expect(commits_in_widget.length).to be < resource.commits.length + expect(commits_in_widget.length).to eq(resource.commits.without_merge_commits.length) + commits_in_widget.each do |c| + expect(find_matching_commit(c[:short_id]).merge_commit?).to eq(false) + end + end + end + + describe 'auto merge' do + context 'when auto merge is enabled' do + let(:resource) { create(:merge_request, :merge_when_pipeline_succeeds) } + + it 'returns auto merge related information' do + expect(subject[:auto_merge_enabled]).to be_truthy + end + end + + context 'when auto merge is not enabled' do + let(:resource) { create(:merge_request) } + + it 'returns auto merge related information' do + expect(subject[:auto_merge_enabled]).to be_falsy + end + end + end + + describe 'attributes for squash commit message' do + context 'when merge request is mergeable' do + before do + stub_const('MergeRequestDiff::COMMITS_SAFE_SIZE', 20) + end + + it 'has default_squash_commit_message and commits_without_merge_commits' do + expect(subject[:default_squash_commit_message]) + .to eq(resource.default_squash_commit_message) + expect(subject[:commits_without_merge_commits].size).to eq(12) + end + end + + context 'when merge request is not mergeable' do + before do + allow(resource).to receive(:mergeable?).and_return(false) + end + + it 'does not have default_squash_commit_message and commits_without_merge_commits' do + expect(subject[:default_squash_commit_message]).to eq(nil) + expect(subject[:commits_without_merge_commits]).to eq(nil) + end + end + end +end diff --git a/spec/serializers/merge_request_poll_widget_entity_spec.rb b/spec/serializers/merge_request_poll_widget_entity_spec.rb new file mode 100644 index 00000000000..ea9052b4046 --- /dev/null +++ b/spec/serializers/merge_request_poll_widget_entity_spec.rb @@ -0,0 +1,180 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MergeRequestPollWidgetEntity do + include ProjectForksHelper + + let(:project) { create :project, :repository } + let(:resource) { create(:merge_request, source_project: project, target_project: project) } + let(:user) { create(:user) } + + let(:request) { double('request', current_user: user, project: project) } + + subject do + described_class.new(resource, request: request).as_json + end + + it 'has default_merge_commit_message_with_description' do + expect(subject[:default_merge_commit_message_with_description]) + .to eq(resource.default_merge_commit_message(include_description: true)) + end + + describe 'merge_pipeline' do + it 'returns nil' do + expect(subject[:merge_pipeline]).to be_nil + end + + context 'when is merged' do + let(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) } + let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) } + + before do + project.add_maintainer(user) + end + + it 'returns merge_pipeline' do + pipeline.reload + pipeline_payload = PipelineDetailsEntity + .represent(pipeline, request: request) + .as_json + + expect(subject[:merge_pipeline]).to eq(pipeline_payload) + end + + context 'when user cannot read pipelines on target project' do + before do + project.add_guest(user) + end + + it 'returns nil' do + expect(subject[:merge_pipeline]).to be_nil + end + end + end + end + + describe 'new_blob_path' do + context 'when user can push to project' do + it 'returns path' do + project.add_developer(user) + + expect(subject[:new_blob_path]) + .to eq("/#{resource.project.full_path}/new/#{resource.source_branch}") + end + end + + context 'when user cannot push to project' do + it 'returns nil' do + expect(subject[:new_blob_path]).to be_nil + end + end + end + + describe 'exposed_artifacts_path' do + context 'when merge request has exposed artifacts' do + before do + expect(resource).to receive(:has_exposed_artifacts?).and_return(true) + end + + it 'set the path to poll data' do + expect(subject[:exposed_artifacts_path]).to be_present + end + end + + context 'when merge request has no exposed artifacts' do + before do + expect(resource).to receive(:has_exposed_artifacts?).and_return(false) + end + + it 'set the path to poll data' do + expect(subject[:exposed_artifacts_path]).to be_nil + end + end + end + + describe 'auto merge' do + context 'when auto merge is enabled' do + let(:resource) { create(:merge_request, :merge_when_pipeline_succeeds) } + + it 'returns auto merge related information' do + expect(subject[:auto_merge_strategy]).to eq('merge_when_pipeline_succeeds') + end + end + + context 'when auto merge is not enabled' do + let(:resource) { create(:merge_request) } + + it 'returns auto merge related information' do + expect(subject[:auto_merge_strategy]).to be_nil + end + end + + context 'when head pipeline is running' do + before do + create(:ci_pipeline, :running, project: project, + ref: resource.source_branch, + sha: resource.diff_head_sha) + resource.update_head_pipeline + end + + it 'returns available auto merge strategies' do + expect(subject[:available_auto_merge_strategies]).to eq(%w[merge_when_pipeline_succeeds]) + end + end + + context 'when head pipeline is finished' do + before do + create(:ci_pipeline, :success, project: project, + ref: resource.source_branch, + sha: resource.diff_head_sha) + resource.update_head_pipeline + end + + it 'returns available auto merge strategies' do + expect(subject[:available_auto_merge_strategies]).to be_empty + end + end + end + + describe 'pipeline' do + let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.source_branch, sha: resource.source_branch_sha, head_pipeline_of: resource) } + + before do + allow_any_instance_of(MergeRequestPresenter).to receive(:can?).and_call_original + allow_any_instance_of(MergeRequestPresenter).to receive(:can?).with(user, :read_pipeline, anything).and_return(result) + end + + context 'when user has access to pipelines' do + let(:result) { true } + + context 'when is up to date' do + let(:req) { double('request', current_user: user, project: project) } + + it 'returns pipeline' do + pipeline_payload = PipelineDetailsEntity + .represent(pipeline, request: req) + .as_json + + expect(subject[:pipeline]).to eq(pipeline_payload) + end + end + + context 'when is not up to date' do + it 'returns nil' do + pipeline.update(sha: "not up to date") + + expect(subject[:pipeline]).to eq(nil) + end + end + end + + context 'when user does not have access to pipelines' do + let(:result) { false } + + it 'does not have pipeline' do + expect(subject[:pipeline]).to eq(nil) + end + end + end +end diff --git a/spec/serializers/merge_request_widget_entity_spec.rb b/spec/serializers/merge_request_widget_entity_spec.rb index 4e79fd32215..22232682be1 100644 --- a/spec/serializers/merge_request_widget_entity_spec.rb +++ b/spec/serializers/merge_request_widget_entity_spec.rb @@ -15,10 +15,6 @@ describe MergeRequestWidgetEntity do described_class.new(resource, request: request).as_json end - it 'has the latest sha of the target branch' do - is_expected.to include(:target_branch_sha) - end - describe 'source_project_full_path' do it 'includes the full path of the source project' do expect(subject[:source_project_full_path]).to be_present @@ -47,156 +43,6 @@ describe MergeRequestWidgetEntity do end end - describe 'pipeline' do - let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.source_branch, sha: resource.source_branch_sha, head_pipeline_of: resource) } - - before do - allow_any_instance_of(MergeRequestPresenter).to receive(:can?).and_call_original - allow_any_instance_of(MergeRequestPresenter).to receive(:can?).with(user, :read_pipeline, anything).and_return(result) - end - - context 'when user has access to pipelines' do - let(:result) { true } - - context 'when is up to date' do - let(:req) { double('request', current_user: user, project: project) } - - it 'returns pipeline' do - pipeline_payload = PipelineDetailsEntity - .represent(pipeline, request: req) - .as_json - - expect(subject[:pipeline]).to eq(pipeline_payload) - end - end - - context 'when is not up to date' do - it 'returns nil' do - pipeline.update(sha: "not up to date") - - expect(subject[:pipeline]).to eq(nil) - end - end - end - - context 'when user does not have access to pipelines' do - let(:result) { false } - - it 'does not have pipeline' do - expect(subject[:pipeline]).to eq(nil) - end - end - end - - describe 'merge_pipeline' do - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - - context 'when is merged' do - let(:resource) { create(:merged_merge_request, source_project: project, merge_commit_sha: project.commit.id) } - let(:pipeline) { create(:ci_empty_pipeline, project: project, ref: resource.target_branch, sha: resource.merge_commit_sha) } - - before do - project.add_maintainer(user) - end - - it 'returns merge_pipeline' do - pipeline.reload - pipeline_payload = PipelineDetailsEntity - .represent(pipeline, request: request) - .as_json - - expect(subject[:merge_pipeline]).to eq(pipeline_payload) - end - - context 'when user cannot read pipelines on target project' do - before do - project.add_guest(user) - end - - it 'returns nil' do - expect(subject[:merge_pipeline]).to be_nil - end - end - end - end - - describe 'metrics' do - context 'when metrics record exists with merged data' do - before do - resource.mark_as_merged! - resource.metrics.update!(merged_by: user) - end - - it 'matches merge request metrics schema' do - expect(subject[:metrics].with_indifferent_access) - .to match_schema('entities/merge_request_metrics') - end - - it 'returns values from metrics record' do - expect(subject.dig(:metrics, :merged_by, :id)) - .to eq(resource.metrics.merged_by_id) - end - end - - context 'when metrics record exists with closed data' do - before do - resource.close! - resource.metrics.update!(latest_closed_by: user) - end - - it 'matches merge request metrics schema' do - expect(subject[:metrics].with_indifferent_access) - .to match_schema('entities/merge_request_metrics') - end - - it 'returns values from metrics record' do - expect(subject.dig(:metrics, :closed_by, :id)) - .to eq(resource.metrics.latest_closed_by_id) - end - end - - context 'when metrics does not exists' do - before do - resource.mark_as_merged! - resource.metrics.destroy! - resource.reload - end - - context 'when events exists' do - let!(:closed_event) { create(:event, :closed, project: project, target: resource) } - let!(:merge_event) { create(:event, :merged, project: project, target: resource) } - - it 'matches merge request metrics schema' do - expect(subject[:metrics].with_indifferent_access) - .to match_schema('entities/merge_request_metrics') - end - - it 'returns values from events record' do - expect(subject.dig(:metrics, :merged_by, :id)) - .to eq(merge_event.author_id) - - expect(subject.dig(:metrics, :closed_by, :id)) - .to eq(closed_event.author_id) - - expect(subject.dig(:metrics, :merged_at).to_s) - .to eq(merge_event.updated_at.to_s) - - expect(subject.dig(:metrics, :closed_at).to_s) - .to eq(closed_event.updated_at.to_s) - end - end - - context 'when events does not exists' do - it 'matches merge request metrics schema' do - expect(subject[:metrics].with_indifferent_access) - .to match_schema('entities/merge_request_metrics') - end - end - end - end - it 'has email_patches_path' do expect(subject[:email_patches_path]) .to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.patch") @@ -207,100 +53,6 @@ describe MergeRequestWidgetEntity do .to eq("/#{resource.project.full_path}/merge_requests/#{resource.iid}.diff") end - it 'has default_merge_commit_message_with_description' do - expect(subject[:default_merge_commit_message_with_description]) - .to eq(resource.default_merge_commit_message(include_description: true)) - end - - describe 'attributes for squash commit message' do - context 'when merge request is mergeable' do - before do - stub_const('MergeRequestDiff::COMMITS_SAFE_SIZE', 20) - end - - it 'has default_squash_commit_message and commits_without_merge_commits' do - expect(subject[:default_squash_commit_message]) - .to eq(resource.default_squash_commit_message) - expect(subject[:commits_without_merge_commits].size).to eq(12) - end - end - - context 'when merge request is not mergeable' do - before do - allow(resource).to receive(:mergeable?).and_return(false) - end - - it 'does not have default_squash_commit_message and commits_without_merge_commits' do - expect(subject[:default_squash_commit_message]).to eq(nil) - expect(subject[:commits_without_merge_commits]).to eq(nil) - end - end - end - - describe 'new_blob_path' do - context 'when user can push to project' do - it 'returns path' do - project.add_developer(user) - - expect(subject[:new_blob_path]) - .to eq("/#{resource.project.full_path}/new/#{resource.source_branch}") - end - end - - context 'when user cannot push to project' do - it 'returns nil' do - expect(subject[:new_blob_path]).to be_nil - end - end - end - - describe 'diff_head_sha' do - before do - allow(resource).to receive(:diff_head_sha) { 'sha' } - end - - context 'when diff head commit is empty' do - it 'returns nil' do - allow(resource).to receive(:diff_head_sha) { '' } - - expect(subject[:diff_head_sha]).to be_nil - end - end - - context 'when diff head commit present' do - it 'returns diff head commit short id' do - expect(subject[:diff_head_sha]).to eq('sha') - end - end - end - - describe 'diverged_commits_count' do - context 'when MR open and its diverging' do - it 'returns diverged commits count' do - allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: true, - diverged_commits_count: 10) - - expect(subject[:diverged_commits_count]).to eq(10) - end - end - - context 'when MR is not open' do - it 'returns 0' do - allow(resource).to receive_messages(open?: false) - - expect(subject[:diverged_commits_count]).to be_zero - end - end - - context 'when MR is not diverging' do - it 'returns 0' do - allow(resource).to receive_messages(open?: true, diverged_from_target_branch?: false) - - expect(subject[:diverged_commits_count]).to be_zero - end - end - end - describe 'when source project is deleted' do let(:project) { create(:project, :repository) } let(:forked_project) { fork_project(project) } @@ -316,88 +68,4 @@ describe MergeRequestWidgetEntity do expect(entity[:rebase_path]).to be_nil end end - - describe 'commits_without_merge_commits' do - def find_matching_commit(short_id) - resource.commits.find { |c| c.short_id == short_id } - end - - it 'does not include merge commits' do - commits_in_widget = subject[:commits_without_merge_commits] - - expect(commits_in_widget.length).to be < resource.commits.length - expect(commits_in_widget.length).to eq(resource.commits.without_merge_commits.length) - commits_in_widget.each do |c| - expect(find_matching_commit(c[:short_id]).merge_commit?).to eq(false) - end - end - end - - describe 'auto merge' do - context 'when auto merge is enabled' do - let(:resource) { create(:merge_request, :merge_when_pipeline_succeeds) } - - it 'returns auto merge related information' do - expect(subject[:auto_merge_enabled]).to be_truthy - expect(subject[:auto_merge_strategy]).to eq('merge_when_pipeline_succeeds') - end - end - - context 'when auto merge is not enabled' do - let(:resource) { create(:merge_request) } - - it 'returns auto merge related information' do - expect(subject[:auto_merge_enabled]).to be_falsy - expect(subject[:auto_merge_strategy]).to be_nil - end - end - - context 'when head pipeline is running' do - before do - create(:ci_pipeline, :running, project: project, - ref: resource.source_branch, - sha: resource.diff_head_sha) - resource.update_head_pipeline - end - - it 'returns available auto merge strategies' do - expect(subject[:available_auto_merge_strategies]).to eq(%w[merge_when_pipeline_succeeds]) - end - end - - context 'when head pipeline is finished' do - before do - create(:ci_pipeline, :success, project: project, - ref: resource.source_branch, - sha: resource.diff_head_sha) - resource.update_head_pipeline - end - - it 'returns available auto merge strategies' do - expect(subject[:available_auto_merge_strategies]).to be_empty - end - end - end - - describe 'exposed_artifacts_path' do - context 'when merge request has exposed artifacts' do - before do - expect(resource).to receive(:has_exposed_artifacts?).and_return(true) - end - - it 'set the path to poll data' do - expect(subject[:exposed_artifacts_path]).to be_present - end - end - - context 'when merge request has no exposed artifacts' do - before do - expect(resource).to receive(:has_exposed_artifacts?).and_return(false) - end - - it 'set the path to poll data' do - expect(subject[:exposed_artifacts_path]).to be_nil - end - end - end end diff --git a/spec/services/ci/create_pipeline_service_spec.rb b/spec/services/ci/create_pipeline_service_spec.rb index 8f16d375f03..d450bb12e8c 100644 --- a/spec/services/ci/create_pipeline_service_spec.rb +++ b/spec/services/ci/create_pipeline_service_spec.rb @@ -10,7 +10,7 @@ describe Ci::CreatePipelineService do let(:ref_name) { 'refs/heads/master' } before do - stub_repository_ci_yaml_file(sha: anything) + stub_ci_pipeline_yaml_file(gitlab_ci_yaml) end describe '#execute' do @@ -510,7 +510,7 @@ describe Ci::CreatePipelineService do it 'attaches errors to the pipeline' do pipeline = execute_service - expect(pipeline.errors.full_messages).to eq ['Missing .gitlab-ci.yml file'] + expect(pipeline.errors.full_messages).to eq ['Missing CI config file'] expect(pipeline).not_to be_persisted end end diff --git a/spec/support/helpers/stub_gitlab_calls.rb b/spec/support/helpers/stub_gitlab_calls.rb index fe343da7838..ff4b9db8ad9 100644 --- a/spec/support/helpers/stub_gitlab_calls.rb +++ b/spec/support/helpers/stub_gitlab_calls.rb @@ -19,24 +19,28 @@ module StubGitlabCalls end def stub_ci_pipeline_yaml_file(ci_yaml_content) - allow_any_instance_of(Repository).to receive(:gitlab_ci_yml_for).and_return(ci_yaml_content) + allow_any_instance_of(Repository) + .to receive(:gitlab_ci_yml_for) + .and_return(ci_yaml_content) # Ensure we don't hit auto-devops when config not found in repository unless ci_yaml_content allow_any_instance_of(Project).to receive(:auto_devops_enabled?).and_return(false) end + + # Stub the first call to `include:[local: .gitlab-ci.yml]` when + # evaluating the CI root config content. + if Feature.enabled?(:ci_root_config_content, default_enabled: true) + allow_any_instance_of(Gitlab::Ci::Config::External::File::Local) + .to receive(:content) + .and_return(ci_yaml_content) + end end def stub_pipeline_modified_paths(pipeline, modified_paths) allow(pipeline).to receive(:modified_paths).and_return(modified_paths) end - def stub_repository_ci_yaml_file(sha:, path: '.gitlab-ci.yml') - allow_any_instance_of(Repository) - .to receive(:gitlab_ci_yml_for).with(sha, path) - .and_return(gitlab_ci_yaml) - end - def stub_ci_builds_disabled allow_any_instance_of(Project).to receive(:builds_enabled?).and_return(false) end diff --git a/spec/views/search/_results.html.haml_spec.rb b/spec/views/search/_results.html.haml_spec.rb index 177ade3b700..628d2e10f93 100644 --- a/spec/views/search/_results.html.haml_spec.rb +++ b/spec/views/search/_results.html.haml_spec.rb @@ -16,7 +16,7 @@ describe 'search/_results' do it 'displays the page size' do render - expect(rendered).to have_content('Showing 1 - 2 of 3 issues for "foo"') + expect(rendered).to have_content('Showing 1 - 2 of 3 issues for foo') end context 'when search results do not have a count' do |