diff --git a/activerecord/CHANGELOG.md b/activerecord/CHANGELOG.md index 1234bb9a15d4dff99ec46f2247c16c9be667d0d7..c5945f3c3a169d25da7b62c2a21fd75c3fd6b6bc 100644 --- a/activerecord/CHANGELOG.md +++ b/activerecord/CHANGELOG.md @@ -1,3 +1,7 @@ +* Deprecate `map!` and `collect!` on `ActiveRecord::Result`. + + *Ryuta Kamizono* + * Support `relation.and` for intersection as Set theory. ```ruby diff --git a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb index e016a6f032598a922d4765a8f662c9c10a1a82f3..0dcc8fd9f31a75b0e3bd7343b3dfa50da6044ce7 100644 --- a/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/sqlite3_adapter.rb @@ -518,7 +518,7 @@ def table_structure_with_collation(table_name, basic_structure) collation_hash[$1] = $2 if COLLATE_REGEX =~ column_string end - basic_structure.map! do |column| + basic_structure.map do |column| column_name = column["name"] if collation_hash.has_key? column_name diff --git a/activerecord/lib/active_record/result.rb b/activerecord/lib/active_record/result.rb index 7e15a8e8e5d7a9452d190bee4ab88ecbc3073617..e0710266b4fbde346e301442c54300fbabfca9fc 100644 --- a/activerecord/lib/active_record/result.rb +++ b/activerecord/lib/active_record/result.rb @@ -75,6 +75,8 @@ def to_hash alias :map! :map alias :collect! :map + deprecate "map!": :map + deprecate "collect!": :map # Returns true if there are no records, otherwise false. def empty? diff --git a/activerecord/test/cases/result_test.rb b/activerecord/test/cases/result_test.rb index 4ac2097734af304994da2655d794d19d9508f90a..cf3da5b62efa7326b389c98aae969f90628ae598 100644 --- a/activerecord/test/cases/result_test.rb +++ b/activerecord/test/cases/result_test.rb @@ -12,6 +12,28 @@ def result ]) end + test "map! is deprecated" do + assert_deprecated do + result.map! { nil } + end + assert_equal [ + { "col_1" => "row 1 col 1", "col_2" => "row 1 col 2" }, + { "col_1" => "row 2 col 1", "col_2" => "row 2 col 2" }, + { "col_1" => "row 3 col 1", "col_2" => "row 3 col 2" }, + ], result.to_a + end + + test "collect! is deprecated" do + assert_deprecated do + result.collect! { nil } + end + assert_equal [ + { "col_1" => "row 1 col 1", "col_2" => "row 1 col 2" }, + { "col_1" => "row 2 col 1", "col_2" => "row 2 col 2" }, + { "col_1" => "row 3 col 1", "col_2" => "row 3 col 2" }, + ], result.to_a + end + test "includes_column?" do assert result.includes_column?("col_1") assert_not result.includes_column?("foo")