bson 4.3.0-java → 4.4.1-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/Rakefile +16 -9
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +1 -1
- data/lib/bson/active_support.rb +17 -0
- data/lib/bson/array.rb +1 -1
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/boolean.rb +1 -1
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +1 -1
- data/lib/bson/config.rb +1 -1
- data/lib/bson/date.rb +1 -1
- data/lib/bson/date_time.rb +1 -1
- data/lib/bson/decimal128.rb +1 -1
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +42 -4
- data/lib/bson/environment.rb +1 -1
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +1 -1
- data/lib/bson/int32.rb +17 -4
- data/lib/bson/int64.rb +17 -4
- data/lib/bson/integer.rb +2 -2
- data/lib/bson/json.rb +1 -1
- data/lib/bson/max_key.rb +1 -1
- data/lib/bson/min_key.rb +1 -1
- data/lib/bson/nil_class.rb +1 -1
- data/lib/bson/object.rb +1 -1
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/open_struct.rb +1 -1
- data/lib/bson/regexp.rb +1 -1
- data/lib/bson/registry.rb +1 -1
- data/lib/bson/specialized.rb +1 -1
- data/lib/bson/string.rb +1 -1
- data/lib/bson/symbol.rb +6 -3
- data/lib/bson/time.rb +1 -1
- data/lib/bson/time_with_zone.rb +54 -0
- data/lib/bson/timestamp.rb +1 -1
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/undefined.rb +1 -1
- data/lib/bson/version.rb +2 -2
- data/spec/bson/array_spec.rb +1 -1
- data/spec/bson/binary_spec.rb +1 -1
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/byte_buffer_spec.rb +40 -0
- data/spec/bson/code_spec.rb +1 -1
- data/spec/bson/code_with_scope_spec.rb +1 -1
- data/spec/bson/date_spec.rb +1 -1
- data/spec/bson/date_time_spec.rb +1 -1
- data/spec/bson/decimal128_spec.rb +1 -1
- data/spec/bson/document_spec.rb +60 -1
- data/spec/bson/false_class_spec.rb +1 -1
- data/spec/bson/float_spec.rb +1 -1
- data/spec/bson/hash_spec.rb +1 -1
- data/spec/bson/int32_spec.rb +139 -3
- data/spec/bson/int64_spec.rb +139 -3
- data/spec/bson/integer_spec.rb +3 -3
- data/spec/bson/json_spec.rb +1 -1
- data/spec/bson/max_key_spec.rb +1 -1
- data/spec/bson/min_key_spec.rb +1 -1
- data/spec/bson/nil_class_spec.rb +1 -1
- data/spec/bson/object_id_spec.rb +1 -1
- data/spec/bson/object_spec.rb +1 -1
- data/spec/bson/open_struct_spec.rb +1 -1
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +1 -1
- data/spec/bson/symbol_spec.rb +3 -3
- data/spec/bson/time_spec.rb +1 -1
- data/spec/bson/time_with_zone_spec.rb +68 -0
- data/spec/bson/timestamp_spec.rb +1 -1
- data/spec/bson/true_class_spec.rb +1 -1
- data/spec/bson/undefined_spec.rb +1 -1
- data/spec/bson_spec.rb +1 -1
- data/spec/spec_helper.rb +15 -1
- data/spec/support/shared_examples.rb +1 -1
- data/spec/support/spec_config.rb +9 -0
- metadata +69 -64
- metadata.gz.sig +0 -0
data/lib/bson/time.rb
CHANGED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Copyright (C) 2018-2019 MongoDB Inc.
|
2
|
+
#
|
3
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
|
+
# you may not use this file except in compliance with the License.
|
5
|
+
# You may obtain a copy of the License at
|
6
|
+
#
|
7
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
8
|
+
#
|
9
|
+
# Unless required by applicable law or agreed to in writing, software
|
10
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
11
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
12
|
+
# See the License for the specific language governing permissions and
|
13
|
+
# limitations under the License.
|
14
|
+
|
15
|
+
require "active_support/time_with_zone"
|
16
|
+
|
17
|
+
module BSON
|
18
|
+
|
19
|
+
# Injects behaviour for encoding ActiveSupport::TimeWithZone values to
|
20
|
+
# raw bytes as specified by the BSON spec for time.
|
21
|
+
#
|
22
|
+
# @see http://bsonspec.org/#/specification
|
23
|
+
#
|
24
|
+
# @since 4.4.0
|
25
|
+
module TimeWithZone
|
26
|
+
|
27
|
+
# Get the ActiveSupport::TimeWithZone as encoded BSON.
|
28
|
+
#
|
29
|
+
# @example Get the ActiveSupport::TimeWithZone as encoded BSON.
|
30
|
+
# Time.utc(2012, 12, 12, 0, 0, 0).in_time_zone("Pacific Time (US & Canada)").to_bson
|
31
|
+
#
|
32
|
+
# @return [ BSON::ByteBuffer ] The buffer with the encoded object.
|
33
|
+
#
|
34
|
+
# @see http://bsonspec.org/#/specification
|
35
|
+
#
|
36
|
+
# @since 4.4.0
|
37
|
+
def to_bson(buffer = ByteBuffer.new, validating_keys = Config.validating_keys?)
|
38
|
+
buffer.put_int64((to_i * 1000) + (usec / 1000))
|
39
|
+
end
|
40
|
+
|
41
|
+
# Get the BSON type for the ActiveSupport::TimeWithZone.
|
42
|
+
#
|
43
|
+
# As the ActiveSupport::TimeWithZone is converted to a time, this returns
|
44
|
+
# the BSON type for time.
|
45
|
+
def bson_type
|
46
|
+
::Time::BSON_TYPE
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
# Enrich the ActiveSupport::TimeWithZone class with this module.
|
51
|
+
#
|
52
|
+
# @since 4.4.0
|
53
|
+
ActiveSupport::TimeWithZone.send(:include, TimeWithZone)
|
54
|
+
end
|
data/lib/bson/timestamp.rb
CHANGED
data/lib/bson/true_class.rb
CHANGED
data/lib/bson/undefined.rb
CHANGED
data/lib/bson/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -13,5 +13,5 @@
|
|
13
13
|
# limitations under the License.
|
14
14
|
|
15
15
|
module BSON
|
16
|
-
VERSION = "4.
|
16
|
+
VERSION = "4.4.1".freeze
|
17
17
|
end
|
data/spec/bson/array_spec.rb
CHANGED
data/spec/bson/binary_spec.rb
CHANGED
data/spec/bson/boolean_spec.rb
CHANGED
@@ -196,6 +196,18 @@ describe BSON::ByteBuffer do
|
|
196
196
|
it 'increments the write position by 1' do
|
197
197
|
expect(modified.write_position).to eq(1)
|
198
198
|
end
|
199
|
+
|
200
|
+
context 'when it receives a numeric value' do
|
201
|
+
it 'raises the ArgumentError exception' do
|
202
|
+
expect{buffer.put_byte(1)}.to raise_error(ArgumentError)
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
context 'when it receives a nil value' do
|
207
|
+
it 'raises the ArgumentError exception' do
|
208
|
+
expect{buffer.put_byte(nil)}.to raise_error(ArgumentError)
|
209
|
+
end
|
210
|
+
end
|
199
211
|
end
|
200
212
|
|
201
213
|
describe '#put_cstring' do
|
@@ -501,4 +513,32 @@ describe BSON::ByteBuffer do
|
|
501
513
|
it_behaves_like 'a rewindable buffer'
|
502
514
|
end
|
503
515
|
end
|
516
|
+
|
517
|
+
describe '#put_bytes' do
|
518
|
+
|
519
|
+
let(:buffer) do
|
520
|
+
described_class.new
|
521
|
+
end
|
522
|
+
|
523
|
+
let!(:modified) do
|
524
|
+
buffer.put_bytes(BSON::Int32::BSON_TYPE)
|
525
|
+
buffer
|
526
|
+
end
|
527
|
+
|
528
|
+
it 'increments the write position by 1' do
|
529
|
+
expect(modified.write_position).to eq(1)
|
530
|
+
end
|
531
|
+
|
532
|
+
context 'when it receives a numeric value' do
|
533
|
+
it 'raises the ArgumentError exception' do
|
534
|
+
expect{buffer.put_bytes(1)}.to raise_error(ArgumentError)
|
535
|
+
end
|
536
|
+
end
|
537
|
+
|
538
|
+
context 'when it receives a nil value' do
|
539
|
+
it 'raises the ArgumentError exception' do
|
540
|
+
expect{buffer.put_bytes(nil)}.to raise_error(ArgumentError)
|
541
|
+
end
|
542
|
+
end
|
543
|
+
end
|
504
544
|
end
|
data/spec/bson/code_spec.rb
CHANGED
data/spec/bson/date_spec.rb
CHANGED
data/spec/bson/date_time_spec.rb
CHANGED
data/spec/bson/document_spec.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
|
3
|
-
# Copyright (C) 2009-
|
3
|
+
# Copyright (C) 2009-2019 MongoDB Inc.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
6
|
# you may not use this file except in compliance with the License.
|
@@ -49,6 +49,36 @@ describe BSON::Document do
|
|
49
49
|
end
|
50
50
|
end
|
51
51
|
|
52
|
+
describe "#fetch" do
|
53
|
+
|
54
|
+
let(:document) do
|
55
|
+
described_class["key", "value", "key2", "value"]
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when provided string keys" do
|
59
|
+
|
60
|
+
it "returns the value" do
|
61
|
+
expect(document.fetch("key")).to eq("value")
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context "when provided symbol keys" do
|
66
|
+
|
67
|
+
it "returns the value" do
|
68
|
+
expect(document.fetch(:key)).to eq("value")
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when key does not exist" do
|
73
|
+
|
74
|
+
it "raises KeyError" do
|
75
|
+
expect do
|
76
|
+
document.fetch(:non_existent_key)
|
77
|
+
end.to raise_exception(KeyError)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
52
82
|
describe "#[]" do
|
53
83
|
|
54
84
|
let(:document) do
|
@@ -68,6 +98,13 @@ describe BSON::Document do
|
|
68
98
|
expect(document[:key]).to eq("value")
|
69
99
|
end
|
70
100
|
end
|
101
|
+
|
102
|
+
context "when key does not exist" do
|
103
|
+
|
104
|
+
it "returns nil" do
|
105
|
+
expect(document[:non_existent_key]).to be nil
|
106
|
+
end
|
107
|
+
end
|
71
108
|
end
|
72
109
|
|
73
110
|
describe "#[]=" do
|
@@ -118,6 +155,28 @@ describe BSON::Document do
|
|
118
155
|
end
|
119
156
|
end
|
120
157
|
|
158
|
+
if described_class.instance_methods.include?(:slice)
|
159
|
+
describe "#slice" do
|
160
|
+
let(:document) do
|
161
|
+
described_class.new("key1" => "value1", key2: "value2")
|
162
|
+
end
|
163
|
+
|
164
|
+
context "when provided string keys" do
|
165
|
+
|
166
|
+
it "returns the partial document" do
|
167
|
+
expect(document.slice("key1")).to contain_exactly(['key1', 'value1'])
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
context "when provided symbol keys" do
|
172
|
+
|
173
|
+
it "returns the partial document" do
|
174
|
+
expect(document.slice(:key1)).to contain_exactly(['key1', 'value1'])
|
175
|
+
end
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
121
180
|
describe "#delete" do
|
122
181
|
|
123
182
|
shared_examples_for "a document with deletable pairs" do
|
data/spec/bson/float_spec.rb
CHANGED
data/spec/bson/hash_spec.rb
CHANGED
data/spec/bson/int32_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2019 MongoDB Inc.
|
2
2
|
#
|
3
3
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
4
4
|
# you may not use this file except in compliance with the License.
|
@@ -93,10 +93,146 @@ describe BSON::Int32 do
|
|
93
93
|
describe "#to_bson_key" do
|
94
94
|
|
95
95
|
let(:obj) { BSON::Int32.new(Integer::MAX_32BIT - 1) }
|
96
|
-
let(:encoded) { (Integer::MAX_32BIT - 1)
|
96
|
+
let(:encoded) { (Integer::MAX_32BIT - 1) }
|
97
97
|
|
98
|
-
it "returns the key as
|
98
|
+
it "returns the key as an integer" do
|
99
99
|
expect(obj.to_bson_key).to eq(encoded)
|
100
100
|
end
|
101
101
|
end
|
102
|
+
|
103
|
+
describe "#==" do
|
104
|
+
|
105
|
+
let(:object) do
|
106
|
+
described_class.new(1)
|
107
|
+
end
|
108
|
+
|
109
|
+
context "when data is identical" do
|
110
|
+
|
111
|
+
let(:other_object) do
|
112
|
+
described_class.new(1)
|
113
|
+
end
|
114
|
+
|
115
|
+
it "returns true" do
|
116
|
+
expect(object).to eq(other_object)
|
117
|
+
end
|
118
|
+
|
119
|
+
context "other object is of another integer type" do
|
120
|
+
|
121
|
+
let(:other_object) do
|
122
|
+
BSON::Int64.new(1)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns false" do
|
126
|
+
expect(object).not_to eq(other_object)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "when the data is different" do
|
132
|
+
|
133
|
+
let(:other_object) do
|
134
|
+
described_class.new(2)
|
135
|
+
end
|
136
|
+
|
137
|
+
it "returns false" do
|
138
|
+
expect(object).not_to eq(other_object)
|
139
|
+
end
|
140
|
+
end
|
141
|
+
|
142
|
+
context "when other is not a BSON integer" do
|
143
|
+
|
144
|
+
it "returns false" do
|
145
|
+
expect(described_class.new(1)).to_not eq('1')
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
|
150
|
+
describe "#===" do
|
151
|
+
|
152
|
+
let(:object) do
|
153
|
+
described_class.new(1)
|
154
|
+
end
|
155
|
+
|
156
|
+
context "when comparing with another BSON int32" do
|
157
|
+
|
158
|
+
context "when the data is equal" do
|
159
|
+
|
160
|
+
let(:other_object) do
|
161
|
+
described_class.new(1)
|
162
|
+
end
|
163
|
+
|
164
|
+
it "returns true" do
|
165
|
+
expect(object === other_object).to be true
|
166
|
+
end
|
167
|
+
|
168
|
+
context "other object is of another integer type" do
|
169
|
+
|
170
|
+
let(:other_object) do
|
171
|
+
BSON::Int64.new(1)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "returns false" do
|
175
|
+
expect(object === other_object).to be false
|
176
|
+
end
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
context "when the data is not equal" do
|
181
|
+
|
182
|
+
let(:other_object) do
|
183
|
+
described_class.new(2)
|
184
|
+
end
|
185
|
+
|
186
|
+
it "returns false" do
|
187
|
+
expect(object === other_object).to be false
|
188
|
+
end
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when comparing to an object id class" do
|
193
|
+
|
194
|
+
it "returns false" do
|
195
|
+
expect(described_class.new(1) === described_class).to be false
|
196
|
+
end
|
197
|
+
end
|
198
|
+
|
199
|
+
context "when comparing with a string" do
|
200
|
+
|
201
|
+
context "when the data is equal" do
|
202
|
+
|
203
|
+
let(:other) do
|
204
|
+
'1'
|
205
|
+
end
|
206
|
+
|
207
|
+
it "returns false" do
|
208
|
+
expect(object === other).to be false
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
context "when the data is not equal" do
|
213
|
+
|
214
|
+
let(:other) do
|
215
|
+
'2'
|
216
|
+
end
|
217
|
+
|
218
|
+
it "returns false" do
|
219
|
+
expect(object === other).to be false
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "when comparing with a non-bson integer object" do
|
225
|
+
|
226
|
+
it "returns false" do
|
227
|
+
expect(object === []).to be false
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
231
|
+
context "when comparing with a non int64 class" do
|
232
|
+
|
233
|
+
it "returns false" do
|
234
|
+
expect(object === String).to be false
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
102
238
|
end
|