Skip to content

Commit

Permalink
raise ArgumentError exception if Model.where.not is called with `…
Browse files Browse the repository at this point in the history
…nil` argument
  • Loading branch information
kuldeepaggarwal committed Dec 29, 2013
1 parent 15e2eb4 commit a2985e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions activerecord/lib/active_record/relation/query_methods.rb
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions activerecord/test/cases/relation/where_chain_test.rb
Expand Up @@ -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])
Expand Down

0 comments on commit a2985e2

Please sign in to comment.