Skip to content

Commit 8d3dee9

Browse files
sdmeisnercolinsurprenant
authored andcommitted
Use latest stable mongo driver, fix tests and update to_bson to accept correct type and return correct format
1 parent c7c07a8 commit 8d3dee9

File tree

4 files changed

+10
-12
lines changed

4 files changed

+10
-12
lines changed

lib/logstash/outputs/bson/big_decimal.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ module BigDecimal
3333
# 1.221311.to_bson
3434
# @return [ String ] The encoded string.
3535
# @see http://bsonspec.org/#/specification
36-
def to_bson(encoded = ''.force_encoding(BINARY))
37-
encoded << [ self ].pack(PACK)
36+
def to_bson(buffer = ByteBuffer.new)
37+
buffer.put_bytes([ self ].pack(PACK))
3838
end
3939

4040
module ClassMethods

lib/logstash/outputs/bson/logstash_timestamp.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ module LogStashTimestamp
2525
# A time is type 0x09 in the BSON spec.
2626
BSON_TYPE = 9.chr.force_encoding(BINARY).freeze
2727

28-
def to_bson(encoded = ''.force_encoding(BINARY))
29-
time.to_bson(encoded)
28+
def to_bson(buffer = ByteBuffer.new)
29+
time.to_bson(buffer)
3030
end
3131

3232
module ClassMethods

spec/bson/big_decimal_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
# encoding: utf-8
22
require 'bigdecimal'
33
require_relative "../spec_helper"
4-
require 'stringio'
54

65
describe ::BigDecimal do
76
let(:a_number) { "4321.1234" }
@@ -13,8 +12,8 @@
1312
expect(subject).to respond_to(:to_bson)
1413
end
1514

16-
it "to_bson returns a binary encoded number" do
17-
expect(subject.to_bson).to eq(4321.1234.to_bson)
15+
it "to_bson returns a binary encoded number which can be encoded back from bson" do
16+
expect(BigDecimal::from_bson(subject.to_bson)).to eq(BigDecimal::from_bson(4321.1234.to_bson))
1817
end
1918

2019
it "bson_type returns a binary encoded 1" do
@@ -23,7 +22,7 @@
2322

2423
describe "class methods" do
2524
it "builds a new BigDecimal from BSON" do
26-
decoded = described_class.from_bson(StringIO.new(4321.1234.to_bson))
25+
decoded = described_class.from_bson(4321.1234.to_bson)
2726
expect(decoded).to eql(BigDecimal.new(a_number))
2827
end
2928
end

spec/bson/logstash_timestamp_spec.rb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# encoding: utf-8
22
require_relative "../spec_helper"
3-
require 'stringio'
43

54
describe ::LogStash::Timestamp do
65
let(:time_array) { [1918,11,11,11,0,0, "+00:00"] }
@@ -13,8 +12,8 @@
1312
expect(subject).to respond_to(:to_bson)
1413
end
1514

16-
it "to_bson returns a binary encoded timestamp" do
17-
expect(timestamp.to_bson).to eq(bson_time)
15+
it "to_bson returns a binary encoded timestamp which may be encoded back from bson" do
16+
expect(Time::from_bson(timestamp.to_bson)).to eq(Time::from_bson(bson_time))
1817
end
1918

2019
it "bson_type returns a binary encoded 9" do
@@ -24,7 +23,7 @@
2423
describe "class methods" do
2524
it "builds a new Timestamp from BSON" do
2625
expected = ::LogStash::Timestamp.new(a_time)
27-
decoded = ::LogStash::Timestamp.from_bson(StringIO.new(bson_time))
26+
decoded = ::LogStash::Timestamp.from_bson(bson_time)
2827
expect(decoded <=> expected).to eq(0)
2928
end
3029
end

0 commit comments

Comments
 (0)