Sha256: b2252f13bf446536c3489b37e74c7e91d76eb5b1cdf4830f8efeb01849408e05

Contents?: true

Size: 725 Bytes

Versions: 14

Compression:

Stored size: 725 Bytes

Contents

require 'spec_helper'

describe 'Symbol encoding to BSON' do
  let(:value) { :foo }

  let(:hash) do
    {'foo' => value}
  end

  let(:serialized) do
    hash.to_bson.to_s
  end

  let(:expected) do
    "\x12\x00\x00\x00\x0Efoo\x00\x04\x00\x00\x00foo\x00\x00".force_encoding('binary')
  end

  it 'encodes symbol to BSON symbol' do
    serialized.should == expected
  end

  it 'round-trips symbol values' do
    buffer = BSON::ByteBuffer.new(serialized)
    Hash.from_bson(buffer).should == hash
  end

  it 'round-trips symbol values using the same byte buffer' do
    if BSON::Environment.jruby?
      pending 'https://jira.mongodb.org/browse/RUBY-2128'
    end

    Hash.from_bson(hash.to_bson).should == hash
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongo-2.14.0.rc1 spec/integration/bson_symbol_spec.rb
mongo-2.13.1 spec/integration/bson_symbol_spec.rb
mongo-2.12.4 spec/integration/bson_symbol_spec.rb
mongo-2.11.6 spec/integration/bson_symbol_spec.rb
mongo-2.13.0 spec/integration/bson_symbol_spec.rb
mongo-2.12.3 spec/integration/bson_symbol_spec.rb
mongo-2.13.0.rc1 spec/integration/bson_symbol_spec.rb
mongo-2.12.2 spec/integration/bson_symbol_spec.rb
mongo-2.10.5 spec/integration/bson_symbol_spec.rb
mongo-2.11.5 spec/integration/bson_symbol_spec.rb
mongo-2.13.0.beta1 spec/integration/bson_symbol_spec.rb
mongo-2.12.1 spec/integration/bson_symbol_spec.rb
mongo-2.12.0.rc0 spec/integration/bson_symbol_spec.rb
mongo-2.11.4 spec/integration/bson_symbol_spec.rb