blob: ed3b1d2d0bf4d67b0cba494198d7f44f885e561f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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
|