diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-14 21:09:03 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-14 21:09:03 +0000 |
commit | f9cda7671cfb07795d9ea01a7117f7d6c6511d0d (patch) | |
tree | 71233af70149f655249c475e764a8c2cd560b096 /spec | |
parent | 18ffa5e88194d8f3fd63bee0221de5bc1fbdfe94 (diff) | |
download | gitlab-ce-f9cda7671cfb07795d9ea01a7117f7d6c6511d0d.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/frontend/issuables_list/components/issuable_spec.js | 34 | ||||
-rw-r--r-- | spec/lib/gitlab/config_checker/external_database_checker_spec.rb | 53 | ||||
-rw-r--r-- | spec/lib/gitlab/database_spec.rb | 36 | ||||
-rw-r--r-- | spec/models/snippet_input_action_spec.rb | 4 | ||||
-rw-r--r-- | spec/services/snippets/create_service_spec.rb | 33 | ||||
-rw-r--r-- | spec/services/snippets/update_service_spec.rb | 14 |
6 files changed, 100 insertions, 74 deletions
diff --git a/spec/frontend/issuables_list/components/issuable_spec.js b/spec/frontend/issuables_list/components/issuable_spec.js index 2af06f59a0f..78a38506059 100644 --- a/spec/frontend/issuables_list/components/issuable_spec.js +++ b/spec/frontend/issuables_list/components/issuable_spec.js @@ -1,5 +1,5 @@ import { shallowMount } from '@vue/test-utils'; -import { GlSprintf, GlLabel } from '@gitlab/ui'; +import { GlSprintf, GlLabel, GlIcon } from '@gitlab/ui'; import { TEST_HOST } from 'helpers/test_constants'; import { trimText } from 'helpers/text_helper'; import initUserPopovers from '~/user_popovers'; @@ -75,7 +75,9 @@ describe('Issuable component', () => { window.Date = DateOrig; }); - const findConfidentialIcon = () => wrapper.find('.fa-eye-slash'); + const checkExists = findFn => () => findFn().exists(); + const hasConfidentialIcon = () => + wrapper.findAll(GlIcon).wrappers.some(iconWrapper => iconWrapper.props('name') === 'eye-slash'); const findTaskStatus = () => wrapper.find('.task-status'); const findOpenedAgoContainer = () => wrapper.find('[data-testid="openedByMessage"]'); const findMilestone = () => wrapper.find('.js-milestone'); @@ -169,19 +171,19 @@ describe('Issuable component', () => { }); it.each` - desc | finder - ${'bulk editing checkbox'} | ${findBulkCheckbox} - ${'confidential icon'} | ${findConfidentialIcon} - ${'task status'} | ${findTaskStatus} - ${'milestone'} | ${findMilestone} - ${'due date'} | ${findDueDate} - ${'labels'} | ${findLabels} - ${'weight'} | ${findWeight} - ${'merge request count'} | ${findMergeRequestsCount} - ${'upvotes'} | ${findUpvotes} - ${'downvotes'} | ${findDownvotes} - `('does not render $desc', ({ finder }) => { - expect(finder().exists()).toBe(false); + desc | check + ${'bulk editing checkbox'} | ${checkExists(findBulkCheckbox)} + ${'confidential icon'} | ${hasConfidentialIcon} + ${'task status'} | ${checkExists(findTaskStatus)} + ${'milestone'} | ${checkExists(findMilestone)} + ${'due date'} | ${checkExists(findDueDate)} + ${'labels'} | ${checkExists(findLabels)} + ${'weight'} | ${checkExists(findWeight)} + ${'merge request count'} | ${checkExists(findMergeRequestsCount)} + ${'upvotes'} | ${checkExists(findUpvotes)} + ${'downvotes'} | ${checkExists(findDownvotes)} + `('does not render $desc', ({ check }) => { + expect(check()).toBe(false); }); it('show relative reference path', () => { @@ -215,7 +217,7 @@ describe('Issuable component', () => { }); it('renders the confidential icon', () => { - expect(findConfidentialIcon().exists()).toBe(true); + expect(hasConfidentialIcon()).toBe(true); }); }); diff --git a/spec/lib/gitlab/config_checker/external_database_checker_spec.rb b/spec/lib/gitlab/config_checker/external_database_checker_spec.rb index c651868bd1e..316696bc584 100644 --- a/spec/lib/gitlab/config_checker/external_database_checker_spec.rb +++ b/spec/lib/gitlab/config_checker/external_database_checker_spec.rb @@ -6,51 +6,54 @@ RSpec.describe Gitlab::ConfigChecker::ExternalDatabaseChecker do describe '#check' do subject { described_class.check } - context 'database version is not deprecated' do + let_it_be(:deprecation_warning) { "Please upgrade" } + let_it_be(:upcoming_deprecation_warning) { "Please consider upgrading" } + + context 'when database meets minimum version and there is no upcoming deprecation' do before do - allow(described_class).to receive(:db_version_deprecated?).and_return(false) + allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true) + allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false) end it { is_expected.to be_empty } end - context 'database version is deprecated' do + context 'when database does not meet minimum version and there is no upcoming deprecation' do before do - allow(described_class).to receive(:db_version_deprecated?).and_return(true) - end - - let(:notice_deprecated_database) do - { - type: 'warning', - message: _('Note that PostgreSQL 11 will become the minimum required PostgreSQL version in GitLab 13.0 (May 2020). '\ - 'PostgreSQL 9.6 and PostgreSQL 10 will no longer be supported in GitLab 13.0. '\ - 'Please consider upgrading your PostgreSQL version (%{db_version}) soon.') % { db_version: Gitlab::Database.version.to_s } - } + allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false) + allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(false) end - it 'reports deprecated database notices' do - is_expected.to contain_exactly(notice_deprecated_database) + it 'only returns notice about deprecated database version' do + is_expected.to include(a_hash_including(message: include(deprecation_warning))) + is_expected.not_to include(a_hash_including(message: include(upcoming_deprecation_warning))) end end - end - describe '#db_version_deprecated' do - subject { described_class.db_version_deprecated? } - - context 'database version is not deprecated' do + context 'when database meets minimum version and there is an upcoming deprecation' do before do - allow(Gitlab::Database).to receive(:version).and_return(11) + allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(true) + allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true) end - it { is_expected.to be false } + it 'only returns notice about an upcoming deprecation' do + is_expected.to include(a_hash_including(message: include(upcoming_deprecation_warning))) + is_expected.not_to include(a_hash_including(message: include(deprecation_warning))) + end end - context 'database version is deprecated' do + context 'when database does not meet minimum version and there is an upcoming deprecation' do before do - allow(Gitlab::Database).to receive(:version).and_return(10) + allow(Gitlab::Database).to receive(:postgresql_minimum_supported_version?).and_return(false) + allow(Gitlab::Database).to receive(:postgresql_upcoming_deprecation?).and_return(true) end - it { is_expected.to be true } + it 'returns notice about deprecated database version and an upcoming deprecation' do + is_expected.to include( + a_hash_including(message: include(deprecation_warning)), + a_hash_including(message: include(upcoming_deprecation_warning)) + ) + end end end end diff --git a/spec/lib/gitlab/database_spec.rb b/spec/lib/gitlab/database_spec.rb index c9e87b46ac9..cd009f955af 100644 --- a/spec/lib/gitlab/database_spec.rb +++ b/spec/lib/gitlab/database_spec.rb @@ -90,28 +90,42 @@ RSpec.describe Gitlab::Database do end describe '.postgresql_minimum_supported_version?' do - it 'returns false when using PostgreSQL 9.5' do - allow(described_class).to receive(:version).and_return('9.5') + it 'returns false when using PostgreSQL 10' do + allow(described_class).to receive(:version).and_return('10') expect(described_class.postgresql_minimum_supported_version?).to eq(false) end - it 'returns false when using PostgreSQL 9.6' do - allow(described_class).to receive(:version).and_return('9.6') + it 'returns true when using PostgreSQL 11' do + allow(described_class).to receive(:version).and_return('11') - expect(described_class.postgresql_minimum_supported_version?).to eq(false) + expect(described_class.postgresql_minimum_supported_version?).to eq(true) end - it 'returns false when using PostgreSQL 10' do - allow(described_class).to receive(:version).and_return('10') + it 'returns true when using PostgreSQL 12' do + allow(described_class).to receive(:version).and_return('12') - expect(described_class.postgresql_minimum_supported_version?).to eq(false) + expect(described_class.postgresql_minimum_supported_version?).to eq(true) end + end - it 'returns true when using PostgreSQL 11 or newer' do - allow(described_class).to receive(:version).and_return('11.0') + describe '.postgresql_upcoming_deprecation?' do + it 'returns true when database version is lower than the upcoming minimum' do + allow(described_class).to receive(:version).and_return('11') - expect(described_class.postgresql_minimum_supported_version?).to eq(true) + expect(described_class.postgresql_upcoming_deprecation?).to eq(true) + end + + it 'returns false when database version equals the upcoming minimum' do + allow(described_class).to receive(:version).and_return('12') + + expect(described_class.postgresql_upcoming_deprecation?).to eq(false) + end + + it 'returns false when database version is greater the upcoming minimum' do + allow(described_class).to receive(:version).and_return('13') + + expect(described_class.postgresql_upcoming_deprecation?).to eq(false) end end diff --git a/spec/models/snippet_input_action_spec.rb b/spec/models/snippet_input_action_spec.rb index 43c2919735b..ca61b80df4c 100644 --- a/spec/models/snippet_input_action_spec.rb +++ b/spec/models/snippet_input_action_spec.rb @@ -29,8 +29,8 @@ RSpec.describe SnippetInputAction do :move | 'foobar' | '' | 'foo1' | nil | true | nil :create | 'foobar' | nil | 'foobar' | nil | false | :content :create | 'foobar' | '' | 'foobar' | nil | false | :content - :create | nil | 'foobar' | 'foobar' | nil | false | :file_path - :create | '' | 'foobar' | 'foobar' | nil | false | :file_path + :create | nil | 'foobar' | 'foobar' | nil | true | nil + :create | '' | 'foobar' | 'foobar' | nil | true | nil :update | 'foobar' | nil | 'foobar' | nil | false | :content :update | 'foobar' | '' | 'foobar' | nil | false | :content :update | 'other' | 'foobar' | 'foobar' | nil | false | :file_path diff --git a/spec/services/snippets/create_service_spec.rb b/spec/services/snippets/create_service_spec.rb index f8e69b4b4bb..d0b2dde6ee4 100644 --- a/spec/services/snippets/create_service_spec.rb +++ b/spec/services/snippets/create_service_spec.rb @@ -177,10 +177,8 @@ RSpec.describe Snippets::CreateService do end it 'returns a generic error' do - response = subject - - expect(response).to be_error - expect(response.payload[:snippet].errors[:repository]).to eq ['Error creating the snippet'] + expect(subject).to be_error + expect(snippet.errors[:repository]).to eq ['Error creating the snippet'] end end @@ -250,7 +248,7 @@ RSpec.describe Snippets::CreateService do end it 'commit the files to the repository' do - subject + expect(subject).to be_success blob = snippet.repository.blob_at('master', file_path) @@ -261,10 +259,7 @@ RSpec.describe Snippets::CreateService do let(:extra_opts) { { content: 'foo', file_name: 'path' } } it 'a validation error is raised' do - response = subject - snippet = response.payload[:snippet] - - expect(response).to be_error + expect(subject).to be_error expect(snippet.errors.full_messages_for(:content)).to eq ['Content and snippet files cannot be used together'] expect(snippet.errors.full_messages_for(:file_name)).to eq ['File name and snippet files cannot be used together'] expect(snippet.repository.exists?).to be_falsey @@ -275,10 +270,7 @@ RSpec.describe Snippets::CreateService do let(:snippet_files) { [{ action: 'invalid_action', file_path: 'snippet_file_path.rb', content: 'snippet_content' }] } it 'a validation error is raised' do - response = subject - snippet = response.payload[:snippet] - - expect(response).to be_error + expect(subject).to be_error expect(snippet.errors.full_messages_for(:snippet_files)).to eq ['Snippet files have invalid data'] expect(snippet.repository.exists?).to be_falsey end @@ -288,14 +280,21 @@ RSpec.describe Snippets::CreateService do let(:snippet_files) { [{ action: 'delete', file_path: 'snippet_file_path.rb' }] } it 'a validation error is raised' do - response = subject - snippet = response.payload[:snippet] - - expect(response).to be_error + expect(subject).to be_error expect(snippet.errors.full_messages_for(:snippet_files)).to eq ['Snippet files have invalid data'] expect(snippet.repository.exists?).to be_falsey end end + + context 'when "create" operation does not have file_path or is empty' do + let(:snippet_files) { [{ action: 'create', content: content }, { action: 'create', content: content, file_path: '' }] } + + it 'generates the file path for the files' do + expect(subject).to be_success + expect(snippet.repository.blob_at('master', 'snippetfile1.txt').data).to eq content + expect(snippet.repository.blob_at('master', 'snippetfile2.txt').data).to eq content + end + end end context 'when ProjectSnippet' do diff --git a/spec/services/snippets/update_service_spec.rb b/spec/services/snippets/update_service_spec.rb index b16c4d64af3..5587668e9ed 100644 --- a/spec/services/snippets/update_service_spec.rb +++ b/spec/services/snippets/update_service_spec.rb @@ -537,10 +537,18 @@ RSpec.describe Snippets::UpdateService do it_behaves_like 'returns an error', 'Snippet files have invalid data' end - context 'when file_path is not present' do - let(:snippet_files) { [{ action: :create, content: content }] } + context 'when file_path is not present or empty' do + let(:snippet_files) { [{ action: :create, content: content }, { action: :create, file_path: '', content: content }] } - it_behaves_like 'returns an error', 'Snippet files have invalid data' + it 'generates the file path for the files' do + expect(blob('snippetfile1.txt')).to be_nil + expect(blob('snippetfile2.txt')).to be_nil + + expect(subject).to be_success + + expect(blob('snippetfile1.txt').data).to eq content + expect(blob('snippetfile2.txt').data).to eq content + end end context 'when file_path already exists in the repository' do |