2019-03-30 03:23:56 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2013-05-06 08:09:26 -04:00
|
|
|
require 'spec_helper'
|
|
|
|
|
2020-06-24 14:09:03 -04:00
|
|
|
RSpec.describe DeployKey, :mailer do
|
2013-05-06 08:09:26 -04:00
|
|
|
describe "Associations" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to have_many(:deploy_keys_projects) }
|
|
|
|
it { is_expected.to have_many(:projects) }
|
2020-11-13 10:09:24 -05:00
|
|
|
it { is_expected.to have_many(:protected_branch_push_access_levels) }
|
2013-05-06 08:09:26 -04:00
|
|
|
end
|
2016-11-18 06:09:03 -05:00
|
|
|
|
|
|
|
describe 'notification' do
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
it 'does not send a notification' do
|
|
|
|
perform_enqueued_jobs do
|
|
|
|
create(:deploy_key, user: user)
|
|
|
|
end
|
|
|
|
|
|
|
|
should_not_email(user)
|
|
|
|
end
|
|
|
|
end
|
2018-03-28 12:54:15 -04:00
|
|
|
|
|
|
|
describe '#user' do
|
|
|
|
let(:deploy_key) { create(:deploy_key) }
|
|
|
|
let(:user) { create(:user) }
|
|
|
|
|
|
|
|
context 'when user is set' do
|
|
|
|
before do
|
|
|
|
deploy_key.user = user
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the user' do
|
|
|
|
expect(deploy_key.user).to be(user)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'when user is not set' do
|
|
|
|
it 'returns the ghost user' do
|
|
|
|
expect(deploy_key.user).to eq(User.ghost)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2020-11-10 10:09:14 -05:00
|
|
|
|
|
|
|
describe '.with_write_access_for_project' do
|
|
|
|
let_it_be(:project) { create(:project, :private) }
|
|
|
|
|
|
|
|
subject { described_class.with_write_access_for_project(project) }
|
|
|
|
|
|
|
|
context 'when no project is passed in' do
|
|
|
|
let(:project) { nil }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
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)
|
|
|
|
|
|
|
|
is_expected.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)
|
|
|
|
|
|
|
|
is_expected.to contain_exactly(deploy_key)
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and a specific deploy key is passed in' do
|
|
|
|
subject { described_class.with_write_access_for_project(project, deploy_key: specific_deploy_key) }
|
|
|
|
|
|
|
|
context 'and this deploy key is not linked to the project' do
|
|
|
|
let(:specific_deploy_key) { create(:deploy_key) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and this deploy key has not write access to the project' do
|
|
|
|
let(:specific_deploy_key) { create(:deploy_key, deploy_keys_projects: [create(:deploy_keys_project, project: project)]) }
|
|
|
|
|
|
|
|
it { is_expected.to be_empty }
|
|
|
|
end
|
|
|
|
|
|
|
|
context 'and this deploy key has write access to the project' do
|
|
|
|
let(:specific_deploy_key) { create(:deploy_key, deploy_keys_projects: [create(:deploy_keys_project, :write_access, project: project)]) }
|
|
|
|
|
|
|
|
it { is_expected.to contain_exactly(specific_deploy_key) }
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-06 08:09:26 -04:00
|
|
|
end
|