From 26ab0ad34be5c0b18b2164e6c22d04b5c18d1015 Mon Sep 17 00:00:00 2001 From: John Hawthorn Date: Wed, 7 Aug 2019 14:51:26 -0700 Subject: [PATCH] Merge pull request #36848 from jhawthorn/type_error_on_resolve_connection Raise TypeError instead of infinite loop in resolve_connection --- .../connection_adapters/connection_specification.rb | 2 +- .../test/cases/connection_specification/resolver_test.rb | 6 ++++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/activerecord/lib/active_record/connection_adapters/connection_specification.rb b/activerecord/lib/active_record/connection_adapters/connection_specification.rb index 9eaf9d9a894b8..bbc10f6625505 100644 --- a/activerecord/lib/active_record/connection_adapters/connection_specification.rb +++ b/activerecord/lib/active_record/connection_adapters/connection_specification.rb @@ -222,7 +222,7 @@ def resolve_connection(config_or_env, pool_name = nil) when Hash resolve_hash_connection config_or_env else - resolve_connection config_or_env + raise TypeError, "Invalid type for configuration. Expected Symbol, String, or Hash. Got #{config_or_env.inspect}" end end diff --git a/activerecord/test/cases/connection_specification/resolver_test.rb b/activerecord/test/cases/connection_specification/resolver_test.rb index 72be14f507780..a9aaf15099c9e 100644 --- a/activerecord/test/cases/connection_specification/resolver_test.rb +++ b/activerecord/test/cases/connection_specification/resolver_test.rb @@ -135,6 +135,12 @@ def test_spec_name_with_inline_config spec = spec("adapter" => "sqlite3") assert_equal "primary", spec.name, "should default to primary id" end + + def test_spec_with_invalid_type + assert_raises TypeError do + spec(Object.new) + end + end end end end