bson 4.8.0-java → 4.9.2-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/README.md +18 -6
- data/lib/bson-ruby.jar +0 -0
- data/lib/bson.rb +1 -1
- data/lib/bson/active_support.rb +1 -1
- data/lib/bson/array.rb +14 -3
- data/lib/bson/binary.rb +1 -1
- data/lib/bson/boolean.rb +9 -2
- data/lib/bson/code.rb +1 -1
- data/lib/bson/code_with_scope.rb +16 -3
- 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/db_pointer.rb +7 -1
- data/lib/bson/decimal128.rb +1 -1
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +1 -1
- data/lib/bson/environment.rb +2 -1
- data/lib/bson/error.rb +4 -0
- data/lib/bson/ext_json.rb +4 -3
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +1 -1
- data/lib/bson/hash.rb +14 -3
- data/lib/bson/int32.rb +1 -1
- data/lib/bson/int64.rb +1 -1
- data/lib/bson/integer.rb +1 -1
- 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 +8 -2
- 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 +1 -1
- data/lib/bson/time.rb +40 -6
- data/lib/bson/time_with_zone.rb +1 -1
- 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/binary_uuid_spec.rb +1 -1
- data/spec/bson/boolean_spec.rb +1 -1
- 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 +1 -1
- data/spec/bson/ext_json_parse_spec.rb +34 -2
- 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 +1 -1
- data/spec/bson/int64_spec.rb +1 -1
- data/spec/bson/integer_spec.rb +1 -1
- 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/raw_spec.rb +12 -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 +1 -1
- data/spec/bson/time_spec.rb +205 -2
- data/spec/bson/time_with_zone_spec.rb +1 -1
- 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/runners/common_driver.rb +1 -1
- data/spec/runners/corpus.rb +13 -10
- data/spec/runners/corpus_legacy.rb +1 -1
- data/spec/spec_helper.rb +1 -1
- data/spec/spec_tests/data/corpus/top.json +0 -4
- data/spec/support/shared_examples.rb +1 -1
- metadata +79 -82
- metadata.gz.sig +0 -0
data/lib/bson/time_with_zone.rb
CHANGED
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-2020 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.9.2".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
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
@@ -50,14 +50,46 @@ describe "BSON::ExtJSON.parse" do
|
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
|
-
context 'when input is a timestamp' do
|
53
|
+
context 'when input is a BSON timestamp' do
|
54
54
|
let(:input) { {'$timestamp' => {'t' => 12345, 'i' => 42}} }
|
55
55
|
|
56
|
-
it 'returns a
|
56
|
+
it 'returns a BSON::Timestamp instance' do
|
57
57
|
parsed.should == BSON::Timestamp.new(12345, 42)
|
58
58
|
end
|
59
59
|
end
|
60
60
|
|
61
|
+
context 'when input is an ISO time' do
|
62
|
+
let(:input) { {'$date' => '1970-01-01T00:00:04Z'} }
|
63
|
+
|
64
|
+
it 'returns a Time instance ' do
|
65
|
+
parsed.should be_a(Time)
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'returns a Time instance with correct value' do
|
69
|
+
parsed.should == Time.at(4)
|
70
|
+
end
|
71
|
+
|
72
|
+
it 'returns a Time instance in UTC' do
|
73
|
+
parsed.zone.should == 'UTC'
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
context 'when input is a Unix timestamp' do
|
78
|
+
let(:input) { {'$date' => {'$numberLong' => '4000'}} }
|
79
|
+
|
80
|
+
it 'returns a Time instance ' do
|
81
|
+
parsed.should be_a(Time)
|
82
|
+
end
|
83
|
+
|
84
|
+
it 'returns a Time instance with correct value' do
|
85
|
+
parsed.should == Time.at(4)
|
86
|
+
end
|
87
|
+
|
88
|
+
it 'returns a Time instance in UTC' do
|
89
|
+
parsed.zone.should == 'UTC'
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
61
93
|
context 'when input is an int32' do
|
62
94
|
let(:input) do
|
63
95
|
{'$numberInt' => '42'}
|
data/spec/bson/float_spec.rb
CHANGED
data/spec/bson/hash_spec.rb
CHANGED
data/spec/bson/int32_spec.rb
CHANGED
data/spec/bson/int64_spec.rb
CHANGED
data/spec/bson/integer_spec.rb
CHANGED
data/spec/bson/json_spec.rb
CHANGED
data/spec/bson/max_key_spec.rb
CHANGED
data/spec/bson/min_key_spec.rb
CHANGED
data/spec/bson/nil_class_spec.rb
CHANGED
data/spec/bson/object_id_spec.rb
CHANGED
data/spec/bson/object_spec.rb
CHANGED
data/spec/bson/raw_spec.rb
CHANGED
@@ -580,4 +580,15 @@ describe Regexp::Raw do
|
|
580
580
|
end
|
581
581
|
end
|
582
582
|
end
|
583
|
-
|
583
|
+
|
584
|
+
describe 'yaml loading' do
|
585
|
+
let(:regexp) { described_class.new('hello.world', 's') }
|
586
|
+
|
587
|
+
it 'round-trips' do
|
588
|
+
actual = YAML.load(regexp.to_yaml)
|
589
|
+
actual.pattern.should == 'hello.world'
|
590
|
+
actual.options.should == 's'
|
591
|
+
actual.compile.should =~ "hello\nworld"
|
592
|
+
end
|
593
|
+
end
|
594
|
+
end
|
data/spec/bson/regexp_spec.rb
CHANGED
data/spec/bson/registry_spec.rb
CHANGED
data/spec/bson/string_spec.rb
CHANGED
data/spec/bson/symbol_spec.rb
CHANGED
data/spec/bson/time_spec.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Copyright (C) 2009-
|
1
|
+
# Copyright (C) 2009-2020 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.
|
@@ -43,7 +43,7 @@ describe Time do
|
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
46
|
-
context "when the time
|
46
|
+
context "when the time precedes epoch" do
|
47
47
|
|
48
48
|
let(:obj) { Time.utc(1969, 1, 1, 0, 0, 0) }
|
49
49
|
let(:bson) { [ (obj.to_f * 1000).to_i ].pack(BSON::Int64::PACK) }
|
@@ -51,5 +51,208 @@ describe Time do
|
|
51
51
|
it_behaves_like "a serializable bson element"
|
52
52
|
it_behaves_like "a deserializable bson element"
|
53
53
|
end
|
54
|
+
|
55
|
+
context 'when value has sub-millisecond precision' do
|
56
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
57
|
+
|
58
|
+
let(:expected_round_tripped_obj) do
|
59
|
+
Time.utc(2012, 1, 1, 0, 0, 0, 999_000)
|
60
|
+
end
|
61
|
+
|
62
|
+
let(:round_tripped_obj) do
|
63
|
+
Time.from_bson(obj.to_bson)
|
64
|
+
end
|
65
|
+
|
66
|
+
it 'truncates to milliseconds when round-tripping' do
|
67
|
+
round_tripped_obj.should == expected_round_tripped_obj
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe '#as_extended_json' do
|
73
|
+
|
74
|
+
context 'canonical mode' do
|
75
|
+
context 'when value has sub-millisecond precision' do
|
76
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
77
|
+
|
78
|
+
let(:expected_serialization) do
|
79
|
+
{'$date' => {'$numberLong' => '1325376000999'}}
|
80
|
+
end
|
81
|
+
|
82
|
+
let(:serialization) do
|
83
|
+
obj.as_extended_json
|
84
|
+
end
|
85
|
+
|
86
|
+
shared_examples_for 'truncates to milliseconds when serializing' do
|
87
|
+
it 'truncates to milliseconds when serializing' do
|
88
|
+
serialization.should == expected_serialization
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
93
|
+
|
94
|
+
context 'when value has sub-microsecond precision' do
|
95
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999_999/1000r) }
|
96
|
+
|
97
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
98
|
+
end
|
99
|
+
|
100
|
+
context "when the time precedes epoch" do
|
101
|
+
let(:obj) { Time.utc(1960, 1, 1, 0, 0, 0, 999_999) }
|
102
|
+
|
103
|
+
let(:expected_serialization) do
|
104
|
+
{'$date' => {'$numberLong' => '-315619199001'}}
|
105
|
+
end
|
106
|
+
|
107
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
context 'relaxed mode' do
|
113
|
+
context 'when value has sub-millisecond precision' do
|
114
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
115
|
+
|
116
|
+
let(:expected_serialization) do
|
117
|
+
{'$date' => '2012-01-01T00:00:00.999Z'}
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:serialization) do
|
121
|
+
obj.as_extended_json(mode: :relaxed)
|
122
|
+
end
|
123
|
+
|
124
|
+
shared_examples_for 'truncates to milliseconds when serializing' do
|
125
|
+
it 'truncates to milliseconds when serializing' do
|
126
|
+
serialization.should == expected_serialization
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
131
|
+
|
132
|
+
context 'when value has sub-microsecond precision' do
|
133
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999_999/1000r) }
|
134
|
+
|
135
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
136
|
+
end
|
137
|
+
|
138
|
+
context "when the time precedes epoch" do
|
139
|
+
let(:obj) { Time.utc(1960, 1, 1, 0, 0, 0, 999_999) }
|
140
|
+
|
141
|
+
let(:expected_serialization) do
|
142
|
+
{'$date' => {'$numberLong' => '-315619199001'}}
|
143
|
+
end
|
144
|
+
|
145
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
|
151
|
+
describe '#to_extended_json' do
|
152
|
+
|
153
|
+
context 'canonical mode' do
|
154
|
+
context 'when value has sub-millisecond precision' do
|
155
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
156
|
+
|
157
|
+
let(:expected_serialization) do
|
158
|
+
%q`{"$date":{"$numberLong":"1325376000999"}}`
|
159
|
+
end
|
160
|
+
|
161
|
+
let(:serialization) do
|
162
|
+
obj.to_extended_json
|
163
|
+
end
|
164
|
+
|
165
|
+
shared_examples_for 'truncates to milliseconds when serializing' do
|
166
|
+
it 'truncates to milliseconds when serializing' do
|
167
|
+
serialization.should == expected_serialization
|
168
|
+
end
|
169
|
+
end
|
170
|
+
|
171
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
172
|
+
|
173
|
+
context 'when value has sub-microsecond precision' do
|
174
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999_999/1000r) }
|
175
|
+
|
176
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
177
|
+
end
|
178
|
+
|
179
|
+
context "when the time precedes epoch" do
|
180
|
+
let(:obj) { Time.utc(1960, 1, 1, 0, 0, 0, 999_999) }
|
181
|
+
|
182
|
+
let(:expected_serialization) do
|
183
|
+
%q`{"$date":{"$numberLong":"-315619199001"}}`
|
184
|
+
end
|
185
|
+
|
186
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
187
|
+
end
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
context 'relaxed mode' do
|
192
|
+
context 'when value has sub-millisecond precision' do
|
193
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
194
|
+
|
195
|
+
let(:expected_serialization) do
|
196
|
+
%q`{"$date":"2012-01-01T00:00:00.999Z"}`
|
197
|
+
end
|
198
|
+
|
199
|
+
let(:serialization) do
|
200
|
+
obj.to_extended_json(mode: :relaxed)
|
201
|
+
end
|
202
|
+
|
203
|
+
shared_examples_for 'truncates to milliseconds when serializing' do
|
204
|
+
it 'truncates to milliseconds when serializing' do
|
205
|
+
serialization.should == expected_serialization
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
210
|
+
|
211
|
+
context 'when value has sub-microsecond precision' do
|
212
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999_999/1000r) }
|
213
|
+
|
214
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
215
|
+
end
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
220
|
+
describe '#to_json' do
|
221
|
+
|
222
|
+
context 'when value has sub-millisecond precision' do
|
223
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999) }
|
224
|
+
|
225
|
+
let(:expected_serialization) do
|
226
|
+
%q`"2012-01-01 00:00:00 UTC"`
|
227
|
+
end
|
228
|
+
|
229
|
+
let(:serialization) do
|
230
|
+
obj.to_json
|
231
|
+
end
|
232
|
+
|
233
|
+
shared_examples_for 'truncates to milliseconds when serializing' do
|
234
|
+
it 'truncates to milliseconds when serializing' do
|
235
|
+
serialization.should == expected_serialization
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
240
|
+
|
241
|
+
context 'when value has sub-microsecond precision' do
|
242
|
+
let(:obj) { Time.utc(2012, 1, 1, 0, 0, 0, 999_999_999/1000r) }
|
243
|
+
|
244
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
245
|
+
end
|
246
|
+
|
247
|
+
context "when the time precedes epoch" do
|
248
|
+
let(:obj) { Time.utc(1960, 1, 1, 0, 0, 0, 999_999) }
|
249
|
+
|
250
|
+
let(:expected_serialization) do
|
251
|
+
%q`"1960-01-01 00:00:00 UTC"`
|
252
|
+
end
|
253
|
+
|
254
|
+
it_behaves_like 'truncates to milliseconds when serializing'
|
255
|
+
end
|
256
|
+
end
|
54
257
|
end
|
55
258
|
end
|