Permalink
Browse files

Return false when matching an empty array.

Fixes #1950.
  • Loading branch information...
i0rek committed Apr 26, 2012
1 parent e4fa046 commit b2677d4ae0d1021317510cce39cd973b137316d1
Showing with 10 additions and 1 deletion.
  1. +4 −1 lib/mongoid/matchers/all.rb
  2. +6 −0 spec/mongoid/matchers/all_spec.rb
@@ -14,8 +14,11 @@ class All < Default
#
# @return [ true, false ] If the values match.
def matches?(value)
+ first = first(value)
+ return false if first.is_a?(Array) && first.empty?
+
attribute_array = Array.wrap(@attribute)
- first(value).all? do |e|
+ first.all? do |e|
attribute_array.any? { |_attribute| e === _attribute }
end
end
@@ -21,5 +21,11 @@
matcher.matches?("$all" => ["second", "third", "fourth"]).should be_false
end
end
+
+ context "when the value is empty" do
+ it "returns false" do
+ matcher.matches?("$all" => []).should be_false
+ end
+ end
end
end

0 comments on commit b2677d4

Please sign in to comment.