Sha256: b0606bc1abd9a7739b3265b70becc0b788b57be52f66f571f6e812869446a8e8

Contents?: true

Size: 1.01 KB

Versions: 18

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true
# encoding: utf-8

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? && (BSON::VERSION.split('.').map(&:to_i) <=> [4, 11, 0]) < 0
      skip 'This test is only relevant to bson versions that increment ByteBuffer '\
       'read and write positions separately in JRuby, as implemented in ' \
       'bson version 4.11.0. For more information, see https://jira.mongodb.org/browse/RUBY-2128'
    end

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

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mongo-2.16.4 spec/integration/bson_symbol_spec.rb
mongo-2.17.4 spec/integration/bson_symbol_spec.rb
mongo-2.18.3 spec/integration/bson_symbol_spec.rb
mongo-2.18.2 spec/integration/bson_symbol_spec.rb
mongo-2.17.3 spec/integration/bson_symbol_spec.rb
mongo-2.18.1 spec/integration/bson_symbol_spec.rb
mongo-2.18.0 spec/integration/bson_symbol_spec.rb
mongo-2.17.2 spec/integration/bson_symbol_spec.rb
mongo-2.16.3 spec/integration/bson_symbol_spec.rb
mongo-2.18.0.beta1 spec/integration/bson_symbol_spec.rb
mongo-2.16.2 spec/integration/bson_symbol_spec.rb
mongo-2.17.1 spec/integration/bson_symbol_spec.rb
mongo-2.16.1 spec/integration/bson_symbol_spec.rb
mongo-2.17.0 spec/integration/bson_symbol_spec.rb
mongo-2.16.0 spec/integration/bson_symbol_spec.rb
mongo-2.15.1 spec/integration/bson_symbol_spec.rb
mongo-2.16.0.alpha1 spec/integration/bson_symbol_spec.rb
mongo-2.15.0 spec/integration/bson_symbol_spec.rb