bson 2.0.0.rc2 → 2.0.0.rc3

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of bson might be problematic. Click here for more details.

Files changed (68) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE +1 -1
  5. data/NOTICE +1 -1
  6. data/README.md +1 -1
  7. data/Rakefile +9 -3
  8. data/ext/bson/native.c +16 -23
  9. data/lib/bson.rb +1 -1
  10. data/lib/bson/array.rb +18 -1
  11. data/lib/bson/binary.rb +56 -1
  12. data/lib/bson/boolean.rb +1 -1
  13. data/lib/bson/code.rb +1 -1
  14. data/lib/bson/code_with_scope.rb +1 -1
  15. data/lib/bson/document.rb +1 -1
  16. data/lib/bson/encodable.rb +1 -1
  17. data/lib/bson/environment.rb +1 -1
  18. data/lib/bson/false_class.rb +1 -1
  19. data/lib/bson/float.rb +1 -1
  20. data/lib/bson/hash.rb +1 -1
  21. data/lib/bson/int32.rb +1 -1
  22. data/lib/bson/int64.rb +1 -1
  23. data/lib/bson/integer.rb +1 -1
  24. data/lib/bson/json.rb +1 -1
  25. data/lib/bson/max_key.rb +1 -1
  26. data/lib/bson/min_key.rb +1 -1
  27. data/lib/bson/nil_class.rb +1 -1
  28. data/lib/bson/object_id.rb +28 -6
  29. data/lib/bson/regexp.rb +1 -1
  30. data/lib/bson/registry.rb +1 -1
  31. data/lib/bson/specialized.rb +1 -1
  32. data/lib/bson/string.rb +18 -1
  33. data/lib/bson/symbol.rb +1 -1
  34. data/lib/bson/time.rb +1 -1
  35. data/lib/bson/timestamp.rb +1 -1
  36. data/lib/bson/true_class.rb +1 -1
  37. data/lib/bson/undefined.rb +1 -1
  38. data/lib/bson/version.rb +2 -2
  39. data/spec/bson/array_spec.rb +28 -1
  40. data/spec/bson/binary_spec.rb +13 -1
  41. data/spec/bson/boolean_spec.rb +1 -1
  42. data/spec/bson/code_spec.rb +1 -1
  43. data/spec/bson/code_with_scope_spec.rb +1 -1
  44. data/spec/bson/document_spec.rb +1 -1
  45. data/spec/bson/false_class_spec.rb +1 -1
  46. data/spec/bson/float_spec.rb +1 -1
  47. data/spec/bson/hash_spec.rb +1 -1
  48. data/spec/bson/int32_spec.rb +1 -1
  49. data/spec/bson/int64_spec.rb +1 -1
  50. data/spec/bson/integer_spec.rb +1 -1
  51. data/spec/bson/json_spec.rb +1 -1
  52. data/spec/bson/max_key_spec.rb +1 -1
  53. data/spec/bson/min_key_spec.rb +1 -1
  54. data/spec/bson/nil_class_spec.rb +1 -1
  55. data/spec/bson/object_id_spec.rb +29 -1
  56. data/spec/bson/regexp_spec.rb +1 -1
  57. data/spec/bson/registry_spec.rb +1 -1
  58. data/spec/bson/string_spec.rb +28 -1
  59. data/spec/bson/symbol_spec.rb +1 -1
  60. data/spec/bson/time_spec.rb +1 -1
  61. data/spec/bson/timestamp_spec.rb +1 -1
  62. data/spec/bson/true_class_spec.rb +1 -1
  63. data/spec/bson/undefined_spec.rb +1 -1
  64. data/spec/bson_spec.rb +1 -1
  65. data/spec/spec_helper.rb +1 -1
  66. data/spec/support/shared_examples.rb +1 -1
  67. metadata +2 -2
  68. metadata.gz.sig +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 26c195c903e73023d0f0ddbc6bd8b802965a2a32
4
- data.tar.gz: 5a678021165a243c12330f9bc5fa8f192ea2beaa
3
+ metadata.gz: 41a5e08411dc7f036bd335197bfae4940fc8e581
4
+ data.tar.gz: 442009c85516195c17958b9902b05882d0b52e02
5
5
  SHA512:
6
- metadata.gz: ce3afab5e81c5c6179e715637693765e54fdb9d459b79684ec8210b862ec73b7940b10aa527bbf7bc9dfece19a69b01f4c86adccaadbf18f33ba5ec407cf9454
7
- data.tar.gz: 55ebdf9995b846d805666bab644ca34df8b90d37ced302fe4eb2d921240d6a023290a84dd8ac651dac8cadcffea5a685ccb13858c90a59776d78b929c1f7b1bb
6
+ metadata.gz: ac26809de3598a7fd2482a800677dbc43311394a0e78710d62d0a64147dd491e9d73518c448ef9198771824bb87f5fccafcf952478e42590378961e251e1c525
7
+ data.tar.gz: 7c82220f69ed5a030707ab67da9e7dcc328c4541769d1a0bc3eaf893d3f3fa3971a2565131fbde8de3ffbb86ea8ff5b20f81136f875be3254f6bca6b4f386ea9
Binary file
data.tar.gz.sig CHANGED
Binary file
data/LICENSE CHANGED
@@ -175,7 +175,7 @@
175
175
 
176
176
  END OF TERMS AND CONDITIONS
177
177
 
178
- Copyright (C) 2008-2013 10gen, Inc.
178
+ Copyright (C) 2008-2013 MongoDB, Inc.
179
179
 
180
180
  Licensed under the Apache License, Version 2.0 (the "License");
181
181
  you may not use this file except in compliance with the License.
data/NOTICE CHANGED
@@ -1,2 +1,2 @@
1
1
  Ruby BSON
2
- Copyright (C) 2009-2013 10gen, Inc.
2
+ Copyright (C) 2009-2013 MongoDB, Inc.
data/README.md CHANGED
@@ -175,7 +175,7 @@ As of 2.0.0, this project adheres to the [Semantic Versioning Specification](htt
175
175
  License
176
176
  -------
177
177
 
178
- Copyright (C) 2013 10gen Inc.
178
+ Copyright (C) 2013 MongoDB Inc.
179
179
 
180
180
  Licensed under the Apache License, Version 2.0 (the "License");
181
181
  you may not use this file except in compliance with the License.
data/Rakefile CHANGED
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -78,11 +78,17 @@ task :clean_all => :clean do
78
78
  end
79
79
  end
80
80
 
81
+ # Run bundle exec rake release with mri and jruby.
81
82
  task :release => :build do
82
83
  system "git tag -a v#{BSON::VERSION} -m 'Tagging release: #{BSON::VERSION}'"
83
84
  system "git push --tags"
84
- system "gem push bson-#{BSON::VERSION}.gem"
85
- system "rm bson-#{BSON::VERSION}.gem"
85
+ if jruby?
86
+ system "gem push bson-#{BSON::VERSION}-java.gem"
87
+ system "rm bson-#{BSON::VERSION}-java.gem"
88
+ else
89
+ system "gem push bson-#{BSON::VERSION}.gem"
90
+ system "rm bson-#{BSON::VERSION}.gem"
91
+ end
86
92
  end
87
93
 
88
94
  namespace :benchmark do
@@ -1,5 +1,5 @@
1
1
  /*
2
- * Copyright (C) 2013 10gen Inc.
2
+ * Copyright (C) 2013 MongoDB Inc.
3
3
  *
4
4
  * Licensed under the Apache License, Version 2.0 (the "License");
5
5
  * you may not use this file except in compliance with the License.
@@ -13,10 +13,20 @@
13
13
  * See the License for the specific language governing permissions and
14
14
  * limitations under the License.
15
15
  */
16
+ #ifdef MINGW32
17
+
18
+ #include <winsock2.h>
19
+ #include <windows.h>
20
+
21
+ #else
16
22
 
17
23
  #include <arpa/inet.h>
18
- #include <stdint.h>
19
24
  #include <sys/time.h>
25
+
26
+ #endif
27
+
28
+
29
+ #include <stdint.h>
20
30
  #include <sys/types.h>
21
31
  #include <time.h>
22
32
  #include <unistd.h>
@@ -223,23 +233,6 @@ static char rb_bson_machine_id[HOST_NAME_MAX];
223
233
  */
224
234
  static unsigned int rb_bson_object_id_counter = 0;
225
235
 
226
- /**
227
- * Get the current time in milliseconds, used in object id generation.
228
- *
229
- * @example Get the current time in milliseconds.
230
- * rb_current_time_milliseconds();
231
- *
232
- * @return [ int ] The current time in millis.
233
- *
234
- * @since 2.0.0
235
- */
236
- static unsigned long rb_current_time_milliseconds()
237
- {
238
- struct timeval time;
239
- gettimeofday(&time, NULL);
240
- return (time.tv_sec) * 1000 + (time.tv_usec) / 1000;
241
- }
242
-
243
236
  /**
244
237
  * Take the provided params and return the encoded bytes or a default one.
245
238
  *
@@ -318,17 +311,17 @@ static VALUE rb_float_from_bson_double(VALUE self, VALUE value)
318
311
  *
319
312
  * @since 2.0.0
320
313
  */
321
- static VALUE rb_object_id_generator_next(int argc, VALUE* time, VALUE self)
314
+ static VALUE rb_object_id_generator_next(int argc, VALUE* args, VALUE self)
322
315
  {
323
316
  char bytes[12];
324
317
  unsigned long t;
325
318
  unsigned short pid = htons(getpid());
326
319
 
327
- if (argc == 0 || (argc == 1 && *time == Qnil)) {
328
- t = rb_current_time_milliseconds();
320
+ if (argc == 0 || (argc == 1 && *args == Qnil)) {
321
+ t = htonl((int) time(NULL));
329
322
  }
330
323
  else {
331
- t = htonl(NUM2UINT(rb_funcall(*time, rb_intern("to_i"), 0)));
324
+ t = htonl(NUM2UINT(rb_funcall(*args, rb_intern("to_i"), 0)));
332
325
  }
333
326
 
334
327
  memcpy(&bytes, &t, 4);
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -51,6 +51,23 @@ module BSON
51
51
  end
52
52
  end
53
53
 
54
+ # Convert the array to an object id. This will only work for arrays of size
55
+ # 12 where the elements are all strings.
56
+ #
57
+ # @example Convert the array to an object id.
58
+ # array.to_bson_object_id
59
+ #
60
+ # @note This is used for repairing legacy bson data.
61
+ #
62
+ # @raise [ InvalidObjectId ] If the array is not 12 elements.
63
+ #
64
+ # @return [ String ] The raw object id bytes.
65
+ #
66
+ # @since 2.0.0
67
+ def to_bson_object_id
68
+ ObjectId.repair(self) { pack("C*") }
69
+ end
70
+
54
71
  module ClassMethods
55
72
 
56
73
  # Deserialize the array from BSON.
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -91,6 +91,7 @@ module BSON
91
91
  #
92
92
  # @since 2.0.0
93
93
  def initialize(data = "", type = :generic)
94
+ validate_type!(type)
94
95
  @data = data
95
96
  @type = type
96
97
  end
@@ -130,6 +131,60 @@ module BSON
130
131
  new(data, type)
131
132
  end
132
133
 
134
+ # Raised when providing an invalid type to the Binary.
135
+ #
136
+ # @since 2.0.0
137
+ class InvalidType < RuntimeError
138
+
139
+ # @!attribute type
140
+ # @return [ Object ] The invalid type.
141
+ # @since 2.0.0
142
+ attr_reader :type
143
+
144
+ # Instantiate the new error.
145
+ #
146
+ # @example Instantiate the error.
147
+ # InvalidType.new(:error)
148
+ #
149
+ # @param [ Object ] type The invalid type.
150
+ #
151
+ # @since 2.0.0
152
+ def initialize(type)
153
+ @type = type
154
+ end
155
+
156
+ # Get the custom error message for the exception.
157
+ #
158
+ # @example Get the message.
159
+ # error.message
160
+ #
161
+ # @return [ String ] The error message.
162
+ #
163
+ # @since 2.0.0
164
+ def message
165
+ "#{type.inspect} is not a valid binary type. " +
166
+ "Please use one of #{SUBTYPES.keys.map(&:inspect).join(", ")}."
167
+ end
168
+ end
169
+
170
+ private
171
+
172
+ # Validate the provided type is a valid type.
173
+ #
174
+ # @api private
175
+ #
176
+ # @example Validate the type.
177
+ # binary.validate_type!(:user)
178
+ #
179
+ # @param [ Object ] type The provided type.
180
+ #
181
+ # @raise [ InvalidType ] The the type is invalid.
182
+ #
183
+ # @since 2.0.0
184
+ def validate_type!(type)
185
+ raise InvalidType.new(type) unless SUBTYPES.has_key?(type)
186
+ end
187
+
133
188
  # Register this type when the module is loaded.
134
189
  #
135
190
  # @since 2.0.0
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -158,7 +158,7 @@ module BSON
158
158
  # @example Get the raw bson bytes.
159
159
  # object_id.to_bson
160
160
  #
161
- # @note Since Moped's BSON and 10gen BSON before 2.0.0 have different
161
+ # @note Since Moped's BSON and MongoDB BSON before 2.0.0 have different
162
162
  # internal representations, we will attempt to repair the data for cases
163
163
  # where the object was instantiated in a non-standard way. (Like a
164
164
  # Marshal.load)
@@ -169,7 +169,7 @@ module BSON
169
169
  #
170
170
  # @since 2.0.0
171
171
  def to_bson(encoded = ''.force_encoding(BINARY))
172
- repair!(@data) if defined?(@data)
172
+ repair if defined?(@data)
173
173
  @raw_data ||= @@generator.next
174
174
  encoded << @raw_data
175
175
  end
@@ -194,8 +194,9 @@ module BSON
194
194
 
195
195
  private
196
196
 
197
- def data=(data)
198
- @raw_data = data
197
+ def repair
198
+ @raw_data = @data.to_bson_object_id
199
+ remove_instance_variable(:@data)
199
200
  end
200
201
 
201
202
  class << self
@@ -226,7 +227,7 @@ module BSON
226
227
  # @since 2.0.0
227
228
  def from_data(data)
228
229
  object_id = allocate
229
- object_id.send(:data=, data)
230
+ object_id.instance_variable_set(:@raw_data, data)
230
231
  object_id
231
232
  end
232
233
 
@@ -283,6 +284,27 @@ module BSON
283
284
  def legal?(string)
284
285
  string.to_s =~ /^[0-9a-f]{24}$/i ? true : false
285
286
  end
287
+
288
+ # Executes the provided block only if the size of the provided object is
289
+ # 12. Used in legacy id repairs.
290
+ #
291
+ # @example Execute in a repairing block.
292
+ # BSON::ObjectId.repair("test") { obj }
293
+ #
294
+ # @param [ String, Array ] object The object to repair.
295
+ #
296
+ # @raise [ Invalid ] If the array is not 12 elements.
297
+ #
298
+ # @return [ String ] The result of the block.
299
+ #
300
+ # @since 2.0.0
301
+ def repair(object)
302
+ if object.size == 12
303
+ block_given? ? yield(object) : object
304
+ else
305
+ raise Invalid.new("#{object.inspect} is not a valid object id.")
306
+ end
307
+ end
286
308
  end
287
309
 
288
310
  # Inner class that encapsulates the behaviour of actually generating each
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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,5 +1,5 @@
1
1
  # -*- coding: utf-8 -*-
2
- # Copyright (C) 2013 10gen Inc.
2
+ # Copyright (C) 2013 MongoDB Inc.
3
3
  #
4
4
  # Licensed under the Apache License, Version 2.0 (the "License");
5
5
  # you may not use this file except in compliance with the License.
@@ -80,6 +80,23 @@ module BSON
80
80
  to_bson_string(encoded) << NULL_BYTE
81
81
  end
82
82
 
83
+ # Convert the string to an object id. This will only work for strings of size
84
+ # 12.
85
+ #
86
+ # @example Convert the string to an object id.
87
+ # string.to_bson_object_id
88
+ #
89
+ # @note This is used for repairing legacy bson data.
90
+ #
91
+ # @raise [ InvalidObjectId ] If the string is not 12 elements.
92
+ #
93
+ # @return [ String ] The raw object id bytes.
94
+ #
95
+ # @since 2.0.0
96
+ def to_bson_object_id
97
+ ObjectId.repair(self)
98
+ end
99
+
83
100
  # Convert the string to a UTF-8 string then force to binary. This is so
84
101
  # we get errors for strings that are not UTF-8 encoded.
85
102
  #
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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 = "2.0.0.rc2"
16
+ VERSION = "2.0.0.rc3"
17
17
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -28,4 +28,31 @@ describe Array do
28
28
  it_behaves_like "a serializable bson element"
29
29
  it_behaves_like "a deserializable bson element"
30
30
  end
31
+
32
+ describe "#to_bson_object_id" do
33
+
34
+ context "when the array has 12 elements" do
35
+
36
+ let(:array) do
37
+ [ 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 ]
38
+ end
39
+
40
+ let(:converted) do
41
+ array.to_bson_object_id
42
+ end
43
+
44
+ it "returns the array as a string" do
45
+ expect(converted).to eq(array.pack("C*"))
46
+ end
47
+ end
48
+
49
+ context "when the array does not have 12 elements" do
50
+
51
+ it "raises an exception" do
52
+ expect {
53
+ [ 1 ].to_bson_object_id
54
+ }.to raise_error(BSON::ObjectId::Invalid)
55
+ end
56
+ end
57
+ end
31
58
  end
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -31,6 +31,18 @@ describe BSON::Binary do
31
31
  it_behaves_like "a JSON serializable object"
32
32
  end
33
33
 
34
+ describe "#initialize" do
35
+
36
+ context "when he type is invalid" do
37
+
38
+ it "raises an error" do
39
+ expect {
40
+ described_class.new("testing", :error)
41
+ }.to raise_error(BSON::Binary::InvalidType)
42
+ end
43
+ end
44
+ end
45
+
34
46
  describe "#to_bson/#from_bson" do
35
47
 
36
48
  let(:type) { 5.chr }
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
3
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
@@ -444,6 +444,34 @@ describe BSON::ObjectId do
444
444
  end
445
445
  end
446
446
 
447
+ describe "#marshal_load" do
448
+
449
+ context "when the object id was dumped in the old format" do
450
+
451
+ let(:legacy) do
452
+ "\x04\bo:\x13BSON::ObjectId\x06:\n" +
453
+ "@data[\x11iUi\x01\xE2i,i\x00i\x00i\x00i\x00i\x00i\x00i\x00i\x00i\x00"
454
+ end
455
+
456
+ let(:object_id) do
457
+ Marshal.load(legacy)
458
+ end
459
+
460
+ let(:expected) do
461
+ described_class.from_time(Time.utc(2013, 1, 1))
462
+ end
463
+
464
+ it "properly loads the object id" do
465
+ expect(object_id).to eq(expected)
466
+ end
467
+
468
+ it "removes the bad legacy data" do
469
+ object_id.to_bson
470
+ expect(object_id.instance_variable_get(:@data)).to be_nil
471
+ end
472
+ end
473
+ end
474
+
447
475
  describe "#to_bson/#from_bson" do
448
476
 
449
477
  let(:time) { Time.utc(2013, 1, 1) }
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
3
+ # Copyright (C) 2013 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.
@@ -128,6 +128,33 @@ describe String do
128
128
  end
129
129
  end
130
130
 
131
+ describe "#to_bson_object_id" do
132
+
133
+ context "when the string has 12 characters" do
134
+
135
+ let(:string) do
136
+ "123456789012"
137
+ end
138
+
139
+ let(:converted) do
140
+ string.to_bson_object_id
141
+ end
142
+
143
+ it "returns the array as a string" do
144
+ expect(converted).to eq(string)
145
+ end
146
+ end
147
+
148
+ context "when the array does not have 12 elements" do
149
+
150
+ it "raises an exception" do
151
+ expect {
152
+ "test".to_bson_object_id
153
+ }.to raise_error(BSON::ObjectId::Invalid)
154
+ end
155
+ end
156
+ end
157
+
131
158
  describe "#to_bson_string" do
132
159
 
133
160
  context "when the string is valid" do
@@ -1,4 +1,4 @@
1
- # Copyright (C) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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) 2013 10gen Inc.
1
+ # Copyright (C) 2013 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.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bson
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc2
4
+ version: 2.0.0.rc3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tyler Brock
@@ -33,7 +33,7 @@ cert_chain:
33
33
  8v7zLF2XliYbfurYIwkcXs8yPn8ggApBIy9bX6VJxRs/l2+UvqzaHIFaFy/F8/GP
34
34
  RNTuXsVG5NDACo7Q
35
35
  -----END CERTIFICATE-----
36
- date: 2013-09-23 00:00:00.000000000 Z
36
+ date: 2013-10-14 00:00:00.000000000 Z
37
37
  dependencies: []
38
38
  description: A full featured BSON specification implementation, in Ruby
39
39
  email:
metadata.gz.sig CHANGED
Binary file