Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/logstash/outputs/bson/big_decimal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ module BigDecimal
# 1.221311.to_bson
# @return [ String ] The encoded string.
# @see http://bsonspec.org/#/specification
def to_bson(encoded = ''.force_encoding(BINARY))
encoded << [ self ].pack(PACK)
def to_bson(buffer = ByteBuffer.new)
buffer.put_bytes([ self ].pack(PACK))
end

module ClassMethods
Expand All @@ -44,7 +44,7 @@ module ClassMethods
# @return [ BigDecimal ] The decoded BigDecimal.
# @see http://bsonspec.org/#/specification
def from_bson(bson)
from_bson_double(bson.read(8))
from_bson_double(bson.get_bytes(8))
end

private
Expand Down
4 changes: 2 additions & 2 deletions lib/logstash/outputs/bson/logstash_timestamp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ module LogStashTimestamp
# A time is type 0x09 in the BSON spec.
BSON_TYPE = 9.chr.force_encoding(BINARY).freeze

def to_bson(encoded = ''.force_encoding(BINARY))
time.to_bson(encoded)
def to_bson(buffer = ByteBuffer.new)
time.to_bson(buffer)
end

module ClassMethods
Expand Down
2 changes: 1 addition & 1 deletion logstash-output-mongodb.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Gem::Specification.new do |s|
# Gem dependencies
s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
s.add_runtime_dependency 'logstash-codec-plain'
s.add_runtime_dependency 'mongo', '~> 2.0.6'
s.add_runtime_dependency 'mongo', '~> 2.6'

s.add_development_dependency 'logstash-devutils'
end
Expand Down
7 changes: 3 additions & 4 deletions spec/bson/big_decimal_spec.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: utf-8
require 'bigdecimal'
require_relative "../spec_helper"
require 'stringio'

describe ::BigDecimal do
let(:a_number) { "4321.1234" }
Expand All @@ -13,8 +12,8 @@
expect(subject).to respond_to(:to_bson)
end

it "to_bson returns a binary encoded number" do
expect(subject.to_bson).to eq(4321.1234.to_bson)
it "to_bson returns a binary encoded number which can be encoded back from bson" do
expect(BigDecimal::from_bson(subject.to_bson)).to eq(BigDecimal::from_bson(4321.1234.to_bson))
end

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

describe "class methods" do
it "builds a new BigDecimal from BSON" do
decoded = described_class.from_bson(StringIO.new(4321.1234.to_bson))
decoded = described_class.from_bson(4321.1234.to_bson)
expect(decoded).to eql(BigDecimal.new(a_number))
end
end
Expand Down
7 changes: 3 additions & 4 deletions spec/bson/logstash_timestamp_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# encoding: utf-8
require_relative "../spec_helper"
require 'stringio'

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

it "to_bson returns a binary encoded timestamp" do
expect(timestamp.to_bson).to eq(bson_time)
it "to_bson returns a binary encoded timestamp which may be encoded back from bson" do
expect(Time::from_bson(timestamp.to_bson)).to eq(Time::from_bson(bson_time))
end

it "bson_type returns a binary encoded 9" do
Expand All @@ -24,7 +23,7 @@
describe "class methods" do
it "builds a new Timestamp from BSON" do
expected = ::LogStash::Timestamp.new(a_time)
decoded = ::LogStash::Timestamp.from_bson(StringIO.new(bson_time))
decoded = ::LogStash::Timestamp.from_bson(bson_time)
expect(decoded <=> expected).to eq(0)
end
end
Expand Down