RUBY-222 BSON::Code must be a string.
This commit is contained in:
parent
65f59ba2d6
commit
bcb37e62c7
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue