Skip to content

Commit efdc20f

Browse files
committed
Remove deprecated access to connection specification using a string acessor.
Now all strings will be handled as a URL.
1 parent a939506 commit efdc20f

3 files changed

Lines changed: 7 additions & 58 deletions

File tree

activerecord/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
* Remove deprecated access to connection specification using a string acessor.
2+
3+
Now all strings will be handled as a URL.
4+
5+
*Rafael Mendonça França*
6+
17
* Change the default `null` value for `timestamps` to `false`.
28

39
*Rafael Mendonça França*

activerecord/lib/active_record/connection_adapters/connection_specification.rb

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
require 'uri'
2-
require 'active_support/core_ext/string/filters'
32

43
module ActiveRecord
54
module ConnectionAdapters
@@ -210,30 +209,12 @@ def resolve_connection(spec)
210209
when Symbol
211210
resolve_symbol_connection spec
212211
when String
213-
resolve_string_connection spec
212+
resolve_url_connection spec
214213
when Hash
215214
resolve_hash_connection spec
216215
end
217216
end
218217

219-
def resolve_string_connection(spec)
220-
# Rails has historically accepted a string to mean either
221-
# an environment key or a URL spec, so we have deprecated
222-
# this ambiguous behaviour and in the future this function
223-
# can be removed in favor of resolve_url_connection.
224-
if configurations.key?(spec) || spec !~ /:/
225-
ActiveSupport::Deprecation.warn(<<-MSG.squish)
226-
Passing a string to ActiveRecord::Base.establish_connection for a
227-
configuration lookup is deprecated, please pass a symbol
228-
(#{spec.to_sym.inspect}) instead.
229-
MSG
230-
231-
resolve_symbol_connection(spec)
232-
else
233-
resolve_url_connection(spec)
234-
end
235-
end
236-
237218
# Takes the environment such as +:production+ or +:development+.
238219
# This requires that the @configurations was initialized with a key that
239220
# matches.

activerecord/test/cases/connection_adapters/merge_and_resolve_default_url_config_test.rb

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,34 +51,6 @@ def test_resolver_with_database_uri_and_current_env_symbol_key_and_rack_env
5151
assert_equal expected, actual
5252
end
5353

54-
def test_resolver_with_database_uri_and_and_current_env_string_key
55-
ENV['DATABASE_URL'] = "postgres://localhost/foo"
56-
config = { "default_env" => { "adapter" => "not_postgres", "database" => "not_foo" } }
57-
actual = assert_deprecated { resolve_spec("default_env", config) }
58-
expected = { "adapter"=>"postgresql", "database"=>"foo", "host"=>"localhost" }
59-
assert_equal expected, actual
60-
end
61-
62-
def test_resolver_with_database_uri_and_and_current_env_string_key_and_rails_env
63-
ENV['DATABASE_URL'] = "postgres://localhost/foo"
64-
ENV['RAILS_ENV'] = "foo"
65-
66-
config = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } }
67-
actual = assert_deprecated { resolve_spec("foo", config) }
68-
expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
69-
assert_equal expected, actual
70-
end
71-
72-
def test_resolver_with_database_uri_and_and_current_env_string_key_and_rack_env
73-
ENV['DATABASE_URL'] = "postgres://localhost/foo"
74-
ENV['RACK_ENV'] = "foo"
75-
76-
config = { "not_production" => {"adapter" => "not_postgres", "database" => "not_foo" } }
77-
actual = assert_deprecated { resolve_spec("foo", config) }
78-
expected = { "adapter" => "postgresql", "database" => "foo", "host" => "localhost" }
79-
assert_equal expected, actual
80-
end
81-
8254
def test_resolver_with_database_uri_and_known_key
8355
ENV['DATABASE_URL'] = "postgres://localhost/foo"
8456
config = { "production" => { "adapter" => "not_postgres", "database" => "not_foo", "host" => "localhost" } }
@@ -95,16 +67,6 @@ def test_resolver_with_database_uri_and_unknown_symbol_key
9567
end
9668
end
9769

98-
def test_resolver_with_database_uri_and_unknown_string_key
99-
ENV['DATABASE_URL'] = "postgres://localhost/foo"
100-
config = { "not_production" => { "adapter" => "not_postgres", "database" => "not_foo" } }
101-
assert_deprecated do
102-
assert_raises AdapterNotSpecified do
103-
resolve_spec("production", config)
104-
end
105-
end
106-
end
107-
10870
def test_resolver_with_database_uri_and_supplied_url
10971
ENV['DATABASE_URL'] = "not-postgres://not-localhost/not_foo"
11072
config = { "production" => { "adapter" => "also_not_postgres", "database" => "also_not_foo" } }

0 commit comments

Comments
 (0)