mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
raise ArgumentError
exception if Model.where.not
is called with nil
argument
This commit is contained in:
parent
15e2eb42a7
commit
a2985e2067
2 changed files with 8 additions and 0 deletions
|
@ -37,6 +37,8 @@ module ActiveRecord
|
||||||
def not(opts, *rest)
|
def not(opts, *rest)
|
||||||
where_value = @scope.send(:build_where, opts, rest).map do |rel|
|
where_value = @scope.send(:build_where, opts, rest).map do |rel|
|
||||||
case rel
|
case rel
|
||||||
|
when NilClass
|
||||||
|
raise ArgumentError, 'Invalid argument for .where.not(), got nil.'
|
||||||
when Arel::Nodes::In
|
when Arel::Nodes::In
|
||||||
Arel::Nodes::NotIn.new(rel.left, rel.right)
|
Arel::Nodes::NotIn.new(rel.left, rel.right)
|
||||||
when Arel::Nodes::Equality
|
when Arel::Nodes::Equality
|
||||||
|
|
|
@ -23,6 +23,12 @@ module ActiveRecord
|
||||||
assert_equal([expected], relation.where_values)
|
assert_equal([expected], relation.where_values)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_not_with_nil
|
||||||
|
assert_raise ArgumentError do
|
||||||
|
Post.where.not(nil)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def test_not_in
|
def test_not_in
|
||||||
expected = Arel::Nodes::NotIn.new(Post.arel_table[@name], %w[hello goodbye])
|
expected = Arel::Nodes::NotIn.new(Post.arel_table[@name], %w[hello goodbye])
|
||||||
relation = Post.where.not(title: %w[hello goodbye])
|
relation = Post.where.not(title: %w[hello goodbye])
|
||||||
|
|
Loading…
Reference in a new issue