-
Type: Task
-
Resolution: Done
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: None
If we do
class Test include Mongoid::Document field :foo end Test.create foo: 3 Test.where({a: 3}).first.matches?({ a: { '$lt' => '3.1' }})
If the type of value for foo is provided by a 3rd party and therefore unknown this is a perfectly valid question. However we get "ArgumentError: comparison of Fixnum with String failed". When the result should be false.
I am currently getting around this with the following monkey patch:
# encoding: utf-8 module Mongoid module Matchable class Default protected def determine(value, operator) attribute.__array__.any? {|attr| begin attr ? attr.send(operator, first(value)) : false rescue ArgumentError false end } end end end end
Happy to write up tests and provide a PR, but wanted to open for discussion first. IE does rescue ArgumentError catch anything that it shouldn't?