diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 18:09:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-03-23 18:09:36 +0300 |
commit | 074d013e1eb3f6e0c27f96a3be8b9361254c8a98 (patch) | |
tree | f185c474ddc8624a4793c84b0b1f4cc07349694b /spec | |
parent | 8f9beefac3774b30e911fb00a68f4c7a5244cf27 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
16 files changed, 259 insertions, 141 deletions
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 e67982bbd31..67996cc3e5d 100644 --- a/spec/features/projects/wiki/user_creates_wiki_page_spec.rb +++ b/spec/features/projects/wiki/user_creates_wiki_page_spec.rb @@ -312,7 +312,6 @@ describe "User creates wiki page" do visit(project_wikis_path(project)) expect(page).to have_content('another') - expect(page).to have_content('More Pages') end context 'when there is a customized sidebar' do @@ -324,10 +323,23 @@ describe "User creates wiki page" do visit(project_wikis_path(project)) expect(page).to have_content('My customized sidebar') - expect(page).to have_content('More Pages') expect(page).not_to have_content('Another') end end end + + context 'when there are more than 15 existing pages' do + before do + create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: 'home' }) + (1..14).each { |i| create(:wiki_page, wiki: wiki, attrs: { title: "page-#{i}", content: "page #{i}" }) } + end + + it 'renders a default sidebar when there is no customized sidebar' do + visit(project_wikis_path(project)) + + expect(page).to have_content('View All Pages') + expect(page).to have_content('page 1') + end + end end end diff --git a/spec/frontend/helpers/dom_shims/element_scroll_by.js b/spec/frontend/helpers/dom_shims/element_scroll_by.js new file mode 100644 index 00000000000..7d91279e4aa --- /dev/null +++ b/spec/frontend/helpers/dom_shims/element_scroll_by.js @@ -0,0 +1 @@ +Element.prototype.scrollBy = jest.fn(); diff --git a/spec/frontend/helpers/dom_shims/index.js b/spec/frontend/helpers/dom_shims/index.js index bcd5da0ce48..17a2090d2f1 100644 --- a/spec/frontend/helpers/dom_shims/index.js +++ b/spec/frontend/helpers/dom_shims/index.js @@ -1,4 +1,5 @@ import './element_scroll_into_view'; +import './element_scroll_by'; import './form_element'; import './get_client_rects'; import './inner_text'; diff --git a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap index 2d411fcce79..5b5c9fd714e 100644 --- a/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap +++ b/spec/frontend/repository/components/table/__snapshots__/row_spec.js.snap @@ -2,25 +2,28 @@ exports[`Repository table row component renders table row 1`] = ` <tr - class="tree-item file_1" + class="tree-item" > <td - class="tree-item-file-name" + class="tree-item-file-name cursor-default position-relative" > - <i - aria-label="file" - class="fa fa-fw fa-file-text-o" - role="img" - /> + <!----> <a - class="str-truncated" + class="tree-item-link str-truncated" data-qa-selector="file_name_link" href="https://test.com" > - - test - + <i + aria-label="file" + class="fa fa-fw mr-1 fa-file-text-o" + role="img" + /> + <span + class="position-relative" + > + test + </span> </a> <!----> @@ -31,7 +34,7 @@ exports[`Repository table row component renders table row 1`] = ` </td> <td - class="d-none d-sm-table-cell tree-commit" + class="d-none d-sm-table-cell tree-commit cursor-default" > <gl-skeleton-loading-stub class="h-auto" @@ -40,7 +43,7 @@ exports[`Repository table row component renders table row 1`] = ` </td> <td - class="tree-time-ago text-right" + class="tree-time-ago text-right cursor-default" > <gl-skeleton-loading-stub class="ml-auto h-auto w-50" @@ -52,25 +55,28 @@ exports[`Repository table row component renders table row 1`] = ` exports[`Repository table row component renders table row for path with special character 1`] = ` <tr - class="tree-item file_1" + class="tree-item" > <td - class="tree-item-file-name" + class="tree-item-file-name cursor-default position-relative" > - <i - aria-label="file" - class="fa fa-fw fa-file-text-o" - role="img" - /> + <!----> <a - class="str-truncated" + class="tree-item-link str-truncated" data-qa-selector="file_name_link" href="https://test.com" > - - test - + <i + aria-label="file" + class="fa fa-fw mr-1 fa-file-text-o" + role="img" + /> + <span + class="position-relative" + > + test + </span> </a> <!----> @@ -81,7 +87,7 @@ exports[`Repository table row component renders table row for path with special </td> <td - class="d-none d-sm-table-cell tree-commit" + class="d-none d-sm-table-cell tree-commit cursor-default" > <gl-skeleton-loading-stub class="h-auto" @@ -90,7 +96,7 @@ exports[`Repository table row component renders table row for path with special </td> <td - class="tree-time-ago text-right" + class="tree-time-ago text-right cursor-default" > <gl-skeleton-loading-stub class="ml-auto h-auto w-50" diff --git a/spec/frontend/repository/components/table/row_spec.js b/spec/frontend/repository/components/table/row_spec.js index 22aacdc735c..7bb7ad6e5dd 100644 --- a/spec/frontend/repository/components/table/row_spec.js +++ b/spec/frontend/repository/components/table/row_spec.js @@ -1,14 +1,8 @@ import { shallowMount, RouterLinkStub } from '@vue/test-utils'; 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'; -jest.mock('~/lib/utils/url_utility', () => ({ - ...jest.requireActual('~/lib/utils/url_utility'), - visitUrl: jest.fn(), -})); - let vm; let $router; @@ -88,31 +82,6 @@ describe('Repository table row component', () => { }); it.each` - type | pushes - ${'tree'} | ${true} - ${'file'} | ${false} - ${'commit'} | ${false} - `('pushes new router if type $type is tree', ({ type, pushes }) => { - factory({ - id: '1', - sha: '123', - path: 'test', - type, - currentPath: '/', - }); - - return vm.vm.$nextTick().then(() => { - vm.trigger('click'); - - if (pushes) { - expect($router.push).toHaveBeenCalledWith({ path: '/-/tree/master/test' }); - } else { - expect($router.push).not.toHaveBeenCalled(); - } - }); - }); - - it.each` path ${'test#'} ${'Ă„nderungen'} @@ -132,7 +101,7 @@ describe('Repository table row component', () => { }); }); - it('pushes new route for directory with hash', () => { + it('renders link for directory with hash', () => { factory({ id: '1', sha: '123', @@ -142,36 +111,7 @@ describe('Repository table row component', () => { }); return vm.vm.$nextTick().then(() => { - vm.trigger('click'); - - expect($router.push).toHaveBeenCalledWith({ path: '/-/tree/master/test%23' }); - }); - }); - - it.each` - type | pushes - ${'tree'} | ${true} - ${'file'} | ${false} - ${'commit'} | ${false} - `('calls visitUrl if $type is not tree', ({ type, pushes }) => { - factory({ - id: '1', - sha: '123', - path: 'test', - type, - currentPath: '/', - }); - - return vm.vm.$nextTick().then(() => { - vm.trigger('click'); - - if (pushes) { - expect(visitUrl).not.toHaveBeenCalled(); - } else { - const [url, external] = visitUrl.mock.calls[0]; - expect(url).toBe('https://test.com'); - expect(external).toBeFalsy(); - } + expect(vm.find('.tree-item-link').props('to')).toEqual({ path: '/-/tree/master/test%23' }); }); }); diff --git a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb index 4490b54d1f7..8b2e33cdfda 100644 --- a/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb +++ b/spec/graphql/resolvers/error_tracking/sentry_detailed_error_resolver_spec.rb @@ -18,6 +18,16 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do .and_return issue_details_service end + shared_examples 'it resolves to nil' do + it 'resolves to nil' do + allow(issue_details_service).to receive(:execute) + .and_return(issue: nil) + + result = resolve_error(args) + expect(result).to be_nil + end + end + describe '#resolve' do let(:args) { { id: issue_global_id(1234) } } @@ -32,7 +42,7 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do before do allow(issue_details_service).to receive(:execute) - .and_return({ issue: detailed_error }) + .and_return(issue: detailed_error) end it 'resolves to a detailed error' do @@ -44,12 +54,14 @@ describe Resolvers::ErrorTracking::SentryDetailedErrorResolver do end end - it 'resolves to nil if no match' do - allow(issue_details_service).to receive(:execute) - .and_return({ issue: nil }) + context 'if id does not match issue' do + it_behaves_like 'it resolves to nil' + end - result = resolve_error(args) - expect(result).to eq nil + context 'blank id' do + let(:args) { { id: '' } } + + it_behaves_like 'it resolves to nil' end end diff --git a/spec/lib/gitlab/danger/changelog_spec.rb b/spec/lib/gitlab/danger/changelog_spec.rb index 64f87ec8cd3..c61e47f80d9 100644 --- a/spec/lib/gitlab/danger/changelog_spec.rb +++ b/spec/lib/gitlab/danger/changelog_spec.rb @@ -76,10 +76,10 @@ describe Gitlab::Danger::Changelog do context 'added files contain a changelog' do [ - 'changelogs/unreleased/entry.md', - 'ee/changelogs/unreleased/entry.md', - 'changelogs/unreleased-ee/entry.md', - 'ee/changelogs/unreleased-ee/entry.md' + 'changelogs/unreleased/entry.yml', + 'ee/changelogs/unreleased/entry.yml', + 'changelogs/unreleased-ee/entry.yml', + 'ee/changelogs/unreleased-ee/entry.yml' ].each do |file_path| let(:added_files) { [file_path] } @@ -107,46 +107,22 @@ describe Gitlab::Danger::Changelog do end describe '#ee_changelog?' do - context 'is ee changelog' do - [ - 'changelogs/unreleased-ee/entry.md', - 'ee/changelogs/unreleased-ee/entry.md' - ].each do |file_path| - subject { changelog.ee_changelog?(file_path) } + subject { changelog.ee_changelog? } - it { is_expected.to be_truthy } - end + before do + allow(changelog).to receive(:found).and_return(file_path) end - context 'is not ee changelog' do - [ - 'changelogs/unreleased/entry.md', - 'ee/changelogs/unreleased/entry.md' - ].each do |file_path| - subject { changelog.ee_changelog?(file_path) } - - it { is_expected.to be_falsy } - end - end - end + context 'is ee changelog' do + let(:file_path) { 'ee/changelogs/unreleased/entry.yml' } - describe '#ce_port_changelog?' do - where(:helper_ee?, :file_path, :expected) do - true | 'changelogs/unreleased-ee/entry.md' | false - true | 'ee/changelogs/unreleased-ee/entry.md' | false - false | 'changelogs/unreleased-ee/entry.md' | false - false | 'ee/changelogs/unreleased-ee/entry.md' | false - true | 'changelogs/unreleased/entry.md' | true - true | 'ee/changelogs/unreleased/entry.md' | true - false | 'changelogs/unreleased/entry.md' | false - false | 'ee/changelogs/unreleased/entry.md' | false + it { is_expected.to be_truthy } end - with_them do - let(:ee?) { helper_ee? } - subject { changelog.ce_port_changelog?(file_path) } + context 'is not ee changelog' do + let(:file_path) { 'changelogs/unreleased/entry.yml' } - it { is_expected.to eq(expected) } + it { is_expected.to be_falsy } end end end diff --git a/spec/lib/gitlab/danger/helper_spec.rb b/spec/lib/gitlab/danger/helper_spec.rb index 4cb957f378c..d5d582d7d6c 100644 --- a/spec/lib/gitlab/danger/helper_spec.rb +++ b/spec/lib/gitlab/danger/helper_spec.rb @@ -76,6 +76,16 @@ describe Gitlab::Danger::Helper do end end + describe '#all_ee_changes' do + subject { helper.all_ee_changes } + + it 'returns all changed files starting with ee/' do + expect(helper).to receive(:all_changed_files).and_return(%w[fr/ee/beer.rb ee/wine.rb ee/lib/ido.rb ee.k]) + + is_expected.to match_array(%w[ee/wine.rb ee/lib/ido.rb]) + end + end + describe '#ee?' do subject { helper.ee? } diff --git a/spec/lib/gitlab/file_detector_spec.rb b/spec/lib/gitlab/file_detector_spec.rb index 3972bd24e80..5bf70ef898a 100644 --- a/spec/lib/gitlab/file_detector_spec.rb +++ b/spec/lib/gitlab/file_detector_spec.rb @@ -96,14 +96,25 @@ describe Gitlab::FileDetector do 'swagger.yml', 'swagger.yaml', 'swagger.json', 'gitlab_swagger.yml', 'openapi_gitlab.yml', 'OpenAPI.YML', 'openapi.Yaml', 'openapi.JSON', - 'openapi.gitlab.yml', 'gitlab.openapi.yml' + 'openapi.gitlab.yml', 'gitlab.openapi.yml', + 'attention/openapi.yml', 'attention/swagger.yml', + 'attention/gitlab_swagger.yml', 'attention/openapi_gitlab.yml', + 'openapi/openapi.yml', 'openapi/swagger.yml', + 'openapi/my_openapi.yml', 'openapi/swagger_one.yml' ] openapi_types.each do |type_name| expect(described_class.type_of(type_name)).to eq(:openapi) end - expect(described_class.type_of('openapiyml')).to be_nil + openapi_bad_types = [ + 'openapiyml', + 'openapi/attention.yaml', 'swagger/attention.yaml' + ] + + openapi_bad_types.each do |type_name| + expect(described_class.type_of(type_name)).to be_nil + end end end end diff --git a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb index c0d71bfe5d0..387baf1ee53 100644 --- a/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb +++ b/spec/lib/gitlab/metrics/dashboard/service_selector_spec.rb @@ -15,7 +15,7 @@ describe Gitlab::Metrics::Dashboard::ServiceSelector do context 'when just the dashboard path is provided' do let(:arguments) { { dashboard_path: '.gitlab/dashboards/test.yml' } } - it { is_expected.to be Metrics::Dashboard::ProjectDashboardService } + it { is_expected.to be Metrics::Dashboard::CustomDashboardService } context 'when the path is for the system dashboard' do let(:arguments) { { dashboard_path: system_dashboard_path } } diff --git a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb index 058e0737a25..e11613b202d 100644 --- a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb +++ b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs/duplicate_job_spec.rb @@ -129,7 +129,8 @@ describe Gitlab::SidekiqMiddleware::DuplicateJobs::DuplicateJob, :clean_gitlab_r before do allow(AuthorizedProjectsWorker).to receive(:idempotent?).and_return(idempotent) allow(duplicate_job).to receive(:duplicate?).and_return(duplicate) - stub_feature_flags(drop_duplicate_sidekiq_jobs: feature_enabled) + allow(Gitlab::SidekiqMiddleware::DuplicateJobs) + .to receive(:drop_duplicates?).with(queue).and_return(feature_enabled) end it 'is droppable when all conditions are met' do diff --git a/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs_spec.rb b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs_spec.rb new file mode 100644 index 00000000000..fa5938f470b --- /dev/null +++ b/spec/lib/gitlab/sidekiq_middleware/duplicate_jobs_spec.rb @@ -0,0 +1,31 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe Gitlab::SidekiqMiddleware::DuplicateJobs do + using RSpec::Parameterized::TableSyntax + + describe '.drop_duplicates?' do + where(:global_feature_enabled, :selected_queue_enabled, :queue, :expected) do + true | true | described_class::DROPPABLE_QUEUES.first | true + true | true | "other_queue" | true + true | false | described_class::DROPPABLE_QUEUES.first | true + true | false | "other_queue" | true + false | true | described_class::DROPPABLE_QUEUES.first | true + false | true | "other_queue" | false + false | false | described_class::DROPPABLE_QUEUES.first | false + false | false | "other_queue" | false + end + + with_them do + before do + stub_feature_flags(drop_duplicate_sidekiq_jobs: global_feature_enabled, + drop_duplicate_sidekiq_jobs_for_queue: selected_queue_enabled) + end + + it "allows dropping jobs when expected" do + expect(described_class.drop_duplicates?(queue)).to be(expected) + end + end + end +end diff --git a/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb new file mode 100644 index 00000000000..87dd2f14b31 --- /dev/null +++ b/spec/rubocop/cop/gitlab/duplicate_spec_location_spec.rb @@ -0,0 +1,105 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' +require 'rubocop' +require 'rubocop/rspec/support' + +require_relative '../../../../rubocop/cop/gitlab/duplicate_spec_location' + +describe RuboCop::Cop::Gitlab::DuplicateSpecLocation do + include RuboCop::RSpec::ExpectOffense + include CopHelper + + subject(:cop) { described_class.new } + + let(:rails_root) { '../../../../' } + + def full_path(path) + File.expand_path(File.join(rails_root, path), __dir__) + end + + context 'Non-EE spec file' do + it 'registers no offenses' do + expect_no_offenses(<<~SOURCE.strip_indent, full_path('spec/foo_spec.rb')) + describe 'Foo' do + end + SOURCE + end + end + + context 'Non-EE application file' do + it 'registers no offenses' do + expect_no_offenses(<<~SOURCE.strip_indent, full_path('app/models/blog_post.rb')) + class BlogPost + end + SOURCE + end + end + + context 'EE application file' do + it 'registers no offenses' do + expect_no_offenses(<<~SOURCE.strip_indent, full_path('ee/app/models/blog_post.rb')) + class BlogPost + end + SOURCE + end + end + + context 'EE spec file for EE only code' do + let(:spec_file_path) { full_path('ee/spec/controllers/foo_spec.rb') } + + it 'registers no offenses' do + expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path) + describe 'Foo' do + end + SOURCE + end + + context 'there is a duplicate file' do + before do + allow(File).to receive(:exist?).and_call_original + + allow(File).to receive(:exist?) + .with(full_path('ee/spec/controllers/ee/foo_spec.rb')) + .and_return(true) + end + + it 'marks the describe as offending' do + expect_offense(<<~SOURCE.strip_indent, spec_file_path) + describe 'Foo' do + ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/ee/foo_spec.rb`. + end + SOURCE + end + end + end + + context 'EE spec file for EE extension' do + let(:spec_file_path) { full_path('ee/spec/controllers/ee/foo_spec.rb') } + + it 'registers no offenses' do + expect_no_offenses(<<~SOURCE.strip_indent, spec_file_path) + describe 'Foo' do + end + SOURCE + end + + context 'there is a duplicate file' do + before do + allow(File).to receive(:exist?).and_call_original + + allow(File).to receive(:exist?) + .with(full_path('ee/spec/controllers/foo_spec.rb')) + .and_return(true) + end + + it 'marks the describe as offending' do + expect_offense(<<~SOURCE.strip_indent, spec_file_path) + describe 'Foo' do + ^^^^^^^^^^^^^^ Duplicate spec location in `ee/spec/controllers/foo_spec.rb`. + end + SOURCE + end + end + end +end diff --git a/spec/services/issuable/clone/attributes_rewriter_spec.rb b/spec/services/issuable/clone/attributes_rewriter_spec.rb index 6bc0df8260b..9111b19d7b7 100644 --- a/spec/services/issuable/clone/attributes_rewriter_spec.rb +++ b/spec/services/issuable/clone/attributes_rewriter_spec.rb @@ -112,9 +112,6 @@ describe Issuable::Clone::AttributesRewriter do expect(event.milestone_id).to eq(expected_attrs[:milestone].id) expect(event.action).to eq(expected_attrs[:action]) expect(event.state).to eq(expected_attrs[:state]) - - expect(event.reference).to be_nil - expect(event.reference_html).to be_nil end end end diff --git a/spec/services/metrics/dashboard/project_dashboard_service_spec.rb b/spec/services/metrics/dashboard/custom_dashboard_service_spec.rb index 829e750d438..9458df3dca0 100644 --- a/spec/services/metrics/dashboard/project_dashboard_service_spec.rb +++ b/spec/services/metrics/dashboard/custom_dashboard_service_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -describe Metrics::Dashboard::ProjectDashboardService, :use_clean_rails_memory_store_caching do +describe Metrics::Dashboard::CustomDashboardService, :use_clean_rails_memory_store_caching do include MetricsDashboardHelpers let_it_be(:user) { create(:user) } diff --git a/spec/workers/namespaces/root_statistics_worker_spec.rb b/spec/workers/namespaces/root_statistics_worker_spec.rb index 45e75c9b0da..910a5b23e17 100644 --- a/spec/workers/namespaces/root_statistics_worker_spec.rb +++ b/spec/workers/namespaces/root_statistics_worker_spec.rb @@ -74,4 +74,19 @@ describe Namespaces::RootStatisticsWorker, '#perform' do worker.perform(group.id) end end + + it_behaves_like 'an idempotent worker' do + let(:job_args) { [group.id] } + + it 'deletes one aggregation schedule' do + # Make sure the group and it's aggregation schedule are created before + # counting + group + + expect { worker.perform(*job_args) } + .to change { Namespace::AggregationSchedule.count }.by(-1) + expect { worker.perform(*job_args) } + .not_to change { Namespace::AggregationSchedule.count } + end + end end |