From e6a3ee56a1ab6dad4429e7b1357ca0919d977c94 Mon Sep 17 00:00:00 2001 From: Jeremy Lenz Date: Fri, 27 Sep 2024 16:50:56 -0400 Subject: [PATCH] Expose multi-CV feature downstream --- app/models/concerns/setting_branding.rb | 2 +- app/models/concerns/upstream_only_settings.rb | 11 ++++++++-- test/unit/setting_registry_branding_test.rb | 22 ++++++++++++++++--- 3 files changed, 29 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/setting_branding.rb b/app/models/concerns/setting_branding.rb index 7db923f..64f9189 100644 --- a/app/models/concerns/setting_branding.rb +++ b/app/models/concerns/setting_branding.rb @@ -7,7 +7,7 @@ def replace_keywords(keyword) end def [](name) - if UpstreamOnlySettings::SETTINGS.include?(name.to_s) + if UpstreamOnlySettings.include?(name.to_s) Rails.logger.debug "Setting '#{name}' is not available in Satellite; ignoring" return nil end diff --git a/app/models/concerns/upstream_only_settings.rb b/app/models/concerns/upstream_only_settings.rb index ff14196..4d678be 100644 --- a/app/models/concerns/upstream_only_settings.rb +++ b/app/models/concerns/upstream_only_settings.rb @@ -1,6 +1,13 @@ # Settings to hide in downstream (will return nil for all values) -module UpstreamOnlySettings +class UpstreamOnlySettings SETTINGS = %w[ - allow_multiple_content_views ].freeze + + def self.include?(key) + new.include?(key) + end + + def include?(key) + SETTINGS.include?(key.to_s) + end end diff --git a/test/unit/setting_registry_branding_test.rb b/test/unit/setting_registry_branding_test.rb index c65b6ec..dec921c 100644 --- a/test/unit/setting_registry_branding_test.rb +++ b/test/unit/setting_registry_branding_test.rb @@ -1,6 +1,7 @@ require 'test_plugin_helper' class SettingRegistryBrandingTest < ActiveSupport::TestCase + # rubocop:disable Metrics/BlockLength describe 'stubbed creation' do test 'it replaces value to a branded one using DSL' do Setting.where(name: 'dsl_setting').delete_all @@ -27,14 +28,29 @@ class SettingRegistryBrandingTest < ActiveSupport::TestCase end test 'hides upstream-only settings' do - assert_nil Setting['allow_multiple_content_views'] + Foreman::SettingManager.define('test2') do + category(:Content) do + setting( + :test_setting, + description: N_("Upstream-only setting test"), + default: 'definitely not falsey', + full_name: N_('Upstream-only setting test'), + type: :string + ) + end + end + Foreman.settings.load + UpstreamOnlySettings.expects(:include?).with('test_setting').returns(true) + assert_nil Setting['test_setting'] end end + # rubocop:enable Metrics/BlockLength end class SettingBrandingTest < ActiveSupport::TestCase test 'replaces warning for upstream-only settings' do - Rails.logger.expects(:debug).with('Setting \'allow_multiple_content_views\' is not available in Satellite; ignoring') - Setting['allow_multiple_content_views'] + UpstreamOnlySettings.expects(:include?).with('test_setting').returns(true) + Rails.logger.expects(:debug).with('Setting \'test_setting\' is not available in Satellite; ignoring') + Setting['test_setting'] end end \ No newline at end of file