diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-07-20 15:26:25 +0300 |
commit | a09983ae35713f5a2bbb100981116d31ce99826e (patch) | |
tree | 2ee2af7bd104d57086db360a7e6d8c9d5d43667a /spec/services/deploy_keys/collect_keys_service_spec.rb | |
parent | 18c5ab32b738c0b6ecb4d0df3994000482f34bd8 (diff) |
Add latest changes from gitlab-org/gitlab@13-2-stable-ee
Diffstat (limited to 'spec/services/deploy_keys/collect_keys_service_spec.rb')
-rw-r--r-- | spec/services/deploy_keys/collect_keys_service_spec.rb | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/spec/services/deploy_keys/collect_keys_service_spec.rb b/spec/services/deploy_keys/collect_keys_service_spec.rb new file mode 100644 index 00000000000..3442e5e456a --- /dev/null +++ b/spec/services/deploy_keys/collect_keys_service_spec.rb @@ -0,0 +1,58 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe DeployKeys::CollectKeysService do + let_it_be(:user) { create(:user) } + let_it_be(:project) { create(:project, :private) } + + subject { DeployKeys::CollectKeysService.new(project, user) } + + before do + project&.add_developer(user) + end + + context 'when no project is passed in' do + let(:project) { nil } + + it 'returns an empty Array' do + expect(subject.execute).to be_empty + end + end + + context 'when no user is passed in' do + let(:user) { nil } + + it 'returns an empty Array' do + expect(subject.execute).to be_empty + end + end + + context 'when a project is passed in' do + let_it_be(:deploy_keys_project) { create(:deploy_keys_project, :write_access, project: project) } + let_it_be(:deploy_key) { deploy_keys_project.deploy_key } + + it 'only returns deploy keys with write access' do + create(:deploy_keys_project, project: project) + + expect(subject.execute).to contain_exactly(deploy_key) + end + + it 'returns deploy keys only for this project' do + other_project = create(:project) + create(:deploy_keys_project, :write_access, project: other_project) + + expect(subject.execute).to contain_exactly(deploy_key) + end + end + + context 'when the user cannot read the project' do + before do + project.members.delete_all + end + + it 'returns an empty Array' do + expect(subject.execute).to be_empty + end + end +end |