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
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 11:17:02 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-08-18 11:17:02 +0300
commitb39512ed755239198a9c294b6a45e65c05900235 (patch)
treed234a3efade1de67c46b9e5a38ce813627726aa7 /spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb
parentd31474cf3b17ece37939d20082b07f6657cc79a9 (diff)
Add latest changes from gitlab-org/gitlab@15-3-stable-eev15.3.0-rc42
Diffstat (limited to 'spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb')
-rw-r--r--spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb53
1 files changed, 53 insertions, 0 deletions
diff --git a/spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb b/spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb
new file mode 100644
index 00000000000..ed3b1d2d0bf
--- /dev/null
+++ b/spec/finders/autocomplete/deploy_keys_with_write_access_finder_spec.rb
@@ -0,0 +1,53 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+RSpec.describe Autocomplete::DeployKeysWithWriteAccessFinder do
+ let_it_be(:user) { create(:user) }
+
+ let(:finder) { described_class.new(user, project) }
+
+ describe '#execute' do
+ subject(:execute) { finder.execute }
+
+ context 'when project is missing' do
+ let(:project) { nil }
+
+ it 'returns an empty ActiveRecord::Relation' do
+ expect(execute).to eq(DeployKey.none)
+ end
+ end
+
+ context 'when project is present' do
+ let_it_be(:project) { create(:project, :public) }
+
+ context 'and current user cannot admin project' do
+ it 'raises Gitlab::Access::AccessDeniedError' do
+ expect { execute }.to raise_error(Gitlab::Access::AccessDeniedError)
+ end
+ end
+
+ context 'and current user can admin project' do
+ before do
+ project.add_maintainer(user)
+ end
+
+ context 'when deploy key does not have write access to project' do
+ let(:deploy_key_project) { create(:deploy_keys_project, project: project) }
+
+ it 'returns an empty ActiveRecord::Relation' do
+ expect(execute).to eq(DeployKey.none)
+ end
+ end
+
+ context 'when deploy key has write access to project' do
+ let(:deploy_key_project) { create(:deploy_keys_project, :write_access, project: project) }
+
+ it 'returns the deploy keys' do
+ expect(execute).to match_array([deploy_key_project.deploy_key])
+ end
+ end
+ end
+ end
+ end
+end