diff options
author | Alexander Randa <randa.alex@gmail.com> | 2017-03-31 12:54:38 +0000 |
---|---|---|
committer | Alexander Randa <randa.alex@gmail.com> | 2017-06-02 19:44:36 +0300 |
commit | 3d70eeb5bb9dac8073a149547dc3b85c90d65e7d (patch) | |
tree | b925f3518e991df59a094ae9d7a6926241c9f5aa /spec/policies | |
parent | f07aee72bef4604312e11a43fce3a47865bce100 (diff) | |
download | gitlab-ce-3d70eeb5bb9dac8073a149547dc3b85c90d65e7d.tar.gz |
Implement ability to update deploy keys
Diffstat (limited to 'spec/policies')
-rw-r--r-- | spec/policies/deploy_key_policy_spec.rb | 56 |
1 files changed, 56 insertions, 0 deletions
diff --git a/spec/policies/deploy_key_policy_spec.rb b/spec/policies/deploy_key_policy_spec.rb new file mode 100644 index 00000000000..28e10f0bfe2 --- /dev/null +++ b/spec/policies/deploy_key_policy_spec.rb @@ -0,0 +1,56 @@ +require 'spec_helper' + +describe DeployKeyPolicy, models: true do + subject { described_class.abilities(current_user, deploy_key).to_set } + + describe 'updating a deploy_key' do + context 'when a regular user' do + let(:current_user) { create(:user) } + + context 'tries to update private deploy key attached to project' do + let(:deploy_key) { create(:deploy_key, public: false) } + let(:project) { create(:project_empty_repo) } + + before do + project.add_master(current_user) + project.deploy_keys << deploy_key + end + + it { is_expected.to include(:update_deploy_key) } + end + + context 'tries to update private deploy key attached to other project' do + let(:deploy_key) { create(:deploy_key, public: false) } + let(:other_project) { create(:project_empty_repo) } + + before do + other_project.deploy_keys << deploy_key + end + + it { is_expected.not_to include(:update_deploy_key) } + end + + context 'tries to update public deploy key' do + let(:deploy_key) { create(:another_deploy_key, public: true) } + + it { is_expected.not_to include(:update_deploy_key) } + end + end + + context 'when an admin user' do + let(:current_user) { create(:user, :admin) } + + context ' tries to update private deploy key' do + let(:deploy_key) { create(:deploy_key, public: false) } + + it { is_expected.to include(:update_deploy_key) } + end + + context 'when an admin user tries to update public deploy key' do + let(:deploy_key) { create(:another_deploy_key, public: true) } + + it { is_expected.to include(:update_deploy_key) } + end + end + end +end |