diff options
author | Douwe Maan <douwe@gitlab.com> | 2015-03-17 14:55:43 +0100 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2015-03-17 14:55:43 +0100 |
commit | 9c7fffb6559facdcf8bbda680795f70d836293bf (patch) | |
tree | ec121310208197f6f50b953c999b0880083b45cd /spec/models | |
parent | 409097bd7e0f5857cf0bc5462bd47484980ec787 (diff) | |
download | gitlab-ce-9c7fffb6559facdcf8bbda680795f70d836293bf.tar.gz |
Delete deploy key when last connection to a project is destroyed.
Diffstat (limited to 'spec/models')
-rw-r--r-- | spec/models/deploy_keys_project_spec.rb | 33 |
1 files changed, 33 insertions, 0 deletions
diff --git a/spec/models/deploy_keys_project_spec.rb b/spec/models/deploy_keys_project_spec.rb index aacd9bf38bf..f351aab9238 100644 --- a/spec/models/deploy_keys_project_spec.rb +++ b/spec/models/deploy_keys_project_spec.rb @@ -21,4 +21,37 @@ describe DeployKeysProject do it { is_expected.to validate_presence_of(:project_id) } it { is_expected.to validate_presence_of(:deploy_key_id) } end + + describe "Destroying" do + let(:project) { create(:project) } + subject { create(:deploy_keys_project, project: project) } + let(:deploy_key) { subject.deploy_key } + + context "when the deploy key is only used by this project" do + it "destroys the deploy key" do + subject.destroy + + expect { + deploy_key.reload + }.to raise_error(ActiveRecord::RecordNotFound) + end + end + + context "when the deploy key is used by more than one project" do + + let!(:other_project) { create(:project) } + + before do + other_project.deploy_keys << deploy_key + end + + it "doesn't destroy the deploy key" do + subject.destroy + + expect { + deploy_key.reload + }.not_to raise_error(ActiveRecord::RecordNotFound) + end + end + end end |