From ae9eb20eb3e95a1fddea07aa8108f379fff5dcf6 Mon Sep 17 00:00:00 2001 From: Beth Skurrie Date: Mon, 21 Mar 2022 15:53:29 +1100 Subject: [PATCH] chore: remove unused configuration overriding code --- lib/pact_broker/configuration.rb | 12 ------ spec/lib/pact_broker/configuration_spec.rb | 43 +++++++++------------- 2 files changed, 18 insertions(+), 37 deletions(-) diff --git a/lib/pact_broker/configuration.rb b/lib/pact_broker/configuration.rb index e534577cf..07a145c9b 100644 --- a/lib/pact_broker/configuration.rb +++ b/lib/pact_broker/configuration.rb @@ -15,10 +15,6 @@ def self.set_configuration(configuration) RequestStore.store[:pact_broker_configuration] = configuration end - def self.with_runtime_configuration_overrides(overrides, &block) - self.configuration.with_runtime_configuration_overrides(overrides, &block) - end - # @private, for testing only def self.reset_configuration RequestStore.store[:pact_broker_configuration] = Configuration.default_configuration @@ -82,14 +78,6 @@ def self.default_configuration config end - def with_runtime_configuration_overrides(overrides) - original_runtime_configuration = runtime_configuration - self.runtime_configuration = override_runtime_configuration!(overrides) - yield - ensure - self.runtime_configuration = original_runtime_configuration - end - def override_runtime_configuration!(overrides) new_runtime_configuration = runtime_configuration.dup valid_overrides = {} diff --git a/spec/lib/pact_broker/configuration_spec.rb b/spec/lib/pact_broker/configuration_spec.rb index 5cada0050..50fe28c24 100644 --- a/spec/lib/pact_broker/configuration_spec.rb +++ b/spec/lib/pact_broker/configuration_spec.rb @@ -35,49 +35,42 @@ module PactBroker end end - describe "with_runtime_configuration_overrides" do + describe "override_runtime_configuration!" do before do - allow(PactBroker.configuration).to receive(:logger).and_return(logger) + allow(duped_config).to receive(:logger).and_return(logger) end let(:logger) { double("logger", debug?: true, debug: nil, warn: nil) } + let(:duped_config) { PactBroker.configuration.dup } + it "overrides the specified runtime configuration attributes within the block" do - attribute_in_block = nil - PactBroker.with_runtime_configuration_overrides(disable_ssl_verification: "true") do - attribute_in_block = PactBroker.configuration.disable_ssl_verification - end - expect(attribute_in_block).to eq true + duped_config.override_runtime_configuration!(disable_ssl_verification: "true") + expect(duped_config.disable_ssl_verification).to eq true expect(PactBroker.configuration.disable_ssl_verification).to eq false end it "logs the overrides at debug level" do expect(logger).to receive(:debug).with("Overridding runtime configuration", payload: hash_including(overrides: { disable_ssl_verification: true })) - PactBroker.with_runtime_configuration_overrides(disable_ssl_verification: "true") do - "foo" - end + duped_config.override_runtime_configuration!(disable_ssl_verification: "true") end it "does not override the other runtime configuration attributes within the block" do - attribute_in_block = nil - PactBroker.with_runtime_configuration_overrides(disable_ssl_verification: "true") do - attribute_in_block = PactBroker.configuration.webhook_scheme_whitelist - end - expect(PactBroker.configuration.webhook_scheme_whitelist).to eq attribute_in_block - end - - it "returns the results of the block" do - return_value = PactBroker.with_runtime_configuration_overrides(disable_ssl_verification: "true") do - "foo" - end - expect(return_value).to eq "foo" + attribute_in_block = PactBroker.configuration.webhook_scheme_whitelist + duped_config.override_runtime_configuration!(disable_ssl_verification: "true") + expect(duped_config.webhook_scheme_whitelist).to eq attribute_in_block end context "when the specified runtime attribute does not exist" do it "logs that it has ignored those attributes" do expect(logger).to receive(:debug).with("Overridding runtime configuration", payload: hash_including(ignoring: { no_existy: true })) - PactBroker.with_runtime_configuration_overrides(no_existy: "true") do - "foo" - end + duped_config.override_runtime_configuration!(no_existy: "true") + end + end + + context "when the configuration is frozen" do + it "raises an error" do + duped_config.freeze + expect { duped_config.override_runtime_configuration!(disable_ssl_verification: "true") }.to raise_error FrozenError end end end