diff options
Diffstat (limited to 'spec/models/deploy_keys_project_spec.rb')
-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 |