Skip to content
This repository has been archived by the owner on Dec 22, 2020. It is now read-only.

Commit

Permalink
Implement BSON::DBRef support.
Browse files Browse the repository at this point in the history
closes #50
  • Loading branch information
nelhage-stripe committed Aug 11, 2014
1 parent 2e86950 commit 8043b96
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mosql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,8 @@ def transform(ns, obj, schema=nil)
case v
when BSON::Binary, BSON::ObjectId, Symbol
v = v.to_s
when BSON::DBRef
v = v.object_id.to_s
when Hash
v = JSON.dump(v)
when Array
Expand Down
7 changes: 7 additions & 0 deletions test/unit/lib/mosql/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,13 @@ class MoSQL::Test::SchemaTest < MoSQL::Test
assert_equal(["row 1", nil, 'stringy', [1,2,3]], out)
end

it 'extracts object ids from a DBRef' do
oid = BSON::ObjectId.new
out = @map.transform('db.collection', {'_id' => "row 1",
'str' => BSON::DBRef.new('db.otherns', oid)})
assert_equal(["row 1", nil, oid.to_s, nil], out)
end

it 'changes NaN to null in extra_props' do
out = @map.transform('db.with_extra_props', {'_id' => 7, 'nancy' => 0.0/0.0})
extra = JSON.parse(out[1])
Expand Down

0 comments on commit 8043b96

Please sign in to comment.