mongodb-mongo 0.2.5 → 0.2.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/mongo/db.rb +2 -2
- data/lib/mongo/util/bson.rb +14 -1
- data/mongo-ruby-driver.gemspec +1 -1
- data/tests/test_bson.rb +16 -0
- data/tests/test_db_api.rb +10 -0
- metadata +1 -1
data/lib/mongo/db.rb
CHANGED
@@ -254,8 +254,8 @@ module XGen
|
|
254
254
|
doc['err']
|
255
255
|
end
|
256
256
|
|
257
|
-
# Returns +true+ if
|
258
|
-
#
|
257
|
+
# Returns +true+ if an error was caused by the most recently executed
|
258
|
+
# database operation.
|
259
259
|
#
|
260
260
|
# Note: as of this writing, errors are only detected on the db server
|
261
261
|
# for certain kinds of operations (writes). The plan is to change this
|
data/lib/mongo/util/bson.rb
CHANGED
@@ -333,7 +333,20 @@ class BSON
|
|
333
333
|
def serialize_object_element(buf, key, val, opcode=OBJECT)
|
334
334
|
buf.put(opcode)
|
335
335
|
self.class.serialize_cstr(buf, key)
|
336
|
-
buf.put_array(BSON.new.serialize(val).to_a)
|
336
|
+
buf.put_array(BSON.new.serialize(put_id_first(val)).to_a)
|
337
|
+
end
|
338
|
+
|
339
|
+
# For internal use only. Looks for '_id' or :_id key of val. If there is
|
340
|
+
# one, returns an OrderedHash where '_id' is first. If not, returns val.
|
341
|
+
def put_id_first(val)
|
342
|
+
oid = val.delete('_id') || val.delete(:_id)
|
343
|
+
if oid
|
344
|
+
h = OrderedHash.new
|
345
|
+
h['_id'] = oid
|
346
|
+
val.each { |k, v| h[k] = v }
|
347
|
+
val = h
|
348
|
+
end
|
349
|
+
val
|
337
350
|
end
|
338
351
|
|
339
352
|
def serialize_array_element(buf, key, val)
|
data/mongo-ruby-driver.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'mongo'
|
3
|
-
s.version = '0.2.
|
3
|
+
s.version = '0.2.6'
|
4
4
|
s.platform = Gem::Platform::RUBY
|
5
5
|
s.summary = 'Simple pure-Ruby driver for the 10gen Mongo DB'
|
6
6
|
s.description = 'A pure-Ruby driver for the 10gen Mongo DB. For more information about Mongo, see http://www.mongodb.org.'
|
data/tests/test_bson.rb
CHANGED
@@ -132,4 +132,20 @@ class BSONTest < Test::Unit::TestCase
|
|
132
132
|
assert_kind_of Undefined, doc2['undef']
|
133
133
|
end
|
134
134
|
|
135
|
+
def test_put_id_first
|
136
|
+
val = {'a' => 'foo'}
|
137
|
+
assert_same val, @b.put_id_first(val)
|
138
|
+
|
139
|
+
val = OrderedHash.new
|
140
|
+
val['not_id'] = 1
|
141
|
+
val['_id'] = 2
|
142
|
+
id_first = @b.put_id_first(val)
|
143
|
+
assert_equal ['_id', 'not_id'], id_first.keys
|
144
|
+
|
145
|
+
val = {'a' => 'foo', 'b' => 'bar', :_id => 42, 'z' => 'hello'}
|
146
|
+
id_first = @b.put_id_first(val)
|
147
|
+
assert id_first.keys.include?('_id')
|
148
|
+
assert !id_first.keys.include?(:_id)
|
149
|
+
end
|
150
|
+
|
135
151
|
end
|
data/tests/test_db_api.rb
CHANGED
@@ -286,6 +286,16 @@ class DBAPITest < Test::Unit::TestCase
|
|
286
286
|
assert_equal regex, rows[0]['b']
|
287
287
|
end
|
288
288
|
|
289
|
+
def test_non_oid_id
|
290
|
+
# Note: can't use Time.new because that will include fractional seconds,
|
291
|
+
# which Mongo does not store.
|
292
|
+
t = Time.at(1234567890)
|
293
|
+
@coll << {'_id' => t}
|
294
|
+
rows = @coll.find({'_id' => t}).to_a
|
295
|
+
assert_equal 1, rows.length
|
296
|
+
assert_equal t, rows[0]['_id']
|
297
|
+
end
|
298
|
+
|
289
299
|
def test_strict
|
290
300
|
assert !@db.strict?
|
291
301
|
@db.strict = true
|