From c984f437919161df99f26453fb45efbd5a9b4887 Mon Sep 17 00:00:00 2001 From: Emily Date: Thu, 28 Jan 2016 13:37:59 +0100 Subject: [PATCH] Add spec for java ext ByteBuf rewind! bug in previous commit --- spec/bson/byte_buffer_spec.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/spec/bson/byte_buffer_spec.rb b/spec/bson/byte_buffer_spec.rb index b23e5551e..f999d60e6 100644 --- a/spec/bson/byte_buffer_spec.rb +++ b/spec/bson/byte_buffer_spec.rb @@ -486,5 +486,28 @@ it_behaves_like 'a rewindable buffer' end + + context 'when the buffer is instantiated from a deserialization' do + + let(:string) do + "#{BSON::Int32::BSON_TYPE}#{BSON::Int32::BSON_TYPE}" + end + + let(:buffer) do + string.to_bson + end + + before do + buffer.rewind! + end + + it 'resets the read position to 0' do + expect(buffer.read_position).to eq(0) + end + + it 'starts subsequent reads at position 0' do + expect(buffer.get_bytes(2)).to eq(string.to_bson.get_bytes(2)) + end + end end end