Skip to content
Browse files

raise `ArgumentError` exception if `Model.where.not` is called with `…

…nil` argument
  • Loading branch information...
1 parent 15e2eb4 commit a2985e206709f7947ef427a527d72ff89824931a @kuldeepaggarwal kuldeepaggarwal committed
View
2 activerecord/lib/active_record/relation/query_methods.rb
@@ -37,6 +37,8 @@ def initialize(scope)
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
6 activerecord/test/cases/relation/where_chain_test.rb
@@ -23,6 +23,12 @@ def test_not_null
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])

0 comments on commit a2985e2

Please sign in to comment.
Something went wrong with that request. Please try again.