Skip to content

Commit 3d9a0dd

Browse files
p-mongop
andcommitted
RUBY-2123 Add test coverage for symbol round-tripping in Hash field values (#1681)
* RUBY-2123 Add test coverage for symbol round-tripping in Hash field values * RUBY-2128 fix the test on JRuby Co-authored-by: Oleg Pudeyev <[email protected]>
1 parent d1bcb41 commit 3d9a0dd

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed

spec/integration/bson_symbol_spec.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
require 'spec_helper'
2+
3+
describe 'Symbol encoding to BSON' do
4+
let(:value) { :foo }
5+
6+
let(:hash) do
7+
{'foo' => value}
8+
end
9+
10+
let(:serialized) do
11+
hash.to_bson.to_s
12+
end
13+
14+
let(:expected) do
15+
"\x12\x00\x00\x00\x0Efoo\x00\x04\x00\x00\x00foo\x00\x00".force_encoding('binary')
16+
end
17+
18+
it 'encodes symbol to BSON symbol' do
19+
serialized.should == expected
20+
end
21+
22+
it 'round-trips symbol values' do
23+
buffer = BSON::ByteBuffer.new(serialized)
24+
Hash.from_bson(buffer).should == hash
25+
end
26+
27+
it 'round-trips symbol values using the same byte buffer' do
28+
if BSON::Environment.jruby?
29+
pending 'https://jira.mongodb.org/browse/RUBY-2128'
30+
end
31+
32+
Hash.from_bson(hash.to_bson).should == hash
33+
end
34+
end

0 commit comments

Comments
 (0)