未验证 提交 59c39f21 编写于 作者: R Ryuta Kamizono 提交者: GitHub

Merge pull request #39589 from kamipo/deprecate_map_bang

Deprecate `map!` and `collect!` on `ActiveRecord::Result`
* Deprecate `map!` and `collect!` on `ActiveRecord::Result`.
*Ryuta Kamizono*
* Support `relation.and` for intersection as Set theory.
```ruby
......
......@@ -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
......
......@@ -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?
......
......@@ -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")
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册