mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
Make .excluding work when a nil argument is passed
The change from https://github.com/rails/rails/pull/41465 was a breaking change. Before, `.without` was delegated to `Array` and worked with nil arguments. This change restores that old behavior.
This commit is contained in:
parent
e10e6ab1d4
commit
b19cd20f63
2 changed files with 13 additions and 5 deletions
|
@ -1131,7 +1131,7 @@ module ActiveRecord
|
|||
def excluding(*records)
|
||||
records.flatten!(1)
|
||||
|
||||
if records.any? { |record| !record.is_a?(klass) }
|
||||
if records.compact.any? { |record| !record.is_a?(klass) }
|
||||
raise ArgumentError, "You must only pass a single or collection of #{klass.name} objects to #excluding."
|
||||
end
|
||||
|
||||
|
|
|
@ -46,13 +46,15 @@ class ExcludingTest < ActiveRecord::TestCase
|
|||
end
|
||||
|
||||
def test_does_not_exclude_records_when_no_arguments
|
||||
assert_includes Post.excluding(), posts(:welcome)
|
||||
assert_equal Post.count, Post.excluding().count
|
||||
assert_does_not_exclude_records { Post.excluding() }
|
||||
end
|
||||
|
||||
def test_does_not_exclude_records_with_empty_collection_argument
|
||||
assert_includes Post.excluding([]), posts(:welcome)
|
||||
assert_equal Post.count, Post.excluding([]).count
|
||||
assert_does_not_exclude_records { Post.excluding([]) }
|
||||
end
|
||||
|
||||
def test_does_not_exclude_records_with_a_nil_argument
|
||||
assert_does_not_exclude_records { Post.excluding(nil) }
|
||||
end
|
||||
|
||||
def test_raises_on_record_from_different_class
|
||||
|
@ -70,4 +72,10 @@ class ExcludingTest < ActiveRecord::TestCase
|
|||
|
||||
assert_not_includes Post.without(post).to_a, post
|
||||
end
|
||||
|
||||
private
|
||||
def assert_does_not_exclude_records
|
||||
assert_includes yield, posts(:welcome)
|
||||
assert_equal Post.count, yield.count
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue