RUBY-222 BSON::Code must be a string.

This commit is contained in:
Kyle Banker 2011-01-06 10:11:15 -05:00
parent 65f59ba2d6
commit bcb37e62c7
2 changed files with 10 additions and 0 deletions

View File

@ -32,6 +32,10 @@ module BSON
def initialize(code, scope={}) def initialize(code, scope={})
@code = code @code = code
@scope = scope @scope = scope
unless @code.is_a?(String)
raise ArgumentError, "BSON::Code must be in the form of a String; #{@code.class} is not allowed."
end
end end
def length def length

View File

@ -150,6 +150,12 @@ class BSONTest < Test::Unit::TestCase
assert_doc_pass(doc) assert_doc_pass(doc)
end end
def test_code_with_symbol
assert_raise_error ArgumentError, "BSON::Code must be in the form of a String" do
Code.new(:fubar)
end
end
def test_code_with_scope def test_code_with_scope
doc = {'$where' => Code.new('this.a.b < this.b', {'foo' => 1})} doc = {'$where' => Code.new('this.a.b < this.b', {'foo' => 1})}
assert_doc_pass(doc) assert_doc_pass(doc)