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:
commit
524ad8f572
2 changed files with 8 additions and 0 deletions
|
@ -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
|
||||
|
|
|
@ -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])
|
||||
|
|
Loading…
Reference in a new issue