diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index adc49c8929..a9d9285d42 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,13 @@ +* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`. + + `fetch` + `each` + `first` + `values` + `[]=` + + *Rafael Mendonça França* + * `where.not` now generates NAND predicates instead of NOR. Before: diff --git a/activerecord/lib/active_record/database_configurations.rb b/activerecord/lib/active_record/database_configurations.rb index 807d164394..c33f33a75e 100644 --- a/activerecord/lib/active_record/database_configurations.rb +++ b/activerecord/lib/active_record/database_configurations.rb @@ -116,19 +116,6 @@ module ActiveRecord end alias :blank? :empty? - def each - throw_getter_deprecation(:each) - configurations.each { |config| - yield [config.env_name, config.configuration_hash] - } - end - - def first - throw_getter_deprecation(:first) - config = configurations.first - [config.env_name, config.configuration_hash] - end - # Returns fully resolved connection, accepts hash, string or symbol. # Always returns a DatabaseConfiguration::DatabaseConfig # @@ -281,37 +268,5 @@ module ActiveRecord url ||= ENV["DATABASE_URL"] if name == "primary" url end - - def method_missing(method, *args, &blk) - case method - when :fetch - throw_getter_deprecation(method) - configs_for(env_name: args.first) - when :values - throw_getter_deprecation(method) - configurations.map(&:configuration_hash) - when :[]= - throw_setter_deprecation(method) - - env_name = args[0] - config = args[1] - - remaining_configs = configurations.reject { |db_config| db_config.env_name == env_name } - new_config = build_configs(env_name => config) - new_configs = remaining_configs + new_config - - ActiveRecord::Base.configurations = new_configs - else - raise NotImplementedError, "`ActiveRecord::Base.configurations` in Rails 6 now returns an object instead of a hash. The `#{method}` method is not supported. Please use `configs_for` or consult the documentation for supported methods." - end - end - - def throw_setter_deprecation(method) - ActiveSupport::Deprecation.warn("Setting `ActiveRecord::Base.configurations` with `#{method}` is deprecated. Use `ActiveRecord::Base.configurations=` directly to set the configurations instead.") - end - - def throw_getter_deprecation(method) - ActiveSupport::Deprecation.warn("`ActiveRecord::Base.configurations` no longer returns a hash. Methods that act on the hash like `#{method}` are deprecated and will be removed in Rails 6.1. Use the `configs_for` method to collect and iterate over the database configurations.") - end end end diff --git a/activerecord/test/cases/database_configurations_test.rb b/activerecord/test/cases/database_configurations_test.rb index fffa88183f..9e2bd5a165 100644 --- a/activerecord/test/cases/database_configurations_test.rb +++ b/activerecord/test/cases/database_configurations_test.rb @@ -108,22 +108,6 @@ class DatabaseConfigurationsTest < ActiveRecord::TestCase end class LegacyDatabaseConfigurationsTest < ActiveRecord::TestCase - unless in_memory_db? - def test_setting_configurations_hash - old_config = ActiveRecord::Base.configurations - config = { "adapter" => "sqlite3" } - - assert_deprecated do - ActiveRecord::Base.configurations["readonly"] = config - end - - assert_equal ["arunit", "arunit2", "arunit_without_prepared_statements", "readonly"], ActiveRecord::Base.configurations.configs_for.map(&:env_name).sort - ensure - ActiveRecord::Base.configurations = old_config - ActiveRecord::Base.establish_connection :arunit - end - end - def test_can_turn_configurations_into_a_hash_and_is_deprecated assert_deprecated do assert ActiveRecord::Base.configurations.to_h.is_a?(Hash), "expected to be a hash but was not." @@ -131,40 +115,6 @@ class LegacyDatabaseConfigurationsTest < ActiveRecord::TestCase end end - def test_each_is_deprecated - assert_deprecated do - all_configs = ActiveRecord::Base.configurations.values - ActiveRecord::Base.configurations.each do |env_name, config| - assert_includes ["arunit", "arunit2", "arunit_without_prepared_statements"], env_name - assert_includes all_configs, config - end - end - end - - def test_first_is_deprecated - first_config = ActiveRecord::Base.configurations.configurations.map(&:configuration_hash).first - assert_deprecated do - env_name, config = ActiveRecord::Base.configurations.first - assert_equal "arunit", env_name - assert_equal first_config, config - end - end - - def test_fetch_is_deprecated - assert_deprecated do - db_config = ActiveRecord::Base.configurations.fetch("arunit").first - assert_equal "arunit", db_config.env_name - assert_equal "primary", db_config.name - end - end - - def test_values_are_deprecated - config_hashes = ActiveRecord::Base.configurations.configurations.map(&:configuration_hash) - assert_deprecated do - assert_equal config_hashes, ActiveRecord::Base.configurations.values - end - end - def test_deprecated_config_method db_config = ActiveRecord::Base.configurations.configs_for(env_name: "arunit", name: "primary") @@ -172,8 +122,8 @@ class LegacyDatabaseConfigurationsTest < ActiveRecord::TestCase end def test_unsupported_method_raises - assert_raises NotImplementedError do - ActiveRecord::Base.configurations.select { |a| a == "foo" } + assert_raises NoMethodError do + ActiveRecord::Base.configurations.fetch(:foo) end end diff --git a/guides/source/6_1_release_notes.md b/guides/source/6_1_release_notes.md index caae54a853..f575acd0e7 100644 --- a/guides/source/6_1_release_notes.md +++ b/guides/source/6_1_release_notes.md @@ -149,6 +149,14 @@ Please refer to the [Changelog][active-record] for detailed changes. ### Removals +* Remove deprecated methods from `ActiveRecord::DatabaseConfigurations`. + + `fetch` + `each` + `first` + `values` + `[]=` + * Remove deprecated `ActiveRecord::Result#to_hash` method. * Remove deprecated support for using unsafe raw SQL in `ActiveRecord::Relation` methods.