summaryrefslogtreecommitdiff
path: root/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb')
-rw-r--r--spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb54
1 files changed, 54 insertions, 0 deletions
diff --git a/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb b/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb
new file mode 100644
index 00000000000..c92e819db19
--- /dev/null
+++ b/spec/support/shared_examples/models/project_ci_cd_settings_shared_examples.rb
@@ -0,0 +1,54 @@
+# frozen_string_literal: true
+
+RSpec.shared_examples 'ci_cd_settings delegation' do
+ let(:exclude_attributes) { [] }
+
+ context 'when ci_cd_settings is destroyed but project is not' do
+ it 'allows methods delegated to ci_cd_settings to be nil', :aggregate_failures do
+ project = create(:project)
+ attributes = project.ci_cd_settings.attributes.keys - %w(id project_id) - exclude_attributes
+ project.ci_cd_settings.destroy!
+ project.reload
+ attributes.each do |attr|
+ method = project.respond_to?("ci_#{attr}") ? "ci_#{attr}" : attr
+ expect(project.send(method)).to be_nil, "#{attr} was not nil"
+ end
+ 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