bson 4.15.0 → 5.0.2
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
- data/README.md +94 -10
- data/Rakefile +68 -39
- data/ext/bson/bson-native.h +12 -4
- data/ext/bson/extconf.rb +8 -3
- data/ext/bson/init.c +11 -11
- data/ext/bson/read.c +39 -9
- data/ext/bson/util.c +171 -16
- data/ext/bson/write.c +34 -39
- data/lib/bson/active_support.rb +1 -0
- data/lib/bson/array.rb +58 -32
- data/lib/bson/big_decimal.rb +16 -6
- data/lib/bson/binary.rb +271 -129
- data/lib/bson/boolean.rb +1 -0
- data/lib/bson/code.rb +10 -12
- data/lib/bson/code_with_scope.rb +9 -11
- data/lib/bson/config.rb +1 -27
- data/lib/bson/date.rb +2 -1
- data/lib/bson/date_time.rb +2 -1
- data/lib/bson/db_pointer.rb +12 -13
- data/lib/bson/dbref.rb +11 -9
- data/lib/bson/decimal128/builder.rb +10 -9
- data/lib/bson/decimal128.rb +25 -111
- data/lib/bson/document.rb +1 -0
- data/lib/bson/environment.rb +1 -0
- data/lib/bson/error/bson_decode_error.rb +11 -0
- data/lib/bson/error/ext_json_parse_error.rb +11 -0
- data/lib/bson/error/illegal_key.rb +23 -0
- data/lib/bson/error/invalid_binary_type.rb +37 -0
- data/lib/bson/error/invalid_dbref_argument.rb +12 -0
- data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
- data/lib/bson/error/invalid_decimal128_range.rb +27 -0
- data/lib/bson/error/invalid_decimal128_string.rb +26 -0
- data/lib/bson/error/invalid_key.rb +24 -0
- data/lib/bson/error/invalid_object_id.rb +11 -0
- data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
- data/lib/bson/error/unrepresentable_precision.rb +19 -0
- data/lib/bson/error/unserializable_class.rb +13 -0
- data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
- data/lib/bson/error/unsupported_type.rb +11 -0
- data/lib/bson/error.rb +16 -28
- data/lib/bson/ext_json.rb +2 -1
- data/lib/bson/false_class.rb +2 -1
- data/lib/bson/float.rb +3 -2
- data/lib/bson/hash.rb +128 -73
- data/lib/bson/int32.rb +17 -5
- data/lib/bson/int64.rb +17 -5
- data/lib/bson/integer.rb +4 -5
- data/lib/bson/json.rb +1 -0
- data/lib/bson/max_key.rb +8 -10
- data/lib/bson/min_key.rb +8 -10
- data/lib/bson/nil_class.rb +1 -0
- data/lib/bson/object.rb +7 -27
- data/lib/bson/object_id.rb +84 -120
- data/lib/bson/open_struct.rb +3 -2
- data/lib/bson/regexp.rb +36 -65
- data/lib/bson/registry.rb +2 -6
- data/lib/bson/specialized.rb +2 -1
- data/lib/bson/string.rb +4 -27
- data/lib/bson/symbol.rb +23 -20
- data/lib/bson/time.rb +3 -2
- data/lib/bson/time_with_zone.rb +13 -1
- data/lib/bson/timestamp.rb +3 -2
- data/lib/bson/true_class.rb +2 -1
- data/lib/bson/undefined.rb +15 -1
- data/lib/bson/version.rb +3 -1
- data/lib/bson.rb +3 -2
- data/spec/bson/array_spec.rb +19 -60
- data/spec/bson/big_decimal_spec.rb +16 -4
- data/spec/bson/binary_spec.rb +129 -81
- data/spec/bson/binary_uuid_spec.rb +1 -0
- data/spec/bson/boolean_spec.rb +1 -0
- data/spec/bson/byte_buffer_read_spec.rb +1 -0
- data/spec/bson/byte_buffer_spec.rb +1 -0
- data/spec/bson/byte_buffer_write_spec.rb +1 -0
- data/spec/bson/code_spec.rb +5 -3
- data/spec/bson/code_with_scope_spec.rb +5 -3
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +1 -0
- data/spec/bson/date_time_spec.rb +1 -0
- data/spec/bson/dbref_legacy_spec.rb +20 -3
- data/spec/bson/dbref_spec.rb +9 -9
- data/spec/bson/decimal128_spec.rb +40 -20
- data/spec/bson/document_as_spec.rb +1 -0
- data/spec/bson/document_spec.rb +1 -1
- data/spec/bson/ext_json_parse_spec.rb +1 -0
- data/spec/bson/false_class_spec.rb +8 -0
- data/spec/bson/float_spec.rb +8 -3
- data/spec/bson/hash_as_spec.rb +1 -0
- data/spec/bson/hash_spec.rb +87 -75
- data/spec/bson/int32_spec.rb +21 -6
- data/spec/bson/int64_spec.rb +21 -6
- data/spec/bson/integer_spec.rb +45 -13
- data/spec/bson/json_spec.rb +1 -0
- data/spec/bson/max_key_spec.rb +5 -3
- data/spec/bson/min_key_spec.rb +5 -3
- data/spec/bson/nil_class_spec.rb +1 -0
- data/spec/bson/object_id_spec.rb +57 -4
- data/spec/bson/object_spec.rb +2 -1
- data/spec/bson/open_struct_spec.rb +14 -71
- data/spec/bson/raw_spec.rb +9 -15
- data/spec/bson/regexp_spec.rb +4 -3
- data/spec/bson/registry_spec.rb +2 -1
- data/spec/bson/string_spec.rb +13 -38
- data/spec/bson/symbol_raw_spec.rb +25 -0
- data/spec/bson/symbol_spec.rb +15 -18
- data/spec/bson/time_spec.rb +1 -0
- data/spec/bson/time_with_zone_spec.rb +1 -0
- data/spec/bson/timestamp_spec.rb +1 -0
- data/spec/bson/true_class_spec.rb +8 -0
- data/spec/bson/undefined_spec.rb +27 -0
- data/spec/bson_spec.rb +1 -0
- data/spec/runners/common_driver.rb +6 -5
- data/spec/runners/corpus.rb +6 -0
- data/spec/runners/corpus_legacy.rb +1 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spec_tests/common_driver_spec.rb +9 -4
- data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
- data/spec/spec_tests/corpus_spec.rb +13 -3
- data/spec/spec_tests/data/corpus/binary.json +5 -0
- data/spec/spec_tests/data/corpus/code.json +13 -13
- data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
- data/spec/spec_tests/data/corpus/document.json +20 -0
- data/spec/spec_tests/data/corpus/symbol.json +7 -7
- data/spec/spec_tests/data/corpus/top.json +18 -3
- data/spec/support/shared_examples.rb +28 -5
- data/spec/support/spec_config.rb +1 -0
- data/spec/support/utils.rb +49 -1
- metadata +114 -164
- checksums.yaml.gz.sig +0 -0
- data/spec/shared/LICENSE +0 -20
- data/spec/shared/bin/get-mongodb-download-url +0 -17
- data/spec/shared/bin/s3-copy +0 -45
- data/spec/shared/bin/s3-upload +0 -69
- data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
- data/spec/shared/lib/mrss/cluster_config.rb +0 -231
- data/spec/shared/lib/mrss/constraints.rb +0 -386
- data/spec/shared/lib/mrss/docker_runner.rb +0 -271
- data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
- data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
- data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
- data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
- data/spec/shared/lib/mrss/utils.rb +0 -15
- data/spec/shared/share/Dockerfile.erb +0 -338
- data/spec/shared/share/haproxy-1.conf +0 -16
- data/spec/shared/share/haproxy-2.conf +0 -17
- data/spec/shared/shlib/distro.sh +0 -74
- data/spec/shared/shlib/server.sh +0 -367
- data/spec/shared/shlib/set_env.sh +0 -131
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -1
data/spec/bson/array_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -34,65 +35,6 @@ describe Array do
|
|
34
35
|
[ { "$testing" => "value" } ]
|
35
36
|
end
|
36
37
|
|
37
|
-
context "when validating keys" do
|
38
|
-
|
39
|
-
context "when validating globally" do
|
40
|
-
|
41
|
-
before do
|
42
|
-
BSON::Config.validating_keys = true
|
43
|
-
end
|
44
|
-
|
45
|
-
after do
|
46
|
-
BSON::Config.validating_keys = false
|
47
|
-
end
|
48
|
-
|
49
|
-
it "raises an error" do
|
50
|
-
expect {
|
51
|
-
obj.to_bson
|
52
|
-
}.to raise_error(BSON::String::IllegalKey)
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
context "when validating locally" do
|
57
|
-
|
58
|
-
it "raises an error" do
|
59
|
-
expect {
|
60
|
-
obj.to_bson(BSON::ByteBuffer.new, true)
|
61
|
-
}.to raise_error(BSON::String::IllegalKey)
|
62
|
-
end
|
63
|
-
|
64
|
-
context "when serializing different types" do
|
65
|
-
|
66
|
-
let(:obj) do
|
67
|
-
[ BSON::Binary.new("testing", :generic),
|
68
|
-
BSON::Code.new("this.value = 5"),
|
69
|
-
BSON::CodeWithScope.new("this.value = val", "test"),
|
70
|
-
Date.new(2012, 1, 1),
|
71
|
-
Time.utc(2012, 1, 1),
|
72
|
-
DateTime.new(2012, 1, 1, 0, 0, 0),
|
73
|
-
false,
|
74
|
-
1.2332,
|
75
|
-
Integer::MAX_32BIT - 1,
|
76
|
-
BSON::ObjectId.new,
|
77
|
-
/\W+/i,
|
78
|
-
'a string',
|
79
|
-
:a_symbol,
|
80
|
-
Time.utc(2012, 1, 1, 0, 0, 0),
|
81
|
-
BSON::Timestamp.new(1, 10),
|
82
|
-
true,
|
83
|
-
{ "$testing" => "value" }
|
84
|
-
]
|
85
|
-
end
|
86
|
-
|
87
|
-
it "raises an error" do
|
88
|
-
expect {
|
89
|
-
obj.to_bson(BSON::ByteBuffer.new, true)
|
90
|
-
}.to raise_error(BSON::String::IllegalKey)
|
91
|
-
end
|
92
|
-
end
|
93
|
-
end
|
94
|
-
end
|
95
|
-
|
96
38
|
context "when not validating keys" do
|
97
39
|
|
98
40
|
let(:bson) do
|
@@ -186,8 +128,25 @@ describe Array do
|
|
186
128
|
it "raises an exception" do
|
187
129
|
expect {
|
188
130
|
[ 1 ].to_bson_object_id
|
189
|
-
}.to raise_error(BSON::
|
131
|
+
}.to raise_error(BSON::Error::InvalidObjectId)
|
190
132
|
end
|
191
133
|
end
|
192
134
|
end
|
135
|
+
|
136
|
+
describe '#as_extended_json' do
|
137
|
+
|
138
|
+
let(:object) do
|
139
|
+
['one', :two, 3, 4.0, nil]
|
140
|
+
end
|
141
|
+
|
142
|
+
let(:expected) do
|
143
|
+
["one", { "$symbol" => "two" }, { "$numberInt" => "3" }, { "$numberDouble"=> "4.0" }, nil]
|
144
|
+
end
|
145
|
+
|
146
|
+
it 'returns the extended serialization' do
|
147
|
+
expect(object.as_extended_json).to eq(expected)
|
148
|
+
end
|
149
|
+
|
150
|
+
it_behaves_like 'an Extended JSON serializable object'
|
151
|
+
end
|
193
152
|
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2016-2021 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -14,7 +15,7 @@
|
|
14
15
|
|
15
16
|
require "spec_helper"
|
16
17
|
|
17
|
-
describe
|
18
|
+
describe BigDecimal do
|
18
19
|
|
19
20
|
describe '#from_bson' do
|
20
21
|
shared_examples_for 'a BSON::BigDecimal deserializer' do
|
@@ -35,7 +36,7 @@ describe BSON::BigDecimal do
|
|
35
36
|
if deserialized_decimal128.to_s == "NaN"
|
36
37
|
expect(deserialized_big_decimal.nan?).to be true
|
37
38
|
else
|
38
|
-
expect(deserialized_big_decimal).to eq(deserialized_decimal128.
|
39
|
+
expect(deserialized_big_decimal).to eq(deserialized_decimal128.to_d)
|
39
40
|
end
|
40
41
|
end
|
41
42
|
end
|
@@ -211,7 +212,7 @@ describe BSON::BigDecimal do
|
|
211
212
|
it "raises an error" do
|
212
213
|
expect do
|
213
214
|
BigDecimal(argument).to_bson
|
214
|
-
end.to raise_error(BSON::
|
215
|
+
end.to raise_error(BSON::Error::InvalidDecimal128Range)
|
215
216
|
end
|
216
217
|
end
|
217
218
|
|
@@ -221,7 +222,7 @@ describe BSON::BigDecimal do
|
|
221
222
|
it "raises an error" do
|
222
223
|
expect do
|
223
224
|
BigDecimal(argument).to_bson
|
224
|
-
end.to raise_error(BSON::
|
225
|
+
end.to raise_error(BSON::Error::UnrepresentablePrecision)
|
225
226
|
end
|
226
227
|
end
|
227
228
|
end
|
@@ -313,4 +314,15 @@ describe BSON::BigDecimal do
|
|
313
314
|
it_behaves_like 'a BSON::BigDecimal round trip'
|
314
315
|
end
|
315
316
|
end
|
317
|
+
|
318
|
+
context "when the class is loaded" do
|
319
|
+
|
320
|
+
let(:registered) do
|
321
|
+
BSON::Registry.get(described_class::BSON_TYPE, 'field')
|
322
|
+
end
|
323
|
+
|
324
|
+
it "registers the type" do
|
325
|
+
expect(registered).to eq(described_class)
|
326
|
+
end
|
327
|
+
end
|
316
328
|
end
|
data/spec/bson/binary_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -19,17 +20,56 @@ describe BSON::Binary do
|
|
19
20
|
let(:testing1) { described_class.new("testing") }
|
20
21
|
let(:testing2) { described_class.new("testing") }
|
21
22
|
let(:not_testing) { described_class.new("not testing") }
|
23
|
+
let(:testing3) { described_class.new("testing", :user) }
|
24
|
+
|
25
|
+
describe "Comparable" do
|
26
|
+
describe "#eql?" do
|
27
|
+
context "for two equal objects" do
|
28
|
+
it "returns true" do
|
29
|
+
expect(testing1).to eql(testing2)
|
30
|
+
end
|
31
|
+
end
|
22
32
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
33
|
+
context "for two different objects" do
|
34
|
+
it "returns false" do
|
35
|
+
expect(testing1).not_to eql(not_testing)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'for objects with identical data but different types' do
|
40
|
+
it 'returns false' do
|
41
|
+
expect(testing1).not_to eql(testing3)
|
42
|
+
end
|
27
43
|
end
|
28
44
|
end
|
29
45
|
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
describe '#<=>' do
|
47
|
+
context 'with a non-Binary object' do
|
48
|
+
it 'returns nil' do
|
49
|
+
expect(testing1 <=> 'bogus').to be_nil
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context 'with identical type and data' do
|
54
|
+
it 'returns 0' do
|
55
|
+
expect(testing1 <=> testing2).to be == 0
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
context 'with mismatched type' do
|
60
|
+
it 'returns nil' do
|
61
|
+
expect(testing1 <=> testing3).to be_nil
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
context 'with identical type but mismatched data' do
|
66
|
+
it 'returns -1 when a < b' do
|
67
|
+
expect(not_testing <=> testing1).to be == -1
|
68
|
+
end
|
69
|
+
|
70
|
+
it 'returns 1 when a > b' do
|
71
|
+
expect(testing1 <=> not_testing).to be == 1
|
72
|
+
end
|
33
73
|
end
|
34
74
|
end
|
35
75
|
end
|
@@ -55,19 +95,20 @@ describe BSON::Binary do
|
|
55
95
|
expect(hash[not_testing]).to be_nil
|
56
96
|
end
|
57
97
|
|
58
|
-
describe "#
|
98
|
+
describe "#as_extended_json" do
|
59
99
|
|
60
100
|
let(:object) do
|
61
101
|
described_class.new("testing", :user)
|
62
102
|
end
|
63
103
|
|
64
104
|
it "returns the binary data plus type" do
|
65
|
-
expect(object.
|
105
|
+
expect(object.as_extended_json).to eq(
|
66
106
|
{ "$binary" => {'base64' => Base64.encode64("testing").strip, "subType" => '80' }}
|
67
107
|
)
|
68
108
|
end
|
69
109
|
|
70
|
-
it_behaves_like
|
110
|
+
it_behaves_like 'an Extended JSON serializable object'
|
111
|
+
it_behaves_like '#as_json calls #as_extended_json'
|
71
112
|
end
|
72
113
|
|
73
114
|
describe "#initialize" do
|
@@ -80,17 +121,26 @@ describe BSON::Binary do
|
|
80
121
|
end
|
81
122
|
end
|
82
123
|
|
83
|
-
context "when
|
124
|
+
context "when the type is invalid" do
|
84
125
|
|
85
126
|
it "raises an error" do
|
86
127
|
expect {
|
87
128
|
described_class.new("testing", :error)
|
88
129
|
}.to raise_error { |error|
|
89
|
-
expect(error).to be_a(BSON::
|
130
|
+
expect(error).to be_a(BSON::Error::InvalidBinaryType)
|
90
131
|
expect(error.message).to match /is not a valid binary type/
|
91
132
|
}
|
92
133
|
end
|
93
134
|
end
|
135
|
+
|
136
|
+
context 'when initialized via legacy YAML' do
|
137
|
+
let(:yaml) { "--- !ruby/object:BSON::Binary\ndata: hello\ntype: :generic\n" }
|
138
|
+
let(:deserialized) { YAML.safe_load(yaml, permitted_classes: [ Symbol, BSON::Binary ]) }
|
139
|
+
|
140
|
+
it 'correctly sets the raw_type' do
|
141
|
+
expect(deserialized.raw_type).to be == BSON::Binary::SUBTYPES[:generic]
|
142
|
+
end
|
143
|
+
end
|
94
144
|
end
|
95
145
|
|
96
146
|
describe '#inspect' do
|
@@ -162,75 +212,73 @@ describe BSON::Binary do
|
|
162
212
|
|
163
213
|
it_behaves_like "a bson element"
|
164
214
|
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
it_behaves_like "a serializable bson element"
|
233
|
-
it_behaves_like "a deserializable bson element"
|
215
|
+
[
|
216
|
+
{
|
217
|
+
types: [ nil, 0, 0.chr, :generic, 'generic' ],
|
218
|
+
bson: "#{7.to_bson}#{0.chr}testing",
|
219
|
+
type: :generic,
|
220
|
+
},
|
221
|
+
{
|
222
|
+
types: [ 1, 1.chr, :function, 'function' ],
|
223
|
+
bson: "#{7.to_bson}#{1.chr}testing",
|
224
|
+
type: :function,
|
225
|
+
},
|
226
|
+
{
|
227
|
+
types: [ 2, 2.chr, :old, 'old' ],
|
228
|
+
bson: "#{11.to_bson}#{2.chr}#{7.to_bson}testing",
|
229
|
+
type: :old,
|
230
|
+
},
|
231
|
+
{
|
232
|
+
types: [ 3, 3.chr, :uuid_old, 'uuid_old' ],
|
233
|
+
bson: "#{7.to_bson}#{3.chr}testing",
|
234
|
+
type: :uuid_old,
|
235
|
+
},
|
236
|
+
{
|
237
|
+
types: [ 4, 4.chr, :uuid, 'uuid' ],
|
238
|
+
bson: "#{7.to_bson}#{4.chr}testing",
|
239
|
+
type: :uuid,
|
240
|
+
},
|
241
|
+
{
|
242
|
+
types: [ 5, 5.chr, :md5, 'md5' ],
|
243
|
+
bson: "#{7.to_bson}#{5.chr}testing",
|
244
|
+
type: :md5,
|
245
|
+
},
|
246
|
+
{
|
247
|
+
types: [ 6, 6.chr, :ciphertext, 'ciphertext' ],
|
248
|
+
bson: "#{7.to_bson}#{6.chr}testing",
|
249
|
+
type: :ciphertext,
|
250
|
+
},
|
251
|
+
{
|
252
|
+
types: [ 0x80, 0x80.chr, :user, 'user' ],
|
253
|
+
bson: "#{7.to_bson}#{128.chr}testing",
|
254
|
+
type: :user,
|
255
|
+
},
|
256
|
+
{
|
257
|
+
types: [ 0xFF, 0xFF.chr ],
|
258
|
+
bson: "#{7.to_bson}#{0xFF.chr}testing",
|
259
|
+
type: :user,
|
260
|
+
},
|
261
|
+
].each do |defn|
|
262
|
+
defn[:types].each do |type|
|
263
|
+
context "when the type is #{type ? type.inspect : 'not provided'}" do
|
264
|
+
let(:obj) do
|
265
|
+
if type
|
266
|
+
described_class.new("testing", type)
|
267
|
+
else
|
268
|
+
described_class.new("testing")
|
269
|
+
end
|
270
|
+
end
|
271
|
+
|
272
|
+
let(:bson) { defn[:bson] }
|
273
|
+
|
274
|
+
it_behaves_like "a serializable bson element"
|
275
|
+
it_behaves_like "a deserializable bson element"
|
276
|
+
|
277
|
+
it "reports its type as #{defn[:type].inspect}" do
|
278
|
+
expect(obj.type).to be == defn[:type]
|
279
|
+
end
|
280
|
+
end
|
281
|
+
end
|
234
282
|
end
|
235
283
|
|
236
284
|
context 'when given binary string' do
|
data/spec/bson/boolean_spec.rb
CHANGED
data/spec/bson/code_spec.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -16,17 +17,18 @@ require "spec_helper"
|
|
16
17
|
|
17
18
|
describe BSON::Code do
|
18
19
|
|
19
|
-
describe "#
|
20
|
+
describe "#as_extended_json" do
|
20
21
|
|
21
22
|
let(:object) do
|
22
23
|
described_class.new("this.value = 5")
|
23
24
|
end
|
24
25
|
|
25
26
|
it "returns the binary data plus type" do
|
26
|
-
expect(object.
|
27
|
+
expect(object.as_extended_json).to eq({ "$code" => "this.value = 5" })
|
27
28
|
end
|
28
29
|
|
29
|
-
it_behaves_like
|
30
|
+
it_behaves_like 'an Extended JSON serializable object'
|
31
|
+
it_behaves_like '#as_json calls #as_extended_json'
|
30
32
|
end
|
31
33
|
|
32
34
|
describe "#to_bson/#from_bson" do
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
2
3
|
#
|
3
4
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -39,19 +40,20 @@ describe BSON::CodeWithScope do
|
|
39
40
|
end
|
40
41
|
end
|
41
42
|
|
42
|
-
describe "#
|
43
|
+
describe "#as_extended_json" do
|
43
44
|
|
44
45
|
let(:object) do
|
45
46
|
described_class.new("this.value = val", :val => "test")
|
46
47
|
end
|
47
48
|
|
48
49
|
it "returns the binary data plus type" do
|
49
|
-
expect(object.
|
50
|
+
expect(object.as_extended_json).to eq(
|
50
51
|
{ "$code" => "this.value = val", "$scope" => { :val => "test" }}
|
51
52
|
)
|
52
53
|
end
|
53
54
|
|
54
|
-
it_behaves_like
|
55
|
+
it_behaves_like 'an Extended JSON serializable object'
|
56
|
+
it_behaves_like '#as_json calls #as_extended_json'
|
55
57
|
end
|
56
58
|
|
57
59
|
describe "#to_bson" do
|
data/spec/bson/config_spec.rb
CHANGED
@@ -1,40 +1,6 @@
|
|
1
|
+
# rubocop:todo all
|
1
2
|
require "spec_helper"
|
2
3
|
|
3
4
|
describe BSON::Config do
|
4
5
|
|
5
|
-
describe "#validating_keys?" do
|
6
|
-
|
7
|
-
context "when the default is used" do
|
8
|
-
|
9
|
-
it "returns false" do
|
10
|
-
expect(described_class).to_not be_validating_keys
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
context "when configuring to false" do
|
15
|
-
|
16
|
-
before do
|
17
|
-
BSON::Config.validating_keys = false
|
18
|
-
end
|
19
|
-
|
20
|
-
it "returns false" do
|
21
|
-
expect(described_class).to_not be_validating_keys
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
context "when configuring to true" do
|
26
|
-
|
27
|
-
before do
|
28
|
-
BSON::Config.validating_keys = true
|
29
|
-
end
|
30
|
-
|
31
|
-
after do
|
32
|
-
BSON::Config.validating_keys = false
|
33
|
-
end
|
34
|
-
|
35
|
-
it "returns true" do
|
36
|
-
expect(described_class).to be_validating_keys
|
37
|
-
end
|
38
|
-
end
|
39
|
-
end
|
40
6
|
end
|
data/spec/bson/date_spec.rb
CHANGED
data/spec/bson/date_time_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
#
|
2
|
+
# rubocop:todo all
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
require 'json'
|
@@ -8,7 +8,24 @@ require 'json'
|
|
8
8
|
# class, and are intended to verify that the current DBRef implementation is
|
9
9
|
# compatible with the legacy driver DBRef interface.
|
10
10
|
|
11
|
-
|
11
|
+
# For testing a class that emits warnings, without spamming the terminal
|
12
|
+
# with them.
|
13
|
+
def silenced_version_of(klass)
|
14
|
+
Class.new(klass) do
|
15
|
+
class <<self
|
16
|
+
def name
|
17
|
+
"#{superclass.name} (silenced)"
|
18
|
+
end
|
19
|
+
|
20
|
+
alias to_s name
|
21
|
+
end
|
22
|
+
|
23
|
+
def warn(*_args)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
describe silenced_version_of BSON::DBRef do
|
12
29
|
|
13
30
|
let(:object_id) do
|
14
31
|
BSON::ObjectId.new
|
@@ -76,7 +93,7 @@ describe BSON::DBRef do
|
|
76
93
|
it 'raises ArgumentError' do
|
77
94
|
lambda do
|
78
95
|
dbref
|
79
|
-
end.should raise_error(
|
96
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
80
97
|
end
|
81
98
|
end
|
82
99
|
end
|
data/spec/bson/dbref_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
#
|
2
|
+
# rubocop:todo all
|
3
3
|
|
4
4
|
require 'spec_helper'
|
5
5
|
require 'json'
|
@@ -79,10 +79,10 @@ describe BSON::DBRef do
|
|
79
79
|
described_class.new({:$ref => 'users', :$id => object_id}, object_id)
|
80
80
|
end
|
81
81
|
|
82
|
-
it 'raises
|
82
|
+
it 'raises InvalidDBRefArgument' do
|
83
83
|
lambda do
|
84
84
|
dbref
|
85
|
-
end.should raise_error(
|
85
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
86
86
|
end
|
87
87
|
end
|
88
88
|
|
@@ -92,10 +92,10 @@ describe BSON::DBRef do
|
|
92
92
|
described_class.new({:$ref => 'users', :$id => object_id}, object_id, 'db')
|
93
93
|
end
|
94
94
|
|
95
|
-
it 'raises
|
95
|
+
it 'raises InvalidDBRefArgument' do
|
96
96
|
lambda do
|
97
97
|
dbref
|
98
|
-
end.should raise_error(
|
98
|
+
end.should raise_error(BSON::Error::InvalidDBRefArgument)
|
99
99
|
end
|
100
100
|
end
|
101
101
|
|
@@ -118,7 +118,7 @@ describe BSON::DBRef do
|
|
118
118
|
it 'raises an error' do
|
119
119
|
expect do
|
120
120
|
dbref
|
121
|
-
end.to raise_error(
|
121
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /DBRef must have \$ref/)
|
122
122
|
end
|
123
123
|
end
|
124
124
|
|
@@ -130,7 +130,7 @@ describe BSON::DBRef do
|
|
130
130
|
it 'raises an error' do
|
131
131
|
expect do
|
132
132
|
dbref
|
133
|
-
end.to raise_error(
|
133
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /DBRef must have \$id/)
|
134
134
|
end
|
135
135
|
end
|
136
136
|
|
@@ -142,7 +142,7 @@ describe BSON::DBRef do
|
|
142
142
|
it 'raises an error' do
|
143
143
|
expect do
|
144
144
|
dbref
|
145
|
-
end.to raise_error(
|
145
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /The value for key \$ref must be a string/)
|
146
146
|
end
|
147
147
|
end
|
148
148
|
|
@@ -154,7 +154,7 @@ describe BSON::DBRef do
|
|
154
154
|
it 'raises an error' do
|
155
155
|
expect do
|
156
156
|
dbref
|
157
|
-
end.to raise_error(
|
157
|
+
end.to raise_error(BSON::Error::InvalidDBRefArgument, /The value for key \$db must be a string/)
|
158
158
|
end
|
159
159
|
end
|
160
160
|
|