Commit 3d378065 authored by Mark Lapierre's avatar Mark Lapierre Committed by Nikola Milojevic

Add tests for predicate methods

parent a0d81c52
......@@ -64,6 +64,30 @@ RSpec.describe Project do
include_examples 'ci_cd_settings delegation'
describe '#merge_pipelines_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :merge_pipelines_enabled? }
end
end
describe '#merge_pipelines_were_disabled?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :merge_pipelines_were_disabled? }
end
end
describe '#merge_trains_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :merge_trains_enabled? }
end
end
describe '#auto_rollback_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :auto_rollback_enabled? }
end
end
describe '#jira_vulnerabilities_integration_enabled?' do
context 'when project lacks a jira_integration relation' do
it 'returns false' do
......
......@@ -660,6 +660,42 @@ RSpec.describe Project, factory_default: :keep do
include_examples 'ci_cd_settings delegation'
describe '#ci_forward_deployment_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method', prefix: 'ci_' do
let(:delegated_method) { :forward_deployment_enabled? }
end
end
describe '#ci_job_token_scope_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method', prefix: 'ci_' do
let(:delegated_method) { :job_token_scope_enabled? }
end
end
describe '#restrict_user_defined_variables?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :restrict_user_defined_variables? }
end
end
describe '#keep_latest_artifacts_available?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :keep_latest_artifacts_available? }
end
end
describe '#keep_latest_artifact?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :keep_latest_artifact? }
end
end
describe '#group_runners_enabled?' do
it_behaves_like 'a ci_cd_settings predicate method' do
let(:delegated_method) { :group_runners_enabled? }
end
end
context 'when read_container_registry_access_level is disabled' do
before do
stub_feature_flags(read_container_registry_access_level: false)
......
......@@ -14,3 +14,39 @@ RSpec.shared_examples 'ci_cd_settings delegation' do
end
end
end
RSpec.shared_examples 'a ci_cd_settings predicate method' do |prefix: ''|
using RSpec::Parameterized::TableSyntax
let_it_be(:project) { create(:project) }
context 'when ci_cd_settings is nil' do
before do
allow(project).to receive(:ci_cd_settings).and_return(nil)
end
it 'returns false' do
expect(project.send("#{prefix}#{delegated_method}")).to be(false)
end
end
context 'when ci_cd_settings is not nil' do
where(:delegated_method_return, :subject_return) do
true | true
false | false
end
with_them do
let(:ci_cd_settings_double) { double('ProjectCiCdSetting') }
before do
allow(project).to receive(:ci_cd_settings).and_return(ci_cd_settings_double)
allow(ci_cd_settings_double).to receive(delegated_method).and_return(delegated_method_return)
end
it 'returns the expected boolean value' do
expect(project.send("#{prefix}#{delegated_method}")).to be(subject_return)
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment