bson 4.3.0 → 4.4.1

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 (81) hide show
  1. checksums.yaml +5 -5
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/Rakefile +16 -9
  5. data/ext/bson/bson_native.c +102 -28
  6. data/lib/bson.rb +1 -1
  7. data/lib/bson/active_support.rb +17 -0
  8. data/lib/bson/array.rb +1 -1
  9. data/lib/bson/binary.rb +1 -1
  10. data/lib/bson/boolean.rb +1 -1
  11. data/lib/bson/code.rb +1 -1
  12. data/lib/bson/code_with_scope.rb +1 -1
  13. data/lib/bson/config.rb +1 -1
  14. data/lib/bson/date.rb +1 -1
  15. data/lib/bson/date_time.rb +1 -1
  16. data/lib/bson/decimal128.rb +1 -1
  17. data/lib/bson/decimal128/builder.rb +1 -1
  18. data/lib/bson/document.rb +42 -4
  19. data/lib/bson/environment.rb +1 -1
  20. data/lib/bson/false_class.rb +1 -1
  21. data/lib/bson/float.rb +1 -1
  22. data/lib/bson/hash.rb +1 -1
  23. data/lib/bson/int32.rb +17 -4
  24. data/lib/bson/int64.rb +17 -4
  25. data/lib/bson/integer.rb +2 -2
  26. data/lib/bson/json.rb +1 -1
  27. data/lib/bson/max_key.rb +1 -1
  28. data/lib/bson/min_key.rb +1 -1
  29. data/lib/bson/nil_class.rb +1 -1
  30. data/lib/bson/object.rb +1 -1
  31. data/lib/bson/object_id.rb +1 -1
  32. data/lib/bson/open_struct.rb +1 -1
  33. data/lib/bson/regexp.rb +1 -1
  34. data/lib/bson/registry.rb +1 -1
  35. data/lib/bson/specialized.rb +1 -1
  36. data/lib/bson/string.rb +1 -1
  37. data/lib/bson/symbol.rb +6 -3
  38. data/lib/bson/time.rb +1 -1
  39. data/lib/bson/time_with_zone.rb +54 -0
  40. data/lib/bson/timestamp.rb +1 -1
  41. data/lib/bson/true_class.rb +1 -1
  42. data/lib/bson/undefined.rb +1 -1
  43. data/lib/bson/version.rb +2 -2
  44. data/spec/bson/array_spec.rb +1 -1
  45. data/spec/bson/binary_spec.rb +1 -1
  46. data/spec/bson/boolean_spec.rb +1 -1
  47. data/spec/bson/byte_buffer_spec.rb +40 -0
  48. data/spec/bson/code_spec.rb +1 -1
  49. data/spec/bson/code_with_scope_spec.rb +1 -1
  50. data/spec/bson/date_spec.rb +1 -1
  51. data/spec/bson/date_time_spec.rb +1 -1
  52. data/spec/bson/decimal128_spec.rb +1 -1
  53. data/spec/bson/document_spec.rb +60 -1
  54. data/spec/bson/false_class_spec.rb +1 -1
  55. data/spec/bson/float_spec.rb +1 -1
  56. data/spec/bson/hash_spec.rb +1 -1
  57. data/spec/bson/int32_spec.rb +139 -3
  58. data/spec/bson/int64_spec.rb +139 -3
  59. data/spec/bson/integer_spec.rb +3 -3
  60. data/spec/bson/json_spec.rb +1 -1
  61. data/spec/bson/max_key_spec.rb +1 -1
  62. data/spec/bson/min_key_spec.rb +1 -1
  63. data/spec/bson/nil_class_spec.rb +1 -1
  64. data/spec/bson/object_id_spec.rb +1 -1
  65. data/spec/bson/object_spec.rb +1 -1
  66. data/spec/bson/open_struct_spec.rb +1 -1
  67. data/spec/bson/regexp_spec.rb +1 -1
  68. data/spec/bson/registry_spec.rb +1 -1
  69. data/spec/bson/string_spec.rb +1 -1
  70. data/spec/bson/symbol_spec.rb +3 -3
  71. data/spec/bson/time_spec.rb +1 -1
  72. data/spec/bson/time_with_zone_spec.rb +68 -0
  73. data/spec/bson/timestamp_spec.rb +1 -1
  74. data/spec/bson/true_class_spec.rb +1 -1
  75. data/spec/bson/undefined_spec.rb +1 -1
  76. data/spec/bson_spec.rb +1 -1
  77. data/spec/spec_helper.rb +15 -1
  78. data/spec/support/shared_examples.rb +1 -1
  79. data/spec/support/spec_config.rb +9 -0
  80. metadata +73 -68
  81. metadata.gz.sig +0 -0
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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).to_s }
96
+ let(:encoded) { (Integer::MAX_32BIT - 1) }
97
97
 
98
- it "returns the key as a string" do
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
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -138,10 +138,146 @@ describe BSON::Int64 do
138
138
  describe "#to_bson_key" do
139
139
 
140
140
  let(:obj) { BSON::Int64.new(Integer::MAX_64BIT - 1) }
141
- let(:encoded) { (Integer::MAX_64BIT - 1).to_s }
141
+ let(:encoded) { (Integer::MAX_64BIT - 1) }
142
142
 
143
- it "returns the key as a string" do
143
+ it "returns the key as an integer" do
144
144
  expect(obj.to_bson_key).to eq(encoded)
145
145
  end
146
146
  end
147
+
148
+ describe "#==" do
149
+
150
+ let(:object) do
151
+ described_class.new(1)
152
+ end
153
+
154
+ context "when data is identical" do
155
+
156
+ let(:other_object) do
157
+ described_class.new(1)
158
+ end
159
+
160
+ it "returns true" do
161
+ expect(object).to eq(other_object)
162
+ end
163
+
164
+ context "other object is of another integer type" do
165
+
166
+ let(:other_object) do
167
+ BSON::Int32.new(1)
168
+ end
169
+
170
+ it "returns false" do
171
+ expect(object).not_to eq(other_object)
172
+ end
173
+ end
174
+ end
175
+
176
+ context "when the data is different" do
177
+
178
+ let(:other_object) do
179
+ described_class.new(2)
180
+ end
181
+
182
+ it "returns false" do
183
+ expect(object).not_to eq(other_object)
184
+ end
185
+ end
186
+
187
+ context "when other is not a BSON integer" do
188
+
189
+ it "returns false" do
190
+ expect(described_class.new(1)).to_not eq('1')
191
+ end
192
+ end
193
+ end
194
+
195
+ describe "#===" do
196
+
197
+ let(:object) do
198
+ described_class.new(1)
199
+ end
200
+
201
+ context "when comparing with another BSON int64" do
202
+
203
+ context "when the data is equal" do
204
+
205
+ let(:other_object) do
206
+ described_class.new(1)
207
+ end
208
+
209
+ it "returns true" do
210
+ expect(object === other_object).to be true
211
+ end
212
+
213
+ context "other object is of another integer type" do
214
+
215
+ let(:other_object) do
216
+ BSON::Int32.new(1)
217
+ end
218
+
219
+ it "returns false" do
220
+ expect(object === other_object).to be false
221
+ end
222
+ end
223
+ end
224
+
225
+ context "when the data is not equal" do
226
+
227
+ let(:other_object) do
228
+ described_class.new(2)
229
+ end
230
+
231
+ it "returns false" do
232
+ expect(object === other_object).to be false
233
+ end
234
+ end
235
+ end
236
+
237
+ context "when comparing to an object id class" do
238
+
239
+ it "returns false" do
240
+ expect(described_class.new(1) === described_class).to be false
241
+ end
242
+ end
243
+
244
+ context "when comparing with a string" do
245
+
246
+ context "when the data is equal" do
247
+
248
+ let(:other) do
249
+ '1'
250
+ end
251
+
252
+ it "returns false" do
253
+ expect(object === other).to be false
254
+ end
255
+ end
256
+
257
+ context "when the data is not equal" do
258
+
259
+ let(:other) do
260
+ '2'
261
+ end
262
+
263
+ it "returns false" do
264
+ expect(object === other).to be false
265
+ end
266
+ end
267
+ end
268
+
269
+ context "when comparing with a non-bson integer object" do
270
+
271
+ it "returns false" do
272
+ expect(object === []).to be false
273
+ end
274
+ end
275
+
276
+ context "when comparing with a non int64 class" do
277
+
278
+ it "returns false" do
279
+ expect(object === String).to be false
280
+ end
281
+ end
282
+ end
147
283
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -62,9 +62,9 @@ describe Integer do
62
62
  describe "#to_bson_key" do
63
63
 
64
64
  let(:obj) { Integer::MAX_32BIT - 1 }
65
- let(:encoded) { obj.to_s }
65
+ let(:encoded) { obj }
66
66
 
67
- it "returns the key as a string" do
67
+ it "returns the key as an integer" do
68
68
  expect(obj.to_bson_key).to eq(encoded)
69
69
  end
70
70
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2016 MongoDB Inc.
1
+ # Copyright (C) 2016-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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,6 +1,6 @@
1
1
  # encoding: utf-8
2
2
 
3
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.
@@ -37,7 +37,7 @@ describe Symbol do
37
37
  describe "#to_bson_key" do
38
38
 
39
39
  let(:symbol) { :test }
40
- let(:encoded) { symbol.to_s }
40
+ let(:encoded) { symbol }
41
41
 
42
42
  it "returns the encoded string" do
43
43
  expect(symbol.to_bson_key).to eq(encoded)
@@ -66,7 +66,7 @@ describe Symbol do
66
66
  end
67
67
 
68
68
  it "allows invalid keys" do
69
- expect(symbol.to_bson_key).to eq(symbol.to_s)
69
+ expect(symbol.to_bson_key).to eq(symbol)
70
70
  end
71
71
  end
72
72
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2009-2014 MongoDB Inc.
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.