1
0
Fork 0
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:
Rafael Mendonça França 2018-09-19 14:31:12 -04:00
parent 1b90f614b1
commit e184d1a94e
No known key found for this signature in database
GPG key ID: FC23B6D0F1EEE948
2 changed files with 5 additions and 2 deletions

View file

@ -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

View file

@ -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