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.
Files changed (153) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +94 -10
  3. data/Rakefile +68 -39
  4. data/ext/bson/bson-native.h +12 -4
  5. data/ext/bson/extconf.rb +8 -3
  6. data/ext/bson/init.c +11 -11
  7. data/ext/bson/read.c +39 -9
  8. data/ext/bson/util.c +171 -16
  9. data/ext/bson/write.c +34 -39
  10. data/lib/bson/active_support.rb +1 -0
  11. data/lib/bson/array.rb +58 -32
  12. data/lib/bson/big_decimal.rb +16 -6
  13. data/lib/bson/binary.rb +271 -129
  14. data/lib/bson/boolean.rb +1 -0
  15. data/lib/bson/code.rb +10 -12
  16. data/lib/bson/code_with_scope.rb +9 -11
  17. data/lib/bson/config.rb +1 -27
  18. data/lib/bson/date.rb +2 -1
  19. data/lib/bson/date_time.rb +2 -1
  20. data/lib/bson/db_pointer.rb +12 -13
  21. data/lib/bson/dbref.rb +11 -9
  22. data/lib/bson/decimal128/builder.rb +10 -9
  23. data/lib/bson/decimal128.rb +25 -111
  24. data/lib/bson/document.rb +1 -0
  25. data/lib/bson/environment.rb +1 -0
  26. data/lib/bson/error/bson_decode_error.rb +11 -0
  27. data/lib/bson/error/ext_json_parse_error.rb +11 -0
  28. data/lib/bson/error/illegal_key.rb +23 -0
  29. data/lib/bson/error/invalid_binary_type.rb +37 -0
  30. data/lib/bson/error/invalid_dbref_argument.rb +12 -0
  31. data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
  32. data/lib/bson/error/invalid_decimal128_range.rb +27 -0
  33. data/lib/bson/error/invalid_decimal128_string.rb +26 -0
  34. data/lib/bson/error/invalid_key.rb +24 -0
  35. data/lib/bson/error/invalid_object_id.rb +11 -0
  36. data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
  37. data/lib/bson/error/unrepresentable_precision.rb +19 -0
  38. data/lib/bson/error/unserializable_class.rb +13 -0
  39. data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
  40. data/lib/bson/error/unsupported_type.rb +11 -0
  41. data/lib/bson/error.rb +16 -28
  42. data/lib/bson/ext_json.rb +2 -1
  43. data/lib/bson/false_class.rb +2 -1
  44. data/lib/bson/float.rb +3 -2
  45. data/lib/bson/hash.rb +128 -73
  46. data/lib/bson/int32.rb +17 -5
  47. data/lib/bson/int64.rb +17 -5
  48. data/lib/bson/integer.rb +4 -5
  49. data/lib/bson/json.rb +1 -0
  50. data/lib/bson/max_key.rb +8 -10
  51. data/lib/bson/min_key.rb +8 -10
  52. data/lib/bson/nil_class.rb +1 -0
  53. data/lib/bson/object.rb +7 -27
  54. data/lib/bson/object_id.rb +84 -120
  55. data/lib/bson/open_struct.rb +3 -2
  56. data/lib/bson/regexp.rb +36 -65
  57. data/lib/bson/registry.rb +2 -6
  58. data/lib/bson/specialized.rb +2 -1
  59. data/lib/bson/string.rb +4 -27
  60. data/lib/bson/symbol.rb +23 -20
  61. data/lib/bson/time.rb +3 -2
  62. data/lib/bson/time_with_zone.rb +13 -1
  63. data/lib/bson/timestamp.rb +3 -2
  64. data/lib/bson/true_class.rb +2 -1
  65. data/lib/bson/undefined.rb +15 -1
  66. data/lib/bson/version.rb +3 -1
  67. data/lib/bson.rb +3 -2
  68. data/spec/bson/array_spec.rb +19 -60
  69. data/spec/bson/big_decimal_spec.rb +16 -4
  70. data/spec/bson/binary_spec.rb +129 -81
  71. data/spec/bson/binary_uuid_spec.rb +1 -0
  72. data/spec/bson/boolean_spec.rb +1 -0
  73. data/spec/bson/byte_buffer_read_spec.rb +1 -0
  74. data/spec/bson/byte_buffer_spec.rb +1 -0
  75. data/spec/bson/byte_buffer_write_spec.rb +1 -0
  76. data/spec/bson/code_spec.rb +5 -3
  77. data/spec/bson/code_with_scope_spec.rb +5 -3
  78. data/spec/bson/config_spec.rb +1 -35
  79. data/spec/bson/date_spec.rb +1 -0
  80. data/spec/bson/date_time_spec.rb +1 -0
  81. data/spec/bson/dbref_legacy_spec.rb +20 -3
  82. data/spec/bson/dbref_spec.rb +9 -9
  83. data/spec/bson/decimal128_spec.rb +40 -20
  84. data/spec/bson/document_as_spec.rb +1 -0
  85. data/spec/bson/document_spec.rb +1 -1
  86. data/spec/bson/ext_json_parse_spec.rb +1 -0
  87. data/spec/bson/false_class_spec.rb +8 -0
  88. data/spec/bson/float_spec.rb +8 -3
  89. data/spec/bson/hash_as_spec.rb +1 -0
  90. data/spec/bson/hash_spec.rb +87 -75
  91. data/spec/bson/int32_spec.rb +21 -6
  92. data/spec/bson/int64_spec.rb +21 -6
  93. data/spec/bson/integer_spec.rb +45 -13
  94. data/spec/bson/json_spec.rb +1 -0
  95. data/spec/bson/max_key_spec.rb +5 -3
  96. data/spec/bson/min_key_spec.rb +5 -3
  97. data/spec/bson/nil_class_spec.rb +1 -0
  98. data/spec/bson/object_id_spec.rb +57 -4
  99. data/spec/bson/object_spec.rb +2 -1
  100. data/spec/bson/open_struct_spec.rb +14 -71
  101. data/spec/bson/raw_spec.rb +9 -15
  102. data/spec/bson/regexp_spec.rb +4 -3
  103. data/spec/bson/registry_spec.rb +2 -1
  104. data/spec/bson/string_spec.rb +13 -38
  105. data/spec/bson/symbol_raw_spec.rb +25 -0
  106. data/spec/bson/symbol_spec.rb +15 -18
  107. data/spec/bson/time_spec.rb +1 -0
  108. data/spec/bson/time_with_zone_spec.rb +1 -0
  109. data/spec/bson/timestamp_spec.rb +1 -0
  110. data/spec/bson/true_class_spec.rb +8 -0
  111. data/spec/bson/undefined_spec.rb +27 -0
  112. data/spec/bson_spec.rb +1 -0
  113. data/spec/runners/common_driver.rb +6 -5
  114. data/spec/runners/corpus.rb +6 -0
  115. data/spec/runners/corpus_legacy.rb +1 -0
  116. data/spec/spec_helper.rb +1 -0
  117. data/spec/spec_tests/common_driver_spec.rb +9 -4
  118. data/spec/spec_tests/corpus_legacy_spec.rb +1 -0
  119. data/spec/spec_tests/corpus_spec.rb +13 -3
  120. data/spec/spec_tests/data/corpus/binary.json +5 -0
  121. data/spec/spec_tests/data/corpus/code.json +13 -13
  122. data/spec/spec_tests/data/corpus/decimal128-4.json +48 -0
  123. data/spec/spec_tests/data/corpus/decimal128-6.json +12 -0
  124. data/spec/spec_tests/data/corpus/decimal128-7.json +4 -0
  125. data/spec/spec_tests/data/corpus/document.json +20 -0
  126. data/spec/spec_tests/data/corpus/symbol.json +7 -7
  127. data/spec/spec_tests/data/corpus/top.json +18 -3
  128. data/spec/support/shared_examples.rb +28 -5
  129. data/spec/support/spec_config.rb +1 -0
  130. data/spec/support/utils.rb +49 -1
  131. metadata +114 -164
  132. checksums.yaml.gz.sig +0 -0
  133. data/spec/shared/LICENSE +0 -20
  134. data/spec/shared/bin/get-mongodb-download-url +0 -17
  135. data/spec/shared/bin/s3-copy +0 -45
  136. data/spec/shared/bin/s3-upload +0 -69
  137. data/spec/shared/lib/mrss/child_process_helper.rb +0 -80
  138. data/spec/shared/lib/mrss/cluster_config.rb +0 -231
  139. data/spec/shared/lib/mrss/constraints.rb +0 -386
  140. data/spec/shared/lib/mrss/docker_runner.rb +0 -271
  141. data/spec/shared/lib/mrss/event_subscriber.rb +0 -200
  142. data/spec/shared/lib/mrss/lite_constraints.rb +0 -191
  143. data/spec/shared/lib/mrss/server_version_registry.rb +0 -120
  144. data/spec/shared/lib/mrss/spec_organizer.rb +0 -179
  145. data/spec/shared/lib/mrss/utils.rb +0 -15
  146. data/spec/shared/share/Dockerfile.erb +0 -338
  147. data/spec/shared/share/haproxy-1.conf +0 -16
  148. data/spec/shared/share/haproxy-2.conf +0 -17
  149. data/spec/shared/shlib/distro.sh +0 -74
  150. data/spec/shared/shlib/server.sh +0 -367
  151. data/spec/shared/shlib/set_env.sh +0 -131
  152. data.tar.gz.sig +0 -0
  153. metadata.gz.sig +0 -1
@@ -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::ObjectId::Invalid)
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 BSON::BigDecimal do
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.to_big_decimal)
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::Decimal128::InvalidRange)
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::Decimal128::UnrepresentablePrecision)
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
@@ -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
- describe "#eql?" do
24
- context "for two equal objects" do
25
- it "returns true" do
26
- expect(testing1).to eql(testing2)
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
- context "for two different objects" do
31
- it "returns false" do
32
- expect(testing1).not_to eql(not_testing)
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 "#as_json" do
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.as_json).to eq(
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 "a JSON serializable object"
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 he type is invalid" do
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::Binary::InvalidType)
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
- context "when the type is :generic" do
166
-
167
- let(:obj) { described_class.new("testing") }
168
- let(:bson) { "#{7.to_bson}#{0.chr}testing" }
169
-
170
- it_behaves_like "a serializable bson element"
171
- it_behaves_like "a deserializable bson element"
172
- end
173
-
174
- context "when the type is :function" do
175
-
176
- let(:obj) { described_class.new("testing", :function) }
177
- let(:bson) { "#{7.to_bson}#{1.chr}testing" }
178
-
179
- it_behaves_like "a serializable bson element"
180
- it_behaves_like "a deserializable bson element"
181
- end
182
-
183
- context "when the type is :old" do
184
-
185
- let(:obj) { described_class.new("testing", :old) }
186
- let(:bson) { "#{11.to_bson}#{2.chr}#{7.to_bson}testing" }
187
-
188
- it_behaves_like "a serializable bson element"
189
- it_behaves_like "a deserializable bson element"
190
- end
191
-
192
- context "when the type is :uuid_old" do
193
-
194
- let(:obj) { described_class.new("testing", :uuid_old) }
195
- let(:bson) { "#{7.to_bson}#{3.chr}testing" }
196
-
197
- it_behaves_like "a serializable bson element"
198
- it_behaves_like "a deserializable bson element"
199
- end
200
-
201
- context "when the type is :uuid" do
202
-
203
- let(:obj) { described_class.new("testing", :uuid) }
204
- let(:bson) { "#{7.to_bson}#{4.chr}testing" }
205
-
206
- it_behaves_like "a serializable bson element"
207
- it_behaves_like "a deserializable bson element"
208
- end
209
-
210
- context "when the type is :md5" do
211
-
212
- let(:obj) { described_class.new("testing", :md5) }
213
- let(:bson) { "#{7.to_bson}#{5.chr}testing" }
214
-
215
- it_behaves_like "a serializable bson element"
216
- it_behaves_like "a deserializable bson element"
217
- end
218
-
219
- context "when the type is :user" do
220
-
221
- let(:obj) { described_class.new("testing", :user) }
222
- let(:bson) { "#{7.to_bson}#{128.chr}testing" }
223
-
224
- it_behaves_like "a serializable bson element"
225
- it_behaves_like "a deserializable bson element"
226
- end
227
-
228
- context "when the type is :cyphertext" do
229
- let(:obj) { described_class.new("testing", :ciphertext) }
230
- let(:bson) { "#{7.to_bson}#{6.chr}testing" }
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
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  # Copyright (C) 2019-2020 MongoDB Inc.
2
3
  #
3
4
  # Licensed under the Apache License, Version 2.0 (the "License");
@@ -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");
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
 
3
4
  describe BSON::ByteBuffer do
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
 
3
4
  describe BSON::ByteBuffer do
@@ -1,3 +1,4 @@
1
+ # rubocop:todo all
1
2
  require 'spec_helper'
2
3
 
3
4
  describe BSON::ByteBuffer 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");
@@ -16,17 +17,18 @@ require "spec_helper"
16
17
 
17
18
  describe BSON::Code do
18
19
 
19
- describe "#as_json" do
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.as_json).to eq({ "$code" => "this.value = 5" })
27
+ expect(object.as_extended_json).to eq({ "$code" => "this.value = 5" })
27
28
  end
28
29
 
29
- it_behaves_like "a JSON serializable object"
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 "#as_json" do
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.as_json).to eq(
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 "a JSON serializable object"
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
@@ -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
@@ -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");
@@ -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");
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # encoding: utf-8
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
- describe BSON::DBRef do
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(ArgumentError)
96
+ end.should raise_error(BSON::Error::InvalidDBRefArgument)
80
97
  end
81
98
  end
82
99
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
- # encoding: utf-8
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 ArgumentError' do
82
+ it 'raises InvalidDBRefArgument' do
83
83
  lambda do
84
84
  dbref
85
- end.should raise_error(ArgumentError)
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 ArgumentError' do
95
+ it 'raises InvalidDBRefArgument' do
96
96
  lambda do
97
97
  dbref
98
- end.should raise_error(ArgumentError)
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(ArgumentError, /DBRef must have \$ref/)
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(ArgumentError, /DBRef must have \$id/)
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(ArgumentError, /The value for key \$ref must be a string/)
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(ArgumentError, /The value for key \$db must be a string/)
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