bson 4.2.2 → 4.12.1
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/README.md +25 -7
- data/Rakefile +16 -9
- data/ext/bson/{native-endian.h → bson-endian.h} +5 -99
- data/ext/bson/bson-native.h +125 -0
- data/ext/bson/bytebuf.c +133 -0
- data/ext/bson/endian.c +117 -0
- data/ext/bson/init.c +355 -0
- data/ext/bson/libbson-utf8.c +230 -0
- data/ext/bson/read.c +411 -0
- data/ext/bson/util.c +95 -0
- data/ext/bson/write.c +680 -0
- data/lib/bson.rb +6 -3
- data/lib/bson/active_support.rb +17 -0
- data/lib/bson/array.rb +57 -17
- data/lib/bson/binary.rb +185 -13
- data/lib/bson/boolean.rb +12 -3
- data/lib/bson/code.rb +16 -2
- data/lib/bson/code_with_scope.rb +32 -5
- data/lib/bson/config.rb +1 -1
- data/lib/bson/date.rb +12 -2
- data/lib/bson/date_time.rb +2 -2
- data/lib/bson/db_pointer.rb +110 -0
- data/lib/bson/decimal128.rb +17 -3
- data/lib/bson/decimal128/builder.rb +1 -1
- data/lib/bson/document.rb +152 -5
- data/lib/bson/environment.rb +2 -1
- data/lib/bson/error.rb +27 -0
- data/lib/bson/ext_json.rb +383 -0
- data/lib/bson/false_class.rb +1 -1
- data/lib/bson/float.rb +48 -2
- data/lib/bson/hash.rb +68 -17
- data/lib/bson/int32.rb +52 -13
- data/lib/bson/int64.rb +59 -15
- data/lib/bson/integer.rb +36 -2
- data/lib/bson/json.rb +1 -1
- data/lib/bson/max_key.rb +13 -1
- data/lib/bson/min_key.rb +13 -1
- data/lib/bson/nil_class.rb +4 -2
- data/lib/bson/object.rb +28 -1
- data/lib/bson/object_id.rb +16 -2
- data/lib/bson/open_struct.rb +1 -1
- data/lib/bson/regexp.rb +27 -4
- data/lib/bson/registry.rb +3 -3
- data/lib/bson/specialized.rb +4 -2
- data/lib/bson/string.rb +5 -3
- data/lib/bson/symbol.rb +99 -7
- data/lib/bson/time.rb +63 -4
- data/lib/bson/time_with_zone.rb +54 -0
- data/lib/bson/timestamp.rb +44 -6
- data/lib/bson/true_class.rb +1 -1
- data/lib/bson/undefined.rb +12 -1
- data/lib/bson/version.rb +2 -2
- data/spec/bson/array_spec.rb +18 -1
- data/spec/bson/binary_spec.rb +100 -3
- data/spec/bson/binary_uuid_spec.rb +189 -0
- data/spec/bson/boolean_spec.rb +1 -1
- data/spec/bson/byte_buffer_read_spec.rb +197 -0
- data/spec/bson/byte_buffer_spec.rb +121 -381
- data/spec/bson/byte_buffer_write_spec.rb +854 -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 +54 -1
- data/spec/bson/decimal128_spec.rb +35 -35
- data/spec/bson/document_as_spec.rb +46 -0
- data/spec/bson/document_spec.rb +197 -30
- data/spec/bson/ext_json_parse_spec.rb +308 -0
- data/spec/bson/false_class_spec.rb +1 -1
- data/spec/bson/float_spec.rb +37 -1
- data/spec/bson/hash_as_spec.rb +57 -0
- data/spec/bson/hash_spec.rb +209 -1
- data/spec/bson/int32_spec.rb +180 -6
- data/spec/bson/int64_spec.rb +199 -6
- data/spec/bson/integer_spec.rb +29 -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/raw_spec.rb +34 -2
- data/spec/bson/regexp_spec.rb +1 -1
- data/spec/bson/registry_spec.rb +1 -1
- data/spec/bson/string_spec.rb +19 -1
- data/spec/bson/symbol_raw_spec.rb +45 -0
- data/spec/bson/symbol_spec.rb +63 -3
- data/spec/bson/time_spec.rb +205 -2
- data/spec/bson/time_with_zone_spec.rb +68 -0
- data/spec/bson/timestamp_spec.rb +56 -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/{support → runners}/common_driver.rb +1 -1
- data/spec/runners/corpus.rb +185 -0
- data/spec/{support/corpus.rb → runners/corpus_legacy.rb} +41 -59
- data/spec/spec_helper.rb +40 -3
- data/spec/{bson/driver_bson_spec.rb → spec_tests/common_driver_spec.rb} +1 -0
- data/spec/{bson/corpus_spec.rb → spec_tests/corpus_legacy_spec.rb} +10 -7
- data/spec/spec_tests/corpus_spec.rb +124 -0
- data/spec/spec_tests/data/corpus/README.md +15 -0
- data/spec/spec_tests/data/corpus/array.json +49 -0
- data/spec/spec_tests/data/corpus/binary.json +113 -0
- data/spec/spec_tests/data/corpus/boolean.json +27 -0
- data/spec/spec_tests/data/corpus/code.json +67 -0
- data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
- data/spec/spec_tests/data/corpus/datetime.json +42 -0
- data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
- data/spec/spec_tests/data/corpus/dbref.json +31 -0
- data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
- data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
- data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
- data/spec/spec_tests/data/corpus/decimal128-4.json +117 -0
- data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +119 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +323 -0
- data/spec/spec_tests/data/corpus/document.json +36 -0
- data/spec/spec_tests/data/corpus/double.json +87 -0
- data/spec/spec_tests/data/corpus/int32.json +43 -0
- data/spec/spec_tests/data/corpus/int64.json +43 -0
- data/spec/spec_tests/data/corpus/maxkey.json +12 -0
- data/spec/spec_tests/data/corpus/minkey.json +12 -0
- data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
- data/spec/spec_tests/data/corpus/multi-type.json +11 -0
- data/spec/spec_tests/data/corpus/null.json +12 -0
- data/spec/spec_tests/data/corpus/oid.json +28 -0
- data/spec/spec_tests/data/corpus/regex.json +65 -0
- data/spec/spec_tests/data/corpus/string.json +72 -0
- data/spec/spec_tests/data/corpus/symbol.json +80 -0
- data/spec/spec_tests/data/corpus/timestamp.json +34 -0
- data/spec/spec_tests/data/corpus/top.json +236 -0
- data/spec/spec_tests/data/corpus/undefined.json +15 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/array.json +8 -2
- data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/binary.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/boolean.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/code_w_scope.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/document.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/double.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/datetime.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/dbpointer.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/int64.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/failures/symbol.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/int32.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/maxkey.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/minkey.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/null.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/oid.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/regex.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/string.json +0 -0
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/timestamp.json +1 -1
- data/spec/{support/corpus-tests → spec_tests/data/corpus_legacy}/top.json +0 -0
- data/spec/{support/corpus-tests/failures → spec_tests/data/corpus_legacy}/undefined.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-1.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-2.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-3.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-4.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-5.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-6.json +0 -0
- data/spec/{support/driver-spec-tests → spec_tests/data}/decimal128/decimal128-7.json +0 -0
- data/spec/support/shared_examples.rb +3 -5
- data/spec/support/spec_config.rb +16 -0
- data/spec/support/utils.rb +10 -0
- metadata +227 -124
- metadata.gz.sig +0 -0
- data/ext/bson/bson_native.c +0 -762
data/spec/bson/int32_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.
|
@@ -25,7 +25,7 @@ describe BSON::Int32 do
|
|
25
25
|
let(:integer) { Integer::MAX_32BIT }
|
26
26
|
|
27
27
|
it "wraps the integer" do
|
28
|
-
expect(obj.
|
28
|
+
expect(obj.value).to be(integer)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,9 +34,9 @@ describe BSON::Int32 do
|
|
34
34
|
let(:integer) { Integer::MAX_32BIT + 1 }
|
35
35
|
|
36
36
|
it "raises an out of range error" do
|
37
|
-
expect
|
37
|
+
expect do
|
38
38
|
obj
|
39
|
-
|
39
|
+
end.to raise_error(RangeError, /#{integer} cannot be stored in 32 bits/)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -50,6 +50,16 @@ describe BSON::Int32 do
|
|
50
50
|
}.to raise_error(RangeError)
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
context 'when argument is an Int32' do
|
55
|
+
let(:integer) do
|
56
|
+
described_class.new(described_class.new(50))
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'works' do
|
60
|
+
expect(integer.value).to be 50
|
61
|
+
end
|
62
|
+
end
|
53
63
|
end
|
54
64
|
|
55
65
|
describe "#from_bson" do
|
@@ -93,10 +103,174 @@ describe BSON::Int32 do
|
|
93
103
|
describe "#to_bson_key" do
|
94
104
|
|
95
105
|
let(:obj) { BSON::Int32.new(Integer::MAX_32BIT - 1) }
|
96
|
-
let(:encoded) { (Integer::MAX_32BIT - 1)
|
106
|
+
let(:encoded) { (Integer::MAX_32BIT - 1) }
|
97
107
|
|
98
|
-
it "returns the key as
|
108
|
+
it "returns the key as an integer" do
|
99
109
|
expect(obj.to_bson_key).to eq(encoded)
|
100
110
|
end
|
101
111
|
end
|
112
|
+
|
113
|
+
describe "#==" do
|
114
|
+
|
115
|
+
let(:object) do
|
116
|
+
described_class.new(1)
|
117
|
+
end
|
118
|
+
|
119
|
+
context "when data is identical" do
|
120
|
+
|
121
|
+
let(:other_object) do
|
122
|
+
described_class.new(1)
|
123
|
+
end
|
124
|
+
|
125
|
+
it "returns true" do
|
126
|
+
expect(object).to eq(other_object)
|
127
|
+
end
|
128
|
+
|
129
|
+
context "other object is of another integer type" do
|
130
|
+
|
131
|
+
let(:other_object) do
|
132
|
+
BSON::Int64.new(1)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns false" do
|
136
|
+
expect(object).not_to eq(other_object)
|
137
|
+
end
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
context "when the data is different" do
|
142
|
+
|
143
|
+
let(:other_object) do
|
144
|
+
described_class.new(2)
|
145
|
+
end
|
146
|
+
|
147
|
+
it "returns false" do
|
148
|
+
expect(object).not_to eq(other_object)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
context "when other is not a BSON integer" do
|
153
|
+
|
154
|
+
it "returns false" do
|
155
|
+
expect(described_class.new(1)).to_not eq('1')
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
|
160
|
+
describe "#===" do
|
161
|
+
|
162
|
+
let(:object) do
|
163
|
+
described_class.new(1)
|
164
|
+
end
|
165
|
+
|
166
|
+
context "when comparing with another BSON int32" do
|
167
|
+
|
168
|
+
context "when the data is equal" do
|
169
|
+
|
170
|
+
let(:other_object) do
|
171
|
+
described_class.new(1)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "returns true" do
|
175
|
+
expect(object === other_object).to be true
|
176
|
+
end
|
177
|
+
|
178
|
+
context "other object is of another integer type" do
|
179
|
+
|
180
|
+
let(:other_object) do
|
181
|
+
BSON::Int64.new(1)
|
182
|
+
end
|
183
|
+
|
184
|
+
it "returns false" do
|
185
|
+
expect(object === other_object).to be false
|
186
|
+
end
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
context "when the data is not equal" do
|
191
|
+
|
192
|
+
let(:other_object) do
|
193
|
+
described_class.new(2)
|
194
|
+
end
|
195
|
+
|
196
|
+
it "returns false" do
|
197
|
+
expect(object === other_object).to be false
|
198
|
+
end
|
199
|
+
end
|
200
|
+
end
|
201
|
+
|
202
|
+
context "when comparing to an object id class" do
|
203
|
+
|
204
|
+
it "returns false" do
|
205
|
+
expect(described_class.new(1) === described_class).to be false
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "when comparing with a string" do
|
210
|
+
|
211
|
+
context "when the data is equal" do
|
212
|
+
|
213
|
+
let(:other) do
|
214
|
+
'1'
|
215
|
+
end
|
216
|
+
|
217
|
+
it "returns false" do
|
218
|
+
expect(object === other).to be false
|
219
|
+
end
|
220
|
+
end
|
221
|
+
|
222
|
+
context "when the data is not equal" do
|
223
|
+
|
224
|
+
let(:other) do
|
225
|
+
'2'
|
226
|
+
end
|
227
|
+
|
228
|
+
it "returns false" do
|
229
|
+
expect(object === other).to be false
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
context "when comparing with a non-bson integer object" do
|
235
|
+
|
236
|
+
it "returns false" do
|
237
|
+
expect(object === []).to be false
|
238
|
+
end
|
239
|
+
end
|
240
|
+
|
241
|
+
context "when comparing with a non int64 class" do
|
242
|
+
|
243
|
+
it "returns false" do
|
244
|
+
expect(object === String).to be false
|
245
|
+
end
|
246
|
+
end
|
247
|
+
end
|
248
|
+
|
249
|
+
describe '#value' do
|
250
|
+
let(:obj) { described_class.new(12345) }
|
251
|
+
|
252
|
+
it 'returns value passed to initializer' do
|
253
|
+
expect(obj.value).to eq(12345)
|
254
|
+
end
|
255
|
+
end
|
256
|
+
|
257
|
+
describe '#as_extended_json' do
|
258
|
+
context 'canonical mode' do
|
259
|
+
it 'returns $numberInt' do
|
260
|
+
described_class.new(42).as_extended_json.should == {'$numberInt' => '42'}
|
261
|
+
end
|
262
|
+
end
|
263
|
+
|
264
|
+
context 'relaxed mode' do
|
265
|
+
it 'returns integer' do
|
266
|
+
described_class.new(42).as_extended_json(mode: :relaxed).should == 42
|
267
|
+
end
|
268
|
+
end
|
269
|
+
|
270
|
+
context 'legacy mode' do
|
271
|
+
it 'returns integer' do
|
272
|
+
described_class.new(42).as_extended_json(mode: :legacy).should be 42
|
273
|
+
end
|
274
|
+
end
|
275
|
+
end
|
102
276
|
end
|
data/spec/bson/int64_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.
|
@@ -25,7 +25,7 @@ describe BSON::Int64 do
|
|
25
25
|
let(:integer) { Integer::MAX_64BIT - 1 }
|
26
26
|
|
27
27
|
it "wraps the integer" do
|
28
|
-
expect(obj.
|
28
|
+
expect(obj.value).to be(integer)
|
29
29
|
end
|
30
30
|
end
|
31
31
|
|
@@ -34,9 +34,9 @@ describe BSON::Int64 do
|
|
34
34
|
let(:integer) { Integer::MAX_64BIT + 1 }
|
35
35
|
|
36
36
|
it "raises an out of range error" do
|
37
|
-
expect
|
37
|
+
expect do
|
38
38
|
obj
|
39
|
-
|
39
|
+
end.to raise_error(RangeError, /#{integer} cannot be stored in 64 bits/)
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -50,6 +50,16 @@ describe BSON::Int64 do
|
|
50
50
|
}.to raise_error(RangeError)
|
51
51
|
end
|
52
52
|
end
|
53
|
+
|
54
|
+
context 'when argument is an Int64' do
|
55
|
+
let(:integer) do
|
56
|
+
described_class.new(described_class.new(50))
|
57
|
+
end
|
58
|
+
|
59
|
+
it 'works' do
|
60
|
+
expect(integer.value).to be 50
|
61
|
+
end
|
62
|
+
end
|
53
63
|
end
|
54
64
|
|
55
65
|
describe "#from_bson" do
|
@@ -61,6 +71,25 @@ describe BSON::Int64 do
|
|
61
71
|
it_behaves_like "a bson element"
|
62
72
|
it_behaves_like "a deserializable bson element"
|
63
73
|
|
74
|
+
context 'canonical deserialization' do
|
75
|
+
let(:integer) { 42 }
|
76
|
+
|
77
|
+
let(:bson) do
|
78
|
+
BSON::ByteBuffer.new(BSON::Int64.new(integer).to_bson.to_s)
|
79
|
+
end
|
80
|
+
|
81
|
+
let(:deserialized) do
|
82
|
+
described_class.from_bson(bson, mode: :bson)
|
83
|
+
end
|
84
|
+
|
85
|
+
it 'deserializes to BSON::Int64' do
|
86
|
+
deserialized.class.should be BSON::Int64
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'has the correct value' do
|
90
|
+
deserialized.value.should == 42
|
91
|
+
end
|
92
|
+
end
|
64
93
|
|
65
94
|
context "when the integer is within the MRI Fixnum range" do
|
66
95
|
|
@@ -138,10 +167,174 @@ describe BSON::Int64 do
|
|
138
167
|
describe "#to_bson_key" do
|
139
168
|
|
140
169
|
let(:obj) { BSON::Int64.new(Integer::MAX_64BIT - 1) }
|
141
|
-
let(:encoded) { (Integer::MAX_64BIT - 1)
|
170
|
+
let(:encoded) { (Integer::MAX_64BIT - 1) }
|
142
171
|
|
143
|
-
it "returns the key as
|
172
|
+
it "returns the key as an integer" do
|
144
173
|
expect(obj.to_bson_key).to eq(encoded)
|
145
174
|
end
|
146
175
|
end
|
176
|
+
|
177
|
+
describe "#==" do
|
178
|
+
|
179
|
+
let(:object) do
|
180
|
+
described_class.new(1)
|
181
|
+
end
|
182
|
+
|
183
|
+
context "when data is identical" do
|
184
|
+
|
185
|
+
let(:other_object) do
|
186
|
+
described_class.new(1)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "returns true" do
|
190
|
+
expect(object).to eq(other_object)
|
191
|
+
end
|
192
|
+
|
193
|
+
context "other object is of another integer type" do
|
194
|
+
|
195
|
+
let(:other_object) do
|
196
|
+
BSON::Int32.new(1)
|
197
|
+
end
|
198
|
+
|
199
|
+
it "returns false" do
|
200
|
+
expect(object).not_to eq(other_object)
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
|
205
|
+
context "when the data is different" do
|
206
|
+
|
207
|
+
let(:other_object) do
|
208
|
+
described_class.new(2)
|
209
|
+
end
|
210
|
+
|
211
|
+
it "returns false" do
|
212
|
+
expect(object).not_to eq(other_object)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "when other is not a BSON integer" do
|
217
|
+
|
218
|
+
it "returns false" do
|
219
|
+
expect(described_class.new(1)).to_not eq('1')
|
220
|
+
end
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
describe "#===" do
|
225
|
+
|
226
|
+
let(:object) do
|
227
|
+
described_class.new(1)
|
228
|
+
end
|
229
|
+
|
230
|
+
context "when comparing with another BSON int64" do
|
231
|
+
|
232
|
+
context "when the data is equal" do
|
233
|
+
|
234
|
+
let(:other_object) do
|
235
|
+
described_class.new(1)
|
236
|
+
end
|
237
|
+
|
238
|
+
it "returns true" do
|
239
|
+
expect(object === other_object).to be true
|
240
|
+
end
|
241
|
+
|
242
|
+
context "other object is of another integer type" do
|
243
|
+
|
244
|
+
let(:other_object) do
|
245
|
+
BSON::Int32.new(1)
|
246
|
+
end
|
247
|
+
|
248
|
+
it "returns false" do
|
249
|
+
expect(object === other_object).to be false
|
250
|
+
end
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "when the data is not equal" do
|
255
|
+
|
256
|
+
let(:other_object) do
|
257
|
+
described_class.new(2)
|
258
|
+
end
|
259
|
+
|
260
|
+
it "returns false" do
|
261
|
+
expect(object === other_object).to be false
|
262
|
+
end
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
context "when comparing to an object id class" do
|
267
|
+
|
268
|
+
it "returns false" do
|
269
|
+
expect(described_class.new(1) === described_class).to be false
|
270
|
+
end
|
271
|
+
end
|
272
|
+
|
273
|
+
context "when comparing with a string" do
|
274
|
+
|
275
|
+
context "when the data is equal" do
|
276
|
+
|
277
|
+
let(:other) do
|
278
|
+
'1'
|
279
|
+
end
|
280
|
+
|
281
|
+
it "returns false" do
|
282
|
+
expect(object === other).to be false
|
283
|
+
end
|
284
|
+
end
|
285
|
+
|
286
|
+
context "when the data is not equal" do
|
287
|
+
|
288
|
+
let(:other) do
|
289
|
+
'2'
|
290
|
+
end
|
291
|
+
|
292
|
+
it "returns false" do
|
293
|
+
expect(object === other).to be false
|
294
|
+
end
|
295
|
+
end
|
296
|
+
end
|
297
|
+
|
298
|
+
context "when comparing with a non-bson integer object" do
|
299
|
+
|
300
|
+
it "returns false" do
|
301
|
+
expect(object === []).to be false
|
302
|
+
end
|
303
|
+
end
|
304
|
+
|
305
|
+
context "when comparing with a non int64 class" do
|
306
|
+
|
307
|
+
it "returns false" do
|
308
|
+
expect(object === String).to be false
|
309
|
+
end
|
310
|
+
end
|
311
|
+
end
|
312
|
+
|
313
|
+
describe '#value' do
|
314
|
+
let(:obj) { described_class.new(12345) }
|
315
|
+
|
316
|
+
it 'returns value passed to initializer' do
|
317
|
+
expect(obj.value).to eq(12345)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
describe '#as_extended_json' do
|
322
|
+
context 'canonical mode' do
|
323
|
+
it 'returns $numberLong' do
|
324
|
+
described_class.new(42).as_extended_json.should == {'$numberLong' => '42'}
|
325
|
+
end
|
326
|
+
end
|
327
|
+
|
328
|
+
context 'relaxed mode' do
|
329
|
+
it 'returns integer' do
|
330
|
+
described_class.new(42).as_extended_json(mode: :relaxed).should == 42
|
331
|
+
end
|
332
|
+
end
|
333
|
+
|
334
|
+
context 'legacy mode' do
|
335
|
+
it 'returns integer' do
|
336
|
+
described_class.new(42).as_extended_json(mode: :legacy).should be 42
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
147
340
|
end
|