From 7453f9a2caa16b471a29339886ca7893a5f0a4ee Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Tue, 26 Dec 2023 21:31:42 -0800 Subject: [PATCH] Only use a default for the shared config --- lib/kredis/connections.rb | 4 +++- test/connections_test.rb | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/kredis/connections.rb b/lib/kredis/connections.rb index 2f1e0ab..d6af252 100644 --- a/lib/kredis/connections.rb +++ b/lib/kredis/connections.rb @@ -14,8 +14,10 @@ def configured_for(name) connections[name] ||= Kredis.instrument :meta, message: "Connected to #{name}" do if configurator.root.join("config/redis/#{name}.yml").exist? connector.call configurator.config_for("redis/#{name}") - else + elsif name == :shared Redis.new url: ENV.fetch("REDIS_URL", DEFAULT_REDIS_URL), timeout: DEFAULT_REDIS_TIMEOUT + else + raise "No configuration found for #{name}" end end end diff --git a/test/connections_test.rb b/test/connections_test.rb index a9cf51b..3f23678 100644 --- a/test/connections_test.rb +++ b/test/connections_test.rb @@ -49,4 +49,10 @@ class ConnectionsTest < ActiveSupport::TestCase test "default config without env" do assert_match %r|redis://127.0.0.1:6379/0|, Kredis.redis.inspect end + + test "custom config is missing" do + assert_raises do + Kredis.configured_for(:missing).set "mykey", "won't get set" + end + end end