1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Merge pull request #13534 from kuldeepaggarwal/f-where-not

raise ArgumentError for nil in .where.not
This commit is contained in:
José Valim 2013-12-29 12:25:21 -08:00
commit 524ad8f572
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])