Skip to content

Commit

Permalink
$all tests
Browse files Browse the repository at this point in the history
  • Loading branch information
p committed Jul 15, 2020
1 parent f555ee7 commit 5be3d8b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/mongoid/matcher/all.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module All
raise Errors::InvalidQuery, "$all argument must be an array: #{Errors::InvalidQuery.truncate_expr(condition)}"
end

condition.any? && condition.all? do |c|
!condition.empty? && condition.all? do |c|
case c
when ::Regexp, BSON::Regexp::Raw
Regex.matches_array_or_scalar?(value, c)
Expand Down
24 changes: 24 additions & 0 deletions spec/integration/matcher_operator_data/all.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,27 @@
$all:
ceo
error: true

- name: field value is null
document:
products: ~
query:
products:
$all: [1, 2]
matches: false

- name: field value is numeric
document:
products: 42
query:
products:
$all: [42]
matches: true

- name: field value is null and query is for null value
document:
products: ~
query:
products:
$all: [~]
matches: true
8 changes: 8 additions & 0 deletions spec/integration/matcher_operator_data/eq.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,3 +181,11 @@
positions:
$eq: ~
matches: false

- name: null field value vs nil argument
document:
positions: ~
query:
positions:
$eq: ~
matches: true

0 comments on commit 5be3d8b

Please sign in to comment.