2010-10-07 21:05:45 +00:00
|
|
|
# encoding:utf-8
|
2011-08-09 22:00:03 +00:00
|
|
|
require './test/bson/test_helper'
|
2012-03-30 15:47:06 +00:00
|
|
|
require './test/support/hash_with_indifferent_access'
|
2010-10-07 21:05:45 +00:00
|
|
|
|
|
|
|
class HashWithIndifferentAccessTest < Test::Unit::TestCase
|
|
|
|
include BSON
|
|
|
|
|
|
|
|
def setup
|
|
|
|
@encoder = BSON::BSON_CODER
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_document
|
|
|
|
doc = HashWithIndifferentAccess.new
|
|
|
|
doc['foo'] = 1
|
|
|
|
doc['bar'] = 'baz'
|
|
|
|
|
|
|
|
bson = @encoder.serialize(doc)
|
|
|
|
assert_equal doc, @encoder.deserialize(bson.to_s)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_embedded_document
|
|
|
|
jimmy = HashWithIndifferentAccess.new
|
|
|
|
jimmy['name'] = 'Jimmy'
|
|
|
|
jimmy['species'] = 'Siberian Husky'
|
|
|
|
|
|
|
|
stats = HashWithIndifferentAccess.new
|
|
|
|
stats['eyes'] = 'blue'
|
|
|
|
|
|
|
|
person = HashWithIndifferentAccess.new
|
|
|
|
person['_id'] = BSON::ObjectId.new
|
|
|
|
person['name'] = 'Mr. Pet Lover'
|
|
|
|
person['pets'] = [jimmy, {'name' => 'Sasha'}]
|
|
|
|
person['stats'] = stats
|
|
|
|
|
|
|
|
bson = @encoder.serialize(person)
|
|
|
|
assert_equal person, @encoder.deserialize(bson.to_s)
|
|
|
|
end
|
|
|
|
end
|