diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 15:07:55 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-14 15:07:55 +0000 |
commit | 85e494935a8726dc98bb19ffa584488420e5011e (patch) | |
tree | 5acf279dab81a2363e4504a9679c32c16510542b /spec | |
parent | 4ce0bee95df15c05cdb0d777eba31fe753bc443b (diff) | |
download | gitlab-ce-85e494935a8726dc98bb19ffa584488420e5011e.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/features/projects/files/user_browses_files_spec.rb | 5 | ||||
-rw-r--r-- | spec/features/projects/files/user_browses_lfs_files_spec.rb | 15 | ||||
-rw-r--r-- | spec/features/projects/wiki/users_views_asciidoc_page_with_includes_spec.rb | 79 | ||||
-rw-r--r-- | spec/fixtures/api/schemas/public_api/v4/service.json | 3 | ||||
-rw-r--r-- | spec/frontend/repository/components/table/parent_row_spec.js | 10 | ||||
-rw-r--r-- | spec/frontend/repository/components/table/row_spec.js | 15 | ||||
-rw-r--r-- | spec/helpers/markup_helper_spec.rb | 5 | ||||
-rw-r--r-- | spec/lib/gitlab/app_text_logger_spec.rb | 7 | ||||
-rw-r--r-- | spec/lib/gitlab/asciidoc_spec.rb | 26 | ||||
-rw-r--r-- | spec/lib/sentry/api_urls_spec.rb | 85 | ||||
-rw-r--r-- | spec/lib/sentry/client/issue_spec.rb | 30 | ||||
-rw-r--r-- | spec/lib/sentry/client/projects_spec.rb | 19 | ||||
-rw-r--r-- | spec/models/concerns/atomic_internal_id_spec.rb | 26 | ||||
-rw-r--r-- | spec/requests/api/issues/post_projects_issues_spec.rb | 10 | ||||
-rw-r--r-- | spec/services/users/destroy_service_spec.rb | 16 | ||||
-rw-r--r-- | spec/support/matchers/eq_uri.rb | 19 |
16 files changed, 315 insertions, 55 deletions
diff --git a/spec/features/projects/files/user_browses_files_spec.rb b/spec/features/projects/files/user_browses_files_spec.rb index 657513431e5..b8efabb0cab 100644 --- a/spec/features/projects/files/user_browses_files_spec.rb +++ b/spec/features/projects/files/user_browses_files_spec.rb @@ -41,6 +41,11 @@ describe "User browses files" do it "shows the `Browse Directory` link" do click_link("files") + + page.within('.repo-breadcrumb') do + expect(page).to have_link('files') + end + click_link("History") expect(page).to have_link("Browse Directory").and have_no_link("Browse Code") diff --git a/spec/features/projects/files/user_browses_lfs_files_spec.rb b/spec/features/projects/files/user_browses_lfs_files_spec.rb index 618290416bd..dbeec973865 100644 --- a/spec/features/projects/files/user_browses_lfs_files_spec.rb +++ b/spec/features/projects/files/user_browses_lfs_files_spec.rb @@ -19,7 +19,17 @@ describe 'Projects > Files > User browses LFS files' do it 'is possible to see raw content of LFS pointer' do click_link 'files' + + page.within('.repo-breadcrumb') do + expect(page).to have_link('files') + end + click_link 'lfs' + + page.within('.repo-breadcrumb') do + expect(page).to have_link('lfs') + end + click_link 'lfs_object.iso' expect(page).to have_content 'version https://git-lfs.github.com/spec/v1' @@ -38,6 +48,11 @@ describe 'Projects > Files > User browses LFS files' do it 'shows an LFS object' do click_link('files') + + page.within('.repo-breadcrumb') do + expect(page).to have_link('files') + end + click_link('lfs') click_link('lfs_object.iso') diff --git a/spec/features/projects/wiki/users_views_asciidoc_page_with_includes_spec.rb b/spec/features/projects/wiki/users_views_asciidoc_page_with_includes_spec.rb new file mode 100644 index 00000000000..08eea14c438 --- /dev/null +++ b/spec/features/projects/wiki/users_views_asciidoc_page_with_includes_spec.rb @@ -0,0 +1,79 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe 'User views AsciiDoc page with includes', :js do + let_it_be(:user) { create(:user) } + let_it_be(:wiki_content_selector) { '[data-qa-selector=wiki_page_content]' } + let(:project) { create(:project, :public, :wiki_repo) } + let!(:included_wiki_page) { create_wiki_page('included_page', content: 'Content from the included page')} + let!(:wiki_page) { create_wiki_page('home', content: "Content from the main page.\ninclude::included_page.asciidoc[]") } + + def create_wiki_page(title, content:) + attrs = { + title: title, + content: content, + format: :asciidoc + } + + create(:wiki_page, wiki: project.wiki, attrs: attrs) + end + + before do + sign_in(user) + end + + context 'when the file being included exists' do + it 'includes the file contents' do + visit(project_wiki_path(project, wiki_page)) + + page.within(:css, wiki_content_selector) do + expect(page).to have_content('Content from the main page. Content from the included page') + end + end + + context 'when there are multiple versions of the wiki pages' do + before do + included_wiki_page.update(message: 'updated included file', content: 'Updated content from the included page') + wiki_page.update(message: 'updated wiki page', content: "Updated content from the main page.\ninclude::included_page.asciidoc[]") + end + + let(:latest_version_id) { wiki_page.versions.first.id } + let(:oldest_version_id) { wiki_page.versions.last.id } + + context 'viewing the latest version' do + it 'includes the latest content' do + visit(project_wiki_path(project, wiki_page, version_id: latest_version_id)) + + page.within(:css, wiki_content_selector) do + expect(page).to have_content('Updated content from the main page. Updated content from the included page') + end + end + end + + context 'viewing the original version' do + it 'includes the content from the original version' do + visit(project_wiki_path(project, wiki_page, version_id: oldest_version_id)) + + page.within(:css, wiki_content_selector) do + expect(page).to have_content('Content from the main page. Content from the included page') + end + end + end + end + end + + context 'when the file being included does not exist' do + before do + included_wiki_page.delete + end + + it 'outputs an error' do + visit(project_wiki_path(project, wiki_page)) + + page.within(:css, wiki_content_selector) do + expect(page).to have_content('Content from the main page. [ERROR: include::included_page.asciidoc[] - unresolved directive]') + end + end + end +end diff --git a/spec/fixtures/api/schemas/public_api/v4/service.json b/spec/fixtures/api/schemas/public_api/v4/service.json index 4a91d264961..a024e38acad 100644 --- a/spec/fixtures/api/schemas/public_api/v4/service.json +++ b/spec/fixtures/api/schemas/public_api/v4/service.json @@ -16,7 +16,8 @@ "confidential_note_events": { "type": "boolean" }, "pipeline_events": { "type": "boolean" }, "wiki_page_events": { "type": "boolean" }, - "job_events": { "type": "boolean" } + "job_events": { "type": "boolean" }, + "comment_on_event_enabled": { "type": "boolean" } }, "additionalProperties": false } diff --git a/spec/frontend/repository/components/table/parent_row_spec.js b/spec/frontend/repository/components/table/parent_row_spec.js index 7020055271f..439c7ff080c 100644 --- a/spec/frontend/repository/components/table/parent_row_spec.js +++ b/spec/frontend/repository/components/table/parent_row_spec.js @@ -1,10 +1,11 @@ import { shallowMount, RouterLinkStub } from '@vue/test-utils'; +import { GlLoadingIcon } from '@gitlab/ui'; import ParentRow from '~/repository/components/table/parent_row.vue'; let vm; let $router; -function factory(path) { +function factory(path, loadingPath) { $router = { push: jest.fn(), }; @@ -13,6 +14,7 @@ function factory(path) { propsData: { commitRef: 'master', path, + loadingPath, }, stubs: { RouterLink: RouterLinkStub, @@ -61,4 +63,10 @@ describe('Repository parent row component', () => { path: '/tree/master/app', }); }); + + it('renders loading icon when loading parent', () => { + factory('app/assets', 'app'); + + expect(vm.find(GlLoadingIcon).exists()).toBe(true); + }); }); diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js index 067bad0dab6..b60560366a6 100644 --- a/spec/frontend/repository/components/table/row_spec.js +++ b/spec/frontend/repository/components/table/row_spec.js @@ -1,5 +1,5 @@ import { shallowMount, RouterLinkStub } from '@vue/test-utils'; -import { GlBadge, GlLink } from '@gitlab/ui'; +import { GlBadge, GlLink, GlLoadingIcon } from '@gitlab/ui'; import { visitUrl } from '~/lib/utils/url_utility'; import TableRow from '~/repository/components/table/row.vue'; import Icon from '~/vue_shared/components/icon.vue'; @@ -198,4 +198,17 @@ describe('Repository table row component', () => { expect(vm.find(Icon).exists()).toBe(true); }); }); + + it('renders loading icon when path is loading', () => { + factory({ + id: '1', + sha: '1', + path: 'test', + type: 'tree', + currentPath: '/', + loadingPath: 'test', + }); + + expect(vm.find(GlLoadingIcon).exists()).toBe(true); + }); }); diff --git a/spec/helpers/markup_helper_spec.rb b/spec/helpers/markup_helper_spec.rb index 66d461a871c..f415fb05b5b 100644 --- a/spec/helpers/markup_helper_spec.rb +++ b/spec/helpers/markup_helper_spec.rb @@ -273,16 +273,19 @@ describe MarkupHelper do describe '#render_wiki_content' do let(:wiki) { double('WikiPage', path: "file.#{extension}") } + let(:wiki_repository) { double('Repository') } let(:context) do { pipeline: :wiki, project: project, project_wiki: wiki, - page_slug: 'nested/page', issuable_state_filter_enabled: true + page_slug: 'nested/page', issuable_state_filter_enabled: true, + repository: wiki_repository } end before do expect(wiki).to receive(:content).and_return('wiki content') expect(wiki).to receive(:slug).and_return('nested/page') + expect(wiki).to receive(:repository).and_return(wiki_repository) helper.instance_variable_set(:@project_wiki, wiki) end diff --git a/spec/lib/gitlab/app_text_logger_spec.rb b/spec/lib/gitlab/app_text_logger_spec.rb index 06d3e643608..c84b986ce40 100644 --- a/spec/lib/gitlab/app_text_logger_spec.rb +++ b/spec/lib/gitlab/app_text_logger_spec.rb @@ -15,4 +15,11 @@ describe Gitlab::AppTextLogger do it 'logs a string unchanged' do expect(subject.format_message('INFO', Time.now, nil, string_message)).to include(string_message) end + + it 'logs time in UTC with ISO8601.3 standard' do + Timecop.freeze do + expect(subject.format_message('INFO', Time.now, nil, string_message)) + .to include(Time.now.utc.iso8601(3)) + end + end end diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb index ba5b70b44de..c8d159d1e84 100644 --- a/spec/lib/gitlab/asciidoc_spec.rb +++ b/spec/lib/gitlab/asciidoc_spec.rb @@ -518,6 +518,28 @@ module Gitlab end end + context 'when repository is passed into the context' do + let(:wiki_repo) { project.wiki.repository } + let(:include_path) { 'wiki_file.adoc' } + + before do + project.create_wiki + context.merge!(repository: wiki_repo) + end + + context 'when the file exists' do + before do + create_file(include_path, 'Content from wiki', repository: wiki_repo) + end + + it { is_expected.to include('<p>Content from wiki</p>') } + end + + context 'when the file does not exist' do + it { is_expected.to include("[ERROR: include::#{include_path}[] - unresolved directive]")} + end + end + context 'recursive includes with relative paths' do let(:input) do <<~ADOC @@ -562,8 +584,8 @@ module Gitlab end end - def create_file(path, content) - project.repository.create_file(project.creator, path, content, + def create_file(path, content, repository: project.repository) + repository.create_file(project.creator, path, content, message: "Add #{path}", branch_name: 'asciidoc') end end diff --git a/spec/lib/sentry/api_urls_spec.rb b/spec/lib/sentry/api_urls_spec.rb new file mode 100644 index 00000000000..78455f8d51f --- /dev/null +++ b/spec/lib/sentry/api_urls_spec.rb @@ -0,0 +1,85 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Sentry::ApiUrls do + let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/' } + let(:token) { 'test-token' } + let(:issue_id) { '123456' } + let(:issue_id_with_reserved_chars) { '123$%' } + let(:escaped_issue_id) { '123%24%25' } + let(:api_urls) { Sentry::ApiUrls.new(sentry_url) } + + # Sentry API returns 404 if there are extra slashes in the URL! + shared_examples 'correct url with extra slashes' do + let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects//sentry-org/sentry-project/' } + + it_behaves_like 'correct url' + end + + shared_examples 'correctly escapes issue ID' do + context 'with param a string with reserved chars' do + let(:issue_id) { issue_id_with_reserved_chars } + + it { expect(subject.to_s).to include(escaped_issue_id) } + end + + context 'with param a symbol with reserved chars' do + let(:issue_id) { issue_id_with_reserved_chars.to_sym } + + it { expect(subject.to_s).to include(escaped_issue_id) } + end + + context 'with param an integer' do + let(:issue_id) { 12345678 } + + it { expect(subject.to_s).to include(issue_id.to_s) } + end + end + + describe '#issues_url' do + subject { api_urls.issues_url } + + shared_examples 'correct url' do + it { is_expected.to eq_uri('https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/issues/') } + end + + it_behaves_like 'correct url' + it_behaves_like 'correct url with extra slashes' + end + + describe '#issue_url' do + subject { api_urls.issue_url(issue_id) } + + shared_examples 'correct url' do + it { is_expected.to eq_uri("https://sentrytest.gitlab.com/api/0/issues/#{issue_id}/") } + end + + it_behaves_like 'correct url' + it_behaves_like 'correct url with extra slashes' + it_behaves_like 'correctly escapes issue ID' + end + + describe '#projects_url' do + subject { api_urls.projects_url } + + shared_examples 'correct url' do + it { is_expected.to eq_uri('https://sentrytest.gitlab.com/api/0/projects/') } + end + + it_behaves_like 'correct url' + it_behaves_like 'correct url with extra slashes' + end + + describe '#issue_latest_event_url' do + subject { api_urls.issue_latest_event_url(issue_id) } + + shared_examples 'correct url' do + it { is_expected.to eq_uri("https://sentrytest.gitlab.com/api/0/issues/#{issue_id}/events/latest/") } + end + + it_behaves_like 'correct url' + it_behaves_like 'correct url with extra slashes' + it_behaves_like 'correctly escapes issue ID' + end +end diff --git a/spec/lib/sentry/client/issue_spec.rb b/spec/lib/sentry/client/issue_spec.rb index e10d27e4342..3130bb38cc2 100644 --- a/spec/lib/sentry/client/issue_spec.rb +++ b/spec/lib/sentry/client/issue_spec.rb @@ -109,28 +109,6 @@ describe Sentry::Client::Issue do it_behaves_like 'no Sentry redirects' end - # Sentry API returns 404 if there are extra slashes in the URL! - context 'extra slashes in URL' do - let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0/projects//sentry-org/sentry-project/' } - - let(:sentry_request_url) do - 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/' \ - 'issues/?limit=20&query=is:unresolved' - end - - it 'removes extra slashes in api url' do - expect(client.url).to eq(sentry_url) - expect(Gitlab::HTTP).to receive(:get).with( - URI('https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/issues/'), - anything - ).and_call_original - - subject - - expect(sentry_api_request).to have_been_requested - end - end - context 'requests with sort parameter in sentry api' do let(:sentry_request_url) do 'https://sentrytest.gitlab.com/api/0/projects/sentry-org/sentry-project/' \ @@ -232,14 +210,6 @@ describe Sentry::Client::Issue do subject { client.issue_details(issue_id: issue_id) } - it 'escapes issue ID' do - allow(CGI).to receive(:escape).and_call_original - - subject - - expect(CGI).to have_received(:escape).with(issue_id.to_s) - end - context 'error object created from sentry response' do using RSpec::Parameterized::TableSyntax diff --git a/spec/lib/sentry/client/projects_spec.rb b/spec/lib/sentry/client/projects_spec.rb index 462f74eaac9..6183d4c5816 100644 --- a/spec/lib/sentry/client/projects_spec.rb +++ b/spec/lib/sentry/client/projects_spec.rb @@ -91,25 +91,6 @@ describe Sentry::Client::Projects do it_behaves_like 'no Sentry redirects' end - # Sentry API returns 404 if there are extra slashes in the URL! - context 'extra slashes in URL' do - let(:sentry_url) { 'https://sentrytest.gitlab.com/api//0/projects//' } - let!(:valid_req_stub) do - stub_sentry_request(sentry_list_projects_url) - end - - it 'removes extra slashes in api url' do - expect(Gitlab::HTTP).to receive(:get).with( - URI(sentry_list_projects_url), - anything - ).and_call_original - - subject - - expect(valid_req_stub).to have_been_requested - end - end - context 'when exception is raised' do let(:sentry_request_url) { sentry_list_projects_url } diff --git a/spec/models/concerns/atomic_internal_id_spec.rb b/spec/models/concerns/atomic_internal_id_spec.rb index 0605392c0aa..93bf7ec10dd 100644 --- a/spec/models/concerns/atomic_internal_id_spec.rb +++ b/spec/models/concerns/atomic_internal_id_spec.rb @@ -9,6 +9,32 @@ describe AtomicInternalId do let(:scope_attrs) { { project: milestone.project } } let(:usage) { :milestones } + describe '#save!' do + context 'when IID is provided' do + before do + milestone.iid = external_iid + end + + it 'tracks the value' do + expect(milestone).to receive(:track_project_iid!) + + milestone.save! + end + + context 'when importing' do + before do + milestone.importing = true + end + + it 'does not track the value' do + expect(milestone).not_to receive(:track_project_iid!) + + milestone.save! + end + end + end + end + describe '#track_project_iid!' do subject { milestone.track_project_iid! } diff --git a/spec/requests/api/issues/post_projects_issues_spec.rb b/spec/requests/api/issues/post_projects_issues_spec.rb index e9f678d164e..67404cf10df 100644 --- a/spec/requests/api/issues/post_projects_issues_spec.rb +++ b/spec/requests/api/issues/post_projects_issues_spec.rb @@ -160,6 +160,16 @@ describe API::Issues do expect(json_response['iid']).not_to eq 9001 end end + + context 'when an issue with the same IID exists on database' do + it 'returns 409' do + post api("/projects/#{project.id}/issues", admin), + params: { title: 'new issue', iid: issue.iid } + + expect(response).to have_gitlab_http_status(409) + expect(json_response['message']).to eq 'Duplicated issue' + end + end end it 'creates a new project issue' do diff --git a/spec/services/users/destroy_service_spec.rb b/spec/services/users/destroy_service_spec.rb index 23a0c71175e..d9335cef5cc 100644 --- a/spec/services/users/destroy_service_spec.rb +++ b/spec/services/users/destroy_service_spec.rb @@ -20,6 +20,22 @@ describe Users::DestroyService do expect { Namespace.find(namespace.id) }.to raise_error(ActiveRecord::RecordNotFound) end + it 'deletes user associations in batches' do + expect(user).to receive(:destroy_dependent_associations_in_batches) + + service.execute(user) + end + + context 'when :destroy_user_associations_in_batches flag is disabled' do + it 'does not delete user associations in batches' do + stub_feature_flags(destroy_user_associations_in_batches: false) + + expect(user).not_to receive(:destroy_dependent_associations_in_batches) + + service.execute(user) + end + end + it 'will delete the project' do expect_next_instance_of(Projects::DestroyService) do |destroy_service| expect(destroy_service).to receive(:execute).once.and_return(true) diff --git a/spec/support/matchers/eq_uri.rb b/spec/support/matchers/eq_uri.rb new file mode 100644 index 00000000000..47b657b3fe1 --- /dev/null +++ b/spec/support/matchers/eq_uri.rb @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +# Assert the result matches a URI object initialized with the expectation variable. +# +# Success: +# ``` +# expect(URI('www.fish.com')).to eq_uri('www.fish.com') +# ``` +# +# Failure: +# ``` +# expect(URI('www.fish.com')).to eq_uri('www.dog.com') +# ``` +# +RSpec::Matchers.define :eq_uri do |expected| + match do |actual| + actual == URI(expected) + end +end |