Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/controllers/projects/issues_controller_spec.rb20
-rw-r--r--spec/features/projects/files/user_uploads_files_spec.rb25
-rw-r--r--spec/finders/group_members_finder_spec.rb10
-rw-r--r--spec/frontend/diffs/components/commit_item_spec.js25
-rw-r--r--spec/lib/api/helpers/custom_validators_spec.rb193
-rw-r--r--spec/lib/api/validations/validators/absence_spec.rb23
-rw-r--r--spec/lib/api/validations/validators/array_none_any_spec.rb28
-rw-r--r--spec/lib/api/validations/validators/file_path_spec.rb36
-rw-r--r--spec/lib/api/validations/validators/git_ref_spec.rb46
-rw-r--r--spec/lib/api/validations/validators/git_sha_spec.rb37
-rw-r--r--spec/lib/api/validations/validators/integer_none_any_spec.rb28
-rw-r--r--spec/lib/banzai/filter/autolink_filter_spec.rb5
-rw-r--r--spec/lib/gitlab/git/blob_spec.rb42
-rw-r--r--spec/models/ability_spec.rb6
-rw-r--r--spec/models/ci/build_spec.rb2
-rw-r--r--spec/requests/api/deploy_tokens_spec.rb30
-rw-r--r--spec/serializers/diffs_entity_spec.rb42
-rw-r--r--spec/services/groups/deploy_tokens/destroy_service_spec.rb11
-rw-r--r--spec/services/projects/deploy_tokens/destroy_service_spec.rb11
-rw-r--r--spec/services/resource_events/synthetic_milestone_notes_builder_service_spec.rb25
-rw-r--r--spec/support/helpers/api_validators_helpers.rb23
-rw-r--r--spec/support/services/deploy_token_shared_examples.rb22
22 files changed, 439 insertions, 251 deletions
diff --git a/spec/controllers/projects/issues_controller_spec.rb b/spec/controllers/projects/issues_controller_spec.rb
index 1fda9d63bbe..30228248baf 100644
--- a/spec/controllers/projects/issues_controller_spec.rb
+++ b/spec/controllers/projects/issues_controller_spec.rb
@@ -1249,6 +1249,26 @@ describe Projects::IssuesController do
expect(response).to have_gitlab_http_status(:not_found)
end
+ context 'invalid branch name' do
+ it 'is unprocessable' do
+ post(
+ :create_merge_request,
+ params: {
+ target_project_id: nil,
+ branch_name: 'master',
+ ref: 'master',
+ namespace_id: project.namespace.to_param,
+ project_id: project.to_param,
+ id: issue.to_param
+ },
+ format: :json
+ )
+
+ expect(response.body).to eq('Branch already exists')
+ expect(response).to have_gitlab_http_status(:unprocessable_entity)
+ end
+ end
+
context 'target_project_id is set' do
let(:target_project) { fork_project(project, user, repository: true) }
let(:target_project_id) { target_project.id }
diff --git a/spec/features/projects/files/user_uploads_files_spec.rb b/spec/features/projects/files/user_uploads_files_spec.rb
index 8a20c1387a3..ecf40969541 100644
--- a/spec/features/projects/files/user_uploads_files_spec.rb
+++ b/spec/features/projects/files/user_uploads_files_spec.rb
@@ -22,6 +22,31 @@ describe 'Projects > Files > User uploads files' do
include_examples 'it uploads and commit a new text file'
include_examples 'it uploads and commit a new image file'
+
+ it 'uploads a file to a sub-directory', :js do
+ click_link 'files'
+
+ page.within('.repo-breadcrumb') do
+ expect(page).to have_content('files')
+ end
+
+ find('.add-to-tree').click
+ click_link('Upload file')
+ drop_in_dropzone(File.join(Rails.root, 'spec', 'fixtures', 'doc_sample.txt'))
+
+ page.within('#modal-upload-blob') do
+ fill_in(:commit_message, with: 'New commit message')
+ end
+
+ click_button('Upload file')
+
+ expect(page).to have_content('New commit message')
+
+ page.within('.repo-breadcrumb') do
+ expect(page).to have_content('files')
+ expect(page).to have_content('doc_sample.txt')
+ end
+ end
end
context 'when a user does not have write access' do
diff --git a/spec/finders/group_members_finder_spec.rb b/spec/finders/group_members_finder_spec.rb
index 34649097f70..d1d97f6f9f0 100644
--- a/spec/finders/group_members_finder_spec.rb
+++ b/spec/finders/group_members_finder_spec.rb
@@ -82,7 +82,7 @@ describe GroupMembersFinder, '#execute' do
group.add_developer(user3)
member = group.add_maintainer(user1)
- result = described_class.new(group).execute(params: { search: user1.name })
+ result = described_class.new(group, params: { search: user1.name }).execute
expect(result.to_a).to match_array([member])
end
@@ -92,7 +92,7 @@ describe GroupMembersFinder, '#execute' do
group.add_developer(user3)
group.add_maintainer(user1)
- result = described_class.new(group).execute(include_relations: [:inherited], params: { search: user1.name })
+ result = described_class.new(group, params: { search: user1.name }).execute(include_relations: [:inherited])
expect(result.to_a).to match_array([])
end
@@ -103,7 +103,7 @@ describe GroupMembersFinder, '#execute' do
nested_group.add_maintainer(create(:user, name: user1.name))
member = group.add_maintainer(user1)
- result = described_class.new(nested_group).execute(include_relations: [:inherited], params: { search: member.user.name })
+ result = described_class.new(nested_group, params: { search: member.user.name }).execute(include_relations: [:inherited])
expect(result.to_a).to contain_exactly(member)
end
@@ -113,7 +113,7 @@ describe GroupMembersFinder, '#execute' do
group.add_maintainer(user1)
member = group.add_maintainer(user5)
- result = described_class.new(group, user2).execute(params: { two_factor: 'enabled' })
+ result = described_class.new(group, user2, params: { two_factor: 'enabled' }).execute
expect(result.to_a).to contain_exactly(member)
end
@@ -123,7 +123,7 @@ describe GroupMembersFinder, '#execute' do
member2 = group.add_maintainer(user1)
member_with_2fa = group.add_maintainer(user5)
- result = described_class.new(group, user2).execute(params: { two_factor: 'disabled' })
+ result = described_class.new(group, user2, params: { two_factor: 'disabled' }).execute
expect(result.to_a).not_to include(member_with_2fa)
expect(result.to_a).to match_array([member1, member2])
diff --git a/spec/frontend/diffs/components/commit_item_spec.js b/spec/frontend/diffs/components/commit_item_spec.js
index 61bab77964e..6bb3a0dcf21 100644
--- a/spec/frontend/diffs/components/commit_item_spec.js
+++ b/spec/frontend/diffs/components/commit_item_spec.js
@@ -30,12 +30,12 @@ describe('diffs/components/commit_item', () => {
const getCommitActionsElement = () => wrapper.find('.commit-actions');
const getCommitPipelineStatus = () => wrapper.find(CommitPipelineStatus);
- const defaultProps = {
- commit: getDiffWithCommit().commit,
- };
- const mountComponent = (propsData = defaultProps) => {
+ const mountComponent = propsData => {
wrapper = mount(Component, {
- propsData,
+ propsData: {
+ commit,
+ ...propsData,
+ },
stubs: {
CommitPipelineStatus: true,
},
@@ -59,9 +59,7 @@ describe('diffs/components/commit_item', () => {
expect(titleElement.text()).toBe(commit.title_html);
});
- // https://gitlab.com/gitlab-org/gitlab/-/issues/209776
- // eslint-disable-next-line jest/no-disabled-tests
- it.skip('renders commit description', () => {
+ it('renders commit description', () => {
const descElement = getDescElement();
const descExpandElement = getDescExpandElement();
@@ -107,7 +105,7 @@ describe('diffs/components/commit_item', () => {
describe('without commit description', () => {
beforeEach(() => {
- mountComponent({ defaultProps, commit: { ...defaultProps.commit, description_html: '' } });
+ mountComponent({ commit: { ...commit, description_html: '' } });
});
it('hides description', () => {
@@ -122,9 +120,8 @@ describe('diffs/components/commit_item', () => {
describe('with no matching user', () => {
beforeEach(() => {
mountComponent({
- defaultProps,
commit: {
- ...defaultProps.commit,
+ ...commit,
author: null,
author_email: TEST_AUTHOR_EMAIL,
author_name: TEST_AUTHOR_NAME,
@@ -154,8 +151,7 @@ describe('diffs/components/commit_item', () => {
describe('with signature', () => {
beforeEach(() => {
mountComponent({
- defaultProps,
- commit: { ...defaultProps.commit, signature_html: TEST_SIGNATURE_HTML },
+ commit: { ...commit, signature_html: TEST_SIGNATURE_HTML },
});
});
@@ -169,8 +165,7 @@ describe('diffs/components/commit_item', () => {
describe('with pipeline status', () => {
beforeEach(() => {
mountComponent({
- defaultProps,
- commit: { ...defaultProps.commit, pipeline_status_path: TEST_PIPELINE_STATUS_PATH },
+ commit: { ...commit, pipeline_status_path: TEST_PIPELINE_STATUS_PATH },
});
});
diff --git a/spec/lib/api/helpers/custom_validators_spec.rb b/spec/lib/api/helpers/custom_validators_spec.rb
deleted file mode 100644
index a4f2cd3452c..00000000000
--- a/spec/lib/api/helpers/custom_validators_spec.rb
+++ /dev/null
@@ -1,193 +0,0 @@
-# frozen_string_literal: true
-
-require 'spec_helper'
-
-describe API::Helpers::CustomValidators do
- let(:scope) do
- Struct.new(:opts) do
- def full_name(attr_name)
- attr_name
- end
- end
- end
-
- describe API::Helpers::CustomValidators::Absence do
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'empty param' do
- it 'does not raise a validation error' do
- expect_no_validation_error({})
- end
- end
-
- context 'invalid parameters' do
- it 'raises a validation error' do
- expect_validation_error('test' => 'some_value')
- end
- end
- end
-
- describe API::Helpers::CustomValidators::GitSha do
- let(:sha) { RepoHelpers.sample_commit.id }
- let(:short_sha) { sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH] }
- let(:too_short_sha) { sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH - 1] }
-
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'valid sha' do
- it 'does not raise a validation error' do
- expect_no_validation_error('test' => sha)
- expect_no_validation_error('test' => short_sha)
- end
- end
-
- context 'empty params' do
- it 'raises a validation error' do
- expect_validation_error('test' => nil)
- expect_validation_error('test' => '')
- end
- end
-
- context 'invalid sha' do
- it 'raises a validation error' do
- expect_validation_error('test' => "#{sha}2") # Sha length > 40
- expect_validation_error('test' => 'somestring')
- expect_validation_error('test' => too_short_sha) # sha length < MIN_SHA_LENGTH (7)
- end
- end
- end
-
- describe API::Helpers::CustomValidators::GitRef do
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'valid revision param' do
- it 'does not raise a validation error' do
- expect_no_validation_error('test' => '4e963fe')
- expect_no_validation_error('test' => 'foo/bar/baz')
- expect_no_validation_error('test' => "heads/fu\303\237")
- expect_no_validation_error('test' => 'a' * 1024)
- end
- end
-
- context "revision param contains invalid chars" do
- it 'raises a validation error' do
- expect_validation_error('test' => '-4e963fe')
- expect_validation_error('test' => '4e963fe..ed4ef')
- expect_validation_error('test' => '4e96\3fe')
- expect_validation_error('test' => '4e96@3fe')
- expect_validation_error('test' => '4e9@{63fe')
- expect_validation_error('test' => '4e963 fe')
- expect_validation_error('test' => '4e96~3fe')
- expect_validation_error('test' => '^4e963fe')
- expect_validation_error('test' => '4:e963fe')
- expect_validation_error('test' => '4e963fe.')
- expect_validation_error('test' => 'heads/foo..bar')
- expect_validation_error('test' => 'foo/bar/.')
- expect_validation_error('test' => 'heads/v@{ation')
- expect_validation_error('test' => 'refs/heads/foo.')
- expect_validation_error('test' => 'heads/foo\bar')
- expect_validation_error('test' => 'heads/f[/bar')
- expect_validation_error('test' => "heads/foo\t")
- expect_validation_error('test' => "heads/foo\177")
- expect_validation_error('test' => "#{'a' * 1025}")
- expect_validation_error('test' => nil)
- expect_validation_error('test' => '')
- end
- end
- end
-
- describe API::Helpers::CustomValidators::FilePath do
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'valid file path' do
- it 'does not raise a validation error' do
- expect_no_validation_error('test' => './foo')
- expect_no_validation_error('test' => './bar.rb')
- expect_no_validation_error('test' => 'foo%2Fbar%2Fnew%2Ffile.rb')
- expect_no_validation_error('test' => 'foo%2Fbar%2Fnew')
- expect_no_validation_error('test' => 'foo%252Fbar%252Fnew%252Ffile.rb')
- end
- end
-
- context 'invalid file path' do
- it 'raise a validation error' do
- expect_validation_error('test' => '../foo')
- expect_validation_error('test' => '../')
- expect_validation_error('test' => 'foo/../../bar')
- expect_validation_error('test' => 'foo/../')
- expect_validation_error('test' => 'foo/..')
- expect_validation_error('test' => '../')
- expect_validation_error('test' => '..\\')
- expect_validation_error('test' => '..\/')
- expect_validation_error('test' => '%2e%2e%2f')
- expect_validation_error('test' => '/etc/passwd')
- end
- end
- end
-
- describe API::Helpers::CustomValidators::IntegerNoneAny do
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'valid parameters' do
- it 'does not raise a validation error' do
- expect_no_validation_error('test' => 2)
- expect_no_validation_error('test' => 100)
- expect_no_validation_error('test' => 'None')
- expect_no_validation_error('test' => 'Any')
- expect_no_validation_error('test' => 'none')
- expect_no_validation_error('test' => 'any')
- end
- end
-
- context 'invalid parameters' do
- it 'raises a validation error' do
- expect_validation_error({ 'test' => 'some_other_string' })
- end
- end
- end
-
- describe API::Helpers::CustomValidators::ArrayNoneAny do
- subject do
- described_class.new(['test'], {}, false, scope.new)
- end
-
- context 'valid parameters' do
- it 'does not raise a validation error' do
- expect_no_validation_error('test' => [])
- expect_no_validation_error('test' => [1, 2, 3])
- expect_no_validation_error('test' => 'None')
- expect_no_validation_error('test' => 'Any')
- expect_no_validation_error('test' => 'none')
- expect_no_validation_error('test' => 'any')
- end
- end
-
- context 'invalid parameters' do
- it 'raises a validation error' do
- expect_validation_error('test' => 'some_other_string')
- end
- end
- end
-
- def expect_no_validation_error(params)
- expect { validate_test_param!(params) }.not_to raise_error
- end
-
- def expect_validation_error(params)
- expect { validate_test_param!(params) }.to raise_error(Grape::Exceptions::Validation)
- end
-
- def validate_test_param!(params)
- subject.validate_param!('test', params)
- end
-end
diff --git a/spec/lib/api/validations/validators/absence_spec.rb b/spec/lib/api/validations/validators/absence_spec.rb
new file mode 100644
index 00000000000..31120979d4f
--- /dev/null
+++ b/spec/lib/api/validations/validators/absence_spec.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::Absence do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'empty param' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error({})
+ end
+ end
+
+ context 'invalid parameters' do
+ it 'raises a validation error' do
+ expect_validation_error('test' => 'some_value')
+ end
+ end
+end
diff --git a/spec/lib/api/validations/validators/array_none_any_spec.rb b/spec/lib/api/validations/validators/array_none_any_spec.rb
new file mode 100644
index 00000000000..03f1c63b117
--- /dev/null
+++ b/spec/lib/api/validations/validators/array_none_any_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::ArrayNoneAny do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'valid parameters' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => [])
+ expect_no_validation_error('test' => [1, 2, 3])
+ expect_no_validation_error('test' => 'None')
+ expect_no_validation_error('test' => 'Any')
+ expect_no_validation_error('test' => 'none')
+ expect_no_validation_error('test' => 'any')
+ end
+ end
+
+ context 'invalid parameters' do
+ it 'raises a validation error' do
+ expect_validation_error('test' => 'some_other_string')
+ end
+ end
+end
diff --git a/spec/lib/api/validations/validators/file_path_spec.rb b/spec/lib/api/validations/validators/file_path_spec.rb
new file mode 100644
index 00000000000..8679f102d23
--- /dev/null
+++ b/spec/lib/api/validations/validators/file_path_spec.rb
@@ -0,0 +1,36 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::FilePath do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'valid file path' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => './foo')
+ expect_no_validation_error('test' => './bar.rb')
+ expect_no_validation_error('test' => 'foo%2Fbar%2Fnew%2Ffile.rb')
+ expect_no_validation_error('test' => 'foo%2Fbar%2Fnew')
+ expect_no_validation_error('test' => 'foo%252Fbar%252Fnew%252Ffile.rb')
+ end
+ end
+
+ context 'invalid file path' do
+ it 'raise a validation error' do
+ expect_validation_error('test' => '../foo')
+ expect_validation_error('test' => '../')
+ expect_validation_error('test' => 'foo/../../bar')
+ expect_validation_error('test' => 'foo/../')
+ expect_validation_error('test' => 'foo/..')
+ expect_validation_error('test' => '../')
+ expect_validation_error('test' => '..\\')
+ expect_validation_error('test' => '..\/')
+ expect_validation_error('test' => '%2e%2e%2f')
+ expect_validation_error('test' => '/etc/passwd')
+ end
+ end
+end
diff --git a/spec/lib/api/validations/validators/git_ref_spec.rb b/spec/lib/api/validations/validators/git_ref_spec.rb
new file mode 100644
index 00000000000..84de6272fe1
--- /dev/null
+++ b/spec/lib/api/validations/validators/git_ref_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::GitRef do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'valid revision param' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => '4e963fe')
+ expect_no_validation_error('test' => 'foo/bar/baz')
+ expect_no_validation_error('test' => "heads/fu\303\237")
+ expect_no_validation_error('test' => 'a' * 1024)
+ end
+ end
+
+ context "revision param contains invalid chars" do
+ it 'raises a validation error' do
+ expect_validation_error('test' => '-4e963fe')
+ expect_validation_error('test' => '4e963fe..ed4ef')
+ expect_validation_error('test' => '4e96\3fe')
+ expect_validation_error('test' => '4e96@3fe')
+ expect_validation_error('test' => '4e9@{63fe')
+ expect_validation_error('test' => '4e963 fe')
+ expect_validation_error('test' => '4e96~3fe')
+ expect_validation_error('test' => '^4e963fe')
+ expect_validation_error('test' => '4:e963fe')
+ expect_validation_error('test' => '4e963fe.')
+ expect_validation_error('test' => 'heads/foo..bar')
+ expect_validation_error('test' => 'foo/bar/.')
+ expect_validation_error('test' => 'heads/v@{ation')
+ expect_validation_error('test' => 'refs/heads/foo.')
+ expect_validation_error('test' => 'heads/foo\bar')
+ expect_validation_error('test' => 'heads/f[/bar')
+ expect_validation_error('test' => "heads/foo\t")
+ expect_validation_error('test' => "heads/foo\177")
+ expect_validation_error('test' => "#{'a' * 1025}")
+ expect_validation_error('test' => nil)
+ expect_validation_error('test' => '')
+ end
+ end
+end
diff --git a/spec/lib/api/validations/validators/git_sha_spec.rb b/spec/lib/api/validations/validators/git_sha_spec.rb
new file mode 100644
index 00000000000..39c2fe1dcf9
--- /dev/null
+++ b/spec/lib/api/validations/validators/git_sha_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::GitSha do
+ include ApiValidatorsHelpers
+
+ let(:sha) { RepoHelpers.sample_commit.id }
+ let(:short_sha) { sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH] }
+ let(:too_short_sha) { sha[0, Gitlab::Git::Commit::MIN_SHA_LENGTH - 1] }
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'valid sha' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => sha)
+ expect_no_validation_error('test' => short_sha)
+ end
+ end
+
+ context 'empty params' do
+ it 'raises a validation error' do
+ expect_validation_error('test' => nil)
+ expect_validation_error('test' => '')
+ end
+ end
+
+ context 'invalid sha' do
+ it 'raises a validation error' do
+ expect_validation_error('test' => "#{sha}2") # Sha length > 40
+ expect_validation_error('test' => 'somestring')
+ expect_validation_error('test' => too_short_sha) # sha length < MIN_SHA_LENGTH (7)
+ end
+ end
+end
diff --git a/spec/lib/api/validations/validators/integer_none_any_spec.rb b/spec/lib/api/validations/validators/integer_none_any_spec.rb
new file mode 100644
index 00000000000..a42f69fd96e
--- /dev/null
+++ b/spec/lib/api/validations/validators/integer_none_any_spec.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe API::Validations::Validators::IntegerNoneAny do
+ include ApiValidatorsHelpers
+
+ subject do
+ described_class.new(['test'], {}, false, scope.new)
+ end
+
+ context 'valid parameters' do
+ it 'does not raise a validation error' do
+ expect_no_validation_error('test' => 2)
+ expect_no_validation_error('test' => 100)
+ expect_no_validation_error('test' => 'None')
+ expect_no_validation_error('test' => 'Any')
+ expect_no_validation_error('test' => 'none')
+ expect_no_validation_error('test' => 'any')
+ end
+ end
+
+ context 'invalid parameters' do
+ it 'raises a validation error' do
+ expect_validation_error({ 'test' => 'some_other_string' })
+ end
+ end
+end
diff --git a/spec/lib/banzai/filter/autolink_filter_spec.rb b/spec/lib/banzai/filter/autolink_filter_spec.rb
index 8fba72a23f6..be6192f9ead 100644
--- a/spec/lib/banzai/filter/autolink_filter_spec.rb
+++ b/spec/lib/banzai/filter/autolink_filter_spec.rb
@@ -192,11 +192,6 @@ describe Banzai::Filter::AutolinkFilter do
expect(doc.text).to eq "See <<<#{link}>>>"
end
- it 'accepts link_attr options' do
- doc = filter("See #{link}", link_attr: { class: 'custom' })
- expect(doc.at_css('a')['class']).to eq 'custom'
- end
-
it 'escapes RTLO and other characters' do
# rendered text looks like "http://example.com/evilexe.mp3"
evil_link = "#{link}evil\u202E3pm.exe"
diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb
index 9c2f0e910b1..f25383ef416 100644
--- a/spec/lib/gitlab/git/blob_spec.rb
+++ b/spec/lib/gitlab/git/blob_spec.rb
@@ -409,37 +409,43 @@ describe Gitlab::Git::Blob, :seed_helper do
end
end
- describe 'encoding' do
+ describe 'encoding', :aggregate_failures do
context 'file with russian text' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "encoding/russian.rb") }
- it { expect(blob.name).to eq("russian.rb") }
- it { expect(blob.data.lines.first).to eq("Хороший файл") }
- it { expect(blob.size).to eq(23) }
- it { expect(blob.truncated?).to be_falsey }
- # Run it twice since data is encoded after the first run
- it { expect(blob.truncated?).to be_falsey }
- it { expect(blob.mode).to eq("100755") }
+ it 'has the correct blob attributes' do
+ expect(blob.name).to eq("russian.rb")
+ expect(blob.data.lines.first).to eq("Хороший файл")
+ expect(blob.size).to eq(23)
+ expect(blob.truncated?).to be_falsey
+ # Run it twice since data is encoded after the first run
+ expect(blob.truncated?).to be_falsey
+ expect(blob.mode).to eq("100755")
+ end
end
context 'file with Japanese text' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::Commit::ID, "encoding/テスト.txt") }
- it { expect(blob.name).to eq("テスト.txt") }
- it { expect(blob.data).to include("これはテスト") }
- it { expect(blob.size).to eq(340) }
- it { expect(blob.mode).to eq("100755") }
- it { expect(blob.truncated?).to be_falsey }
+ it 'has the correct blob attributes' do
+ expect(blob.name).to eq("テスト.txt")
+ expect(blob.data).to include("これはテスト")
+ expect(blob.size).to eq(340)
+ expect(blob.mode).to eq("100755")
+ expect(blob.truncated?).to be_falsey
+ end
end
context 'file with ISO-8859 text' do
let(:blob) { Gitlab::Git::Blob.find(repository, SeedRepo::LastCommit::ID, "encoding/iso8859.txt") }
- it { expect(blob.name).to eq("iso8859.txt") }
- it { expect(blob.loaded_size).to eq(4) }
- it { expect(blob.size).to eq(4) }
- it { expect(blob.mode).to eq("100644") }
- it { expect(blob.truncated?).to be_falsey }
+ it 'has the correct blob attributes' do
+ expect(blob.name).to eq("iso8859.txt")
+ expect(blob.loaded_size).to eq(4)
+ expect(blob.size).to eq(4)
+ expect(blob.mode).to eq("100644")
+ expect(blob.truncated?).to be_falsey
+ end
end
end
diff --git a/spec/models/ability_spec.rb b/spec/models/ability_spec.rb
index d9d60e02a97..2bf971f553f 100644
--- a/spec/models/ability_spec.rb
+++ b/spec/models/ability_spec.rb
@@ -137,12 +137,6 @@ describe Ability do
expect(users_for_snippet(snippet)).to match_array([author])
end
- it 'internal snippet is readable by all registered users' do
- snippet = create(:personal_snippet, :public, author: author)
-
- expect(users_for_snippet(snippet)).to match_array(users)
- end
-
it 'public snippet is readable by all users' do
snippet = create(:personal_snippet, :public, author: author)
diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb
index 88c26c92417..673b9e5f076 100644
--- a/spec/models/ci/build_spec.rb
+++ b/spec/models/ci/build_spec.rb
@@ -3337,7 +3337,7 @@ describe Ci::Build do
end
it "doesn't save timeout" do
- expect { run_job_without_exception }.not_to change { job.reload.ensure_metadata.timeout_source }
+ expect { run_job_without_exception }.not_to change { job.reload.ensure_metadata.timeout }
end
it "doesn't save timeout_source" do
diff --git a/spec/requests/api/deploy_tokens_spec.rb b/spec/requests/api/deploy_tokens_spec.rb
index a885e80fd55..5948c3d719f 100644
--- a/spec/requests/api/deploy_tokens_spec.rb
+++ b/spec/requests/api/deploy_tokens_spec.rb
@@ -175,8 +175,12 @@ describe API::DeployTokens do
it { is_expected.to have_gitlab_http_status(:no_content) }
- it 'deletes the deploy token' do
- expect { subject }.to change { project.deploy_tokens.count }.by(-1)
+ it 'calls the deploy token destroy service' do
+ expect(::Projects::DeployTokens::DestroyService).to receive(:new)
+ .with(project, user, token_id: deploy_token.id)
+ .and_return(true)
+
+ subject
end
context 'invalid request' do
@@ -187,9 +191,13 @@ describe API::DeployTokens do
end
it 'returns bad_request with invalid token id' do
- delete api("/projects/#{project.id}/deploy_tokens/123abc", user)
+ expect(::Projects::DeployTokens::DestroyService).to receive(:new)
+ .with(project, user, token_id: 999)
+ .and_raise(ActiveRecord::RecordNotFound)
+
+ delete api("/projects/#{project.id}/deploy_tokens/999", user)
- expect(response).to have_gitlab_http_status(:bad_request)
+ expect(response).to have_gitlab_http_status(:not_found)
end
end
end
@@ -307,10 +315,12 @@ describe API::DeployTokens do
group.add_maintainer(user)
end
- it 'deletes the deploy token' do
- expect { subject }.to change { group.deploy_tokens.count }.by(-1)
+ it 'calls the deploy token destroy service' do
+ expect(::Groups::DeployTokens::DestroyService).to receive(:new)
+ .with(group, user, token_id: group_deploy_token.id)
+ .and_return(true)
- expect(group.deploy_tokens).to be_empty
+ subject
end
context 'invalid request' do
@@ -321,7 +331,11 @@ describe API::DeployTokens do
end
it 'returns not found with invalid deploy token id' do
- delete api("/groups/#{group.id}/deploy_tokens/bad_id", user)
+ expect(::Groups::DeployTokens::DestroyService).to receive(:new)
+ .with(group, user, token_id: 999)
+ .and_raise(ActiveRecord::RecordNotFound)
+
+ delete api("/groups/#{group.id}/deploy_tokens/999", user)
expect(response).to have_gitlab_http_status(:not_found)
end
diff --git a/spec/serializers/diffs_entity_spec.rb b/spec/serializers/diffs_entity_spec.rb
index bb4ac5f9608..b42240037df 100644
--- a/spec/serializers/diffs_entity_spec.rb
+++ b/spec/serializers/diffs_entity_spec.rb
@@ -26,5 +26,47 @@ describe DiffsEntity do
:merge_request_diffs, :definition_path_prefix
)
end
+
+ context "when a commit_id is passed" do
+ let(:commits) { merge_request.commits }
+ let(:entity) do
+ described_class.new(
+ merge_request_diffs.first.diffs,
+ request: request,
+ merge_request: merge_request,
+ merge_request_diffs: merge_request_diffs,
+ commit: commit
+ )
+ end
+
+ subject { entity.as_json }
+
+ context "when the passed commit is not the first or last in the group" do
+ let(:commit) { commits.third }
+
+ it 'includes commit references for previous and next' do
+ expect(subject[:commit][:prev_commit_id]).to eq(commits.second.id)
+ expect(subject[:commit][:next_commit_id]).to eq(commits.fourth.id)
+ end
+ end
+
+ context "when the passed commit is the first in the group" do
+ let(:commit) { commits.first }
+
+ it 'includes commit references for nil and next' do
+ expect(subject[:commit][:prev_commit_id]).to be_nil
+ expect(subject[:commit][:next_commit_id]).to eq(commits.second.id)
+ end
+ end
+
+ context "when the passed commit is the last in the group" do
+ let(:commit) { commits.last }
+
+ it 'includes commit references for previous and nil' do
+ expect(subject[:commit][:prev_commit_id]).to eq(commits[-2].id)
+ expect(subject[:commit][:next_commit_id]).to be_nil
+ end
+ end
+ end
end
end
diff --git a/spec/services/groups/deploy_tokens/destroy_service_spec.rb b/spec/services/groups/deploy_tokens/destroy_service_spec.rb
new file mode 100644
index 00000000000..d4ef5963558
--- /dev/null
+++ b/spec/services/groups/deploy_tokens/destroy_service_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Groups::DeployTokens::DestroyService do
+ it_behaves_like 'a deploy token deletion service' do
+ let_it_be(:entity) { create(:group) }
+ let_it_be(:deploy_token_class) { GroupDeployToken }
+ let_it_be(:deploy_token) { create(:deploy_token, :group, groups: [entity]) }
+ end
+end
diff --git a/spec/services/projects/deploy_tokens/destroy_service_spec.rb b/spec/services/projects/deploy_tokens/destroy_service_spec.rb
new file mode 100644
index 00000000000..24407f46615
--- /dev/null
+++ b/spec/services/projects/deploy_tokens/destroy_service_spec.rb
@@ -0,0 +1,11 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe Projects::DeployTokens::DestroyService do
+ it_behaves_like 'a deploy token deletion service' do
+ let_it_be(:entity) { create(:project) }
+ let_it_be(:deploy_token_class) { ProjectDeployToken }
+ let_it_be(:deploy_token) { create(:deploy_token, projects: [entity]) }
+ end
+end
diff --git a/spec/services/resource_events/synthetic_milestone_notes_builder_service_spec.rb b/spec/services/resource_events/synthetic_milestone_notes_builder_service_spec.rb
new file mode 100644
index 00000000000..e98b8bd00dc
--- /dev/null
+++ b/spec/services/resource_events/synthetic_milestone_notes_builder_service_spec.rb
@@ -0,0 +1,25 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe ResourceEvents::SyntheticMilestoneNotesBuilderService do
+ describe '#execute' do
+ let_it_be(:user) { create(:user) }
+ let_it_be(:issue) { create(:issue, author: user) }
+
+ before do
+ create_list(:resource_milestone_event, 3, issue: issue)
+
+ stub_feature_flags(track_resource_milestone_change_events: false)
+ end
+
+ context 'when resource milestone events are disabled' do
+ # https://gitlab.com/gitlab-org/gitlab/-/issues/212985
+ it 'still builds notes for existing resource milestone events' do
+ notes = described_class.new(issue, user).execute
+
+ expect(notes.size).to eq(3)
+ end
+ end
+ end
+end
diff --git a/spec/support/helpers/api_validators_helpers.rb b/spec/support/helpers/api_validators_helpers.rb
new file mode 100644
index 00000000000..dc05e5afd57
--- /dev/null
+++ b/spec/support/helpers/api_validators_helpers.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+module ApiValidatorsHelpers
+ def scope
+ Struct.new(:opts) do
+ def full_name(attr_name)
+ attr_name
+ end
+ end
+ end
+
+ def expect_no_validation_error(params)
+ expect { validate_test_param!(params) }.not_to raise_error
+ end
+
+ def expect_validation_error(params)
+ expect { validate_test_param!(params) }.to raise_error(Grape::Exceptions::Validation)
+ end
+
+ def validate_test_param!(params)
+ subject.validate_param!('test', params)
+ end
+end
diff --git a/spec/support/services/deploy_token_shared_examples.rb b/spec/support/services/deploy_token_shared_examples.rb
index 70efd1fcd0c..9d681970739 100644
--- a/spec/support/services/deploy_token_shared_examples.rb
+++ b/spec/support/services/deploy_token_shared_examples.rb
@@ -58,3 +58,25 @@ RSpec.shared_examples 'a deploy token creation service' do
end
end
end
+
+RSpec.shared_examples 'a deploy token deletion service' do
+ let(:user) { create(:user) }
+ let(:deploy_token_params) { { token_id: deploy_token.id } }
+
+ describe '#execute' do
+ subject { described_class.new(entity, user, deploy_token_params).execute }
+
+ it "destroys a token record and it's associated DeployToken" do
+ expect { subject }.to change { deploy_token_class.count }.by(-1)
+ .and change { DeployToken.count }.by(-1)
+ end
+
+ context 'invalid token id' do
+ let(:deploy_token_params) { { token_id: 9999 } }
+
+ it 'raises an error' do
+ expect { subject }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+ end
+end