Don't return the same object when using find with an empty array

When you pass an empty array to find we know we shoudl return an empty
array but it is surprising that we are returning the original empty
array instead of a new one.
上级 c0ed2d29
......@@ -417,7 +417,7 @@ def find_with_ids(*ids)
raise UnknownPrimaryKey.new(@klass) if primary_key.nil?
expects_array = ids.first.kind_of?(Array)
return ids.first if expects_array && ids.first.empty?
return [] if expects_array && ids.first.empty?
ids = ids.flatten.compact.uniq
......
......@@ -365,7 +365,10 @@ def test_find_by_bang_on_relation_with_large_number
end
def test_find_an_empty_array
assert_equal [], Topic.find([])
empty_array = []
result = Topic.find(empty_array)
assert_equal [], result
assert_not_same empty_array, result
end
def test_find_doesnt_have_implicit_ordering
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册