This commit is contained in:
Kyle Banker 2010-05-06 22:05:01 -04:00
parent 7b89523315
commit 2d160ac602
3 changed files with 21 additions and 5 deletions

View File

@ -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

View File

@ -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

View File

@ -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)