mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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.
This commit is contained in:
parent
1b90f614b1
commit
e184d1a94e
2 changed files with 5 additions and 2 deletions
|
@ -416,7 +416,7 @@ module ActiveRecord
|
|||
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
|
||||
|
||||
|
|
|
@ -371,7 +371,10 @@ class FinderTest < ActiveRecord::TestCase
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue