debian-mirror-gitlab/spec/models/deploy_keys_project_spec.rb

59 lines
1.5 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2014-09-02 18:07:02 +05:30
require 'spec_helper'
2020-07-28 23:09:34 +05:30
RSpec.describe DeployKeysProject do
2014-09-02 18:07:02 +05:30
describe "Associations" do
2015-04-26 12:48:37 +05:30
it { is_expected.to belong_to(:deploy_key) }
it { is_expected.to belong_to(:project) }
2014-09-02 18:07:02 +05:30
end
describe "Validation" do
2015-04-26 12:48:37 +05:30
it { is_expected.to validate_presence_of(:project_id) }
2018-03-17 18:26:18 +05:30
it { is_expected.to validate_presence_of(:deploy_key) }
2015-04-26 12:48:37 +05:30
end
describe "Destroying" do
2017-09-10 17:25:29 +05:30
let(:project) { create(:project) }
2015-04-26 12:48:37 +05:30
subject { create(:deploy_keys_project, project: project) }
2019-12-21 20:55:43 +05:30
2015-04-26 12:48:37 +05:30
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
2015-09-11 14:41:01 +05:30
expect { deploy_key.reload }.not_to raise_error
2015-04-26 12:48:37 +05:30
end
end
context "when the deploy key is private" do
it "destroys the deploy key" do
subject.destroy
2015-09-11 14:41:01 +05:30
expect { deploy_key.reload }.to raise_error(ActiveRecord::RecordNotFound)
2015-04-26 12:48:37 +05:30
end
end
end
context "when the deploy key is used by more than one project" do
2017-09-10 17:25:29 +05:30
let!(:other_project) { create(:project) }
2015-04-26 12:48:37 +05:30
before do
other_project.deploy_keys << deploy_key
end
it "doesn't destroy the deploy key" do
subject.destroy
2015-09-11 14:41:01 +05:30
expect { deploy_key.reload }.not_to raise_error
2015-04-26 12:48:37 +05:30
end
end
2014-09-02 18:07:02 +05:30
end
end