1
0
Fork 0
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:
Kuldeep Aggarwal 2013-12-30 01:53:02 +05:30
parent 15e2eb42a7
commit a2985e2067
2 changed files with 8 additions and 0 deletions

View file

@ -37,6 +37,8 @@ module ActiveRecord
def not(opts, *rest)
where_value = @scope.send(:build_where, opts, rest).map do |rel|
case rel
when NilClass
raise ArgumentError, 'Invalid argument for .where.not(), got nil.'
when Arel::Nodes::In
Arel::Nodes::NotIn.new(rel.left, rel.right)
when Arel::Nodes::Equality

View file

@ -23,6 +23,12 @@ module ActiveRecord
assert_equal([expected], relation.where_values)
end
def test_not_with_nil
assert_raise ArgumentError do
Post.where.not(nil)
end
end
def test_not_in
expected = Arel::Nodes::NotIn.new(Post.arel_table[@name], %w[hello goodbye])
relation = Post.where.not(title: %w[hello goodbye])