gitlab-org--gitlab-foss/spec/models/deploy_keys_project_spec.rb
Douwe Maan 536a47b4b7 Merge branch 'sh-migrate-can-push-to-deploy-keys-projects-10-3' into 'security-10-3'
[10.3] Migrate `can_push` column from `keys` to `deploy_keys_project`

See merge request gitlab/gitlabhq!2276

(cherry picked from commit f6ca52d31bac350a23938e0aebf717c767b4710c)

1f2bd3c0 Backport to 10.3
2018-01-16 17:04:51 -08:00

55 lines
1.4 KiB
Ruby

require 'spec_helper'
describe DeployKeysProject do
describe "Associations" do
it { is_expected.to belong_to(:deploy_key) }
it { is_expected.to belong_to(:project) }
end
describe "Validation" do
it { is_expected.to validate_presence_of(:project_id) }
it { is_expected.to validate_presence_of(:deploy_key) }
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
context "when the deploy key is public" do
before do
deploy_key.update_attribute(:public, true)
end
it "doesn't destroy the deploy key" do
subject.destroy
expect { deploy_key.reload }.not_to raise_error
end
end
context "when the deploy key is private" do
it "destroys the deploy key" do
subject.destroy
expect { deploy_key.reload }.to raise_error(ActiveRecord::RecordNotFound)
end
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
end
end
end
end