RUBY-127
This commit is contained in:
parent
7b89523315
commit
2d160ac602
|
@ -299,10 +299,10 @@ module Mongo
|
|||
selector
|
||||
when nil
|
||||
{}
|
||||
when String
|
||||
{"$where" => Code.new(selector)}
|
||||
when Code
|
||||
when BSON::Code
|
||||
{"$where" => selector}
|
||||
when String
|
||||
{"$where" => BSON::Code.new(selector)}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -469,8 +469,18 @@ class DBAPITest < Test::Unit::TestCase
|
|||
@@coll.insert('a' => 3)
|
||||
|
||||
assert_equal 3, @@coll.count
|
||||
assert_equal 1, @@coll.find('$where' => Code.new('this.a > 2')).count()
|
||||
assert_equal 2, @@coll.find('$where' => Code.new('this.a > i', {'i' => 1})).count()
|
||||
assert_equal 1, @@coll.find('$where' => BSON::Code.new('this.a > 2')).count()
|
||||
assert_equal 2, @@coll.find('$where' => BSON::Code.new('this.a > i', {'i' => 1})).count()
|
||||
end
|
||||
|
||||
def test_implicit_where
|
||||
@@coll.remove
|
||||
@@coll.insert('a' => 2)
|
||||
@@coll.insert('a' => 3)
|
||||
|
||||
assert_equal 2, @@coll.count
|
||||
assert_equal 1, @@coll.find('this.a > 2').count()
|
||||
assert_equal 2, @@coll.find(BSON::Code.new('this.a > z', {'z' => 1})).to_a.length
|
||||
end
|
||||
|
||||
def test_eval
|
||||
|
|
|
@ -98,6 +98,12 @@ class BSONTest < Test::Unit::TestCase
|
|||
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
||||
end
|
||||
|
||||
def test_code_with_scope
|
||||
doc = {'$where' => Code.new('this.a.b < this.b', {'foo' => 1})}
|
||||
bson = BSON::BSON_CODER.serialize(doc)
|
||||
assert_equal doc, BSON::BSON_CODER.deserialize(bson)
|
||||
end
|
||||
|
||||
def test_number
|
||||
doc = {'doc' => 41.99}
|
||||
bson = BSON::BSON_CODER.serialize(doc)
|
||||
|
|
Loading…
Reference in New Issue