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 DeployKeysProject do
|
2013-05-06 08:09:26 -04:00
|
|
|
describe "Associations" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to belong_to(:deploy_key) }
|
|
|
|
it { is_expected.to belong_to(:project) }
|
2013-05-06 08:09:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
describe "Validation" do
|
2015-02-12 13:17:35 -05:00
|
|
|
it { is_expected.to validate_presence_of(:project_id) }
|
2018-01-05 10:23:44 -05:00
|
|
|
it { is_expected.to validate_presence_of(:deploy_key) }
|
2013-05-06 08:09:26 -04:00
|
|
|
end
|
2015-03-17 09:55:43 -04:00
|
|
|
|
|
|
|
describe "Destroying" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let(:project) { create(:project) }
|
2015-03-17 09:55:43 -04:00
|
|
|
subject { create(:deploy_keys_project, project: project) }
|
2019-10-18 07:11:44 -04:00
|
|
|
|
2015-03-17 09:55:43 -04:00
|
|
|
let(:deploy_key) { subject.deploy_key }
|
|
|
|
|
|
|
|
context "when the deploy key is only used by this project" do
|
2015-03-27 09:43:48 -04:00
|
|
|
context "when the deploy key is public" do
|
|
|
|
before do
|
|
|
|
deploy_key.update_attribute(:public, true)
|
|
|
|
end
|
2015-03-17 09:55:43 -04:00
|
|
|
|
2015-03-27 09:43:48 -04:00
|
|
|
it "doesn't destroy the deploy key" do
|
2021-04-05 05:09:05 -04:00
|
|
|
subject.destroy!
|
2015-03-27 09:43:48 -04:00
|
|
|
|
2015-05-18 16:40:32 -04:00
|
|
|
expect { deploy_key.reload }.not_to raise_error
|
2015-03-27 09:43:48 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the deploy key is private" do
|
|
|
|
it "destroys the deploy key" do
|
2021-04-05 05:09:05 -04:00
|
|
|
subject.destroy!
|
2015-03-27 09:43:48 -04:00
|
|
|
|
2015-06-22 16:00:54 -04:00
|
|
|
expect { deploy_key.reload }.to raise_error(ActiveRecord::RecordNotFound)
|
2015-03-27 09:43:48 -04:00
|
|
|
end
|
2015-03-17 09:55:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
context "when the deploy key is used by more than one project" do
|
2017-08-02 15:55:11 -04:00
|
|
|
let!(:other_project) { create(:project) }
|
2015-03-17 09:55:43 -04:00
|
|
|
|
|
|
|
before do
|
|
|
|
other_project.deploy_keys << deploy_key
|
|
|
|
end
|
|
|
|
|
|
|
|
it "doesn't destroy the deploy key" do
|
2021-04-05 05:09:05 -04:00
|
|
|
subject.destroy!
|
2015-03-17 09:55:43 -04:00
|
|
|
|
2015-05-18 16:40:32 -04:00
|
|
|
expect { deploy_key.reload }.not_to raise_error
|
2015-03-17 09:55:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2013-05-06 08:09:26 -04:00
|
|
|
end
|