kbaum-mongo 0.18.3.2 → 0.19

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
 
3
3
  module Mongo
4
- VERSION = "0.18.3.2"
4
+ VERSION = "0.19"
5
5
  end
6
6
 
7
7
  begin
@@ -261,7 +261,7 @@ module Mongo
261
261
  message = ByteBuffer.new([0, 0, 0, 0])
262
262
  BSON_RUBY.serialize_cstr(message, "#{@db.name}.#{@name}")
263
263
  message.put_int(0)
264
- message.put_array(BSON.serialize(selector, false).to_a)
264
+ message.put_array(BSON.serialize(selector, false, true).to_a)
265
265
 
266
266
  if opts[:safe]
267
267
  @connection.send_message_with_safe_check(Mongo::Constants::OP_DELETE, message, @db.name,
@@ -303,7 +303,7 @@ module Mongo
303
303
  update_options += 1 if options[:upsert]
304
304
  update_options += 2 if options[:multi]
305
305
  message.put_int(update_options)
306
- message.put_array(BSON.serialize(selector, false).to_a)
306
+ message.put_array(BSON.serialize(selector, false, true).to_a)
307
307
  message.put_array(BSON.serialize(document, false, true).to_a)
308
308
  if options[:safe]
309
309
  @connection.send_message_with_safe_check(Mongo::Constants::OP_UPDATE, message, @db.name,
@@ -105,14 +105,14 @@ class BSON_RUBY
105
105
  # Write key/value pairs. Always write _id first if it exists.
106
106
  if move_id
107
107
  if obj.has_key? '_id'
108
- serialize_key_value('_id', obj['_id'], check_keys)
108
+ serialize_key_value('_id', obj['_id'], false)
109
109
  elsif obj.has_key? :_id
110
- serialize_key_value('_id', obj[:_id], check_keys)
110
+ serialize_key_value('_id', obj[:_id], false)
111
111
  end
112
112
  obj.each {|k, v| serialize_key_value(k, v, check_keys) unless k == '_id' || k == :_id }
113
113
  else
114
114
  if obj.has_key?('_id') && obj.has_key?(:_id)
115
- obj.delete(:_id)
115
+ obj['_id'] = obj.delete(:_id)
116
116
  end
117
117
  obj.each {|k, v| serialize_key_value(k, v, check_keys) }
118
118
  end
@@ -356,6 +356,13 @@ class BSONTest < Test::Unit::TestCase
356
356
  assert_equal BSON.serialize(one).to_a, BSON.serialize(dup).to_a
357
357
  end
358
358
 
359
+ def test_no_duplicate_id_when_moving_id
360
+ dup = {"_id" => "foo", :_id => "foo"}
361
+ one = {:_id => "foo"}
362
+
363
+ assert_equal BSON.serialize(one, false, true).to_s, BSON.serialize(dup, false, true).to_s
364
+ end
365
+
359
366
  def test_null_character
360
367
  doc = {"a" => "\x00"}
361
368
 
@@ -399,6 +406,7 @@ class BSONTest < Test::Unit::TestCase
399
406
  a['key'] = 'abc'
400
407
  a['_id'] = 1
401
408
 
409
+
402
410
  assert_equal ")\000\000\000\020_id\000\001\000\000\000\002text" +
403
411
  "\000\004\000\000\000abc\000\002key\000\004\000\000\000abc\000\000",
404
412
  BSON.serialize(a, false, true).to_s
@@ -424,4 +432,23 @@ class BSONTest < Test::Unit::TestCase
424
432
  "\000\002\000\000\000\000\020_id\000\003\000\000\000\000",
425
433
  BSON.serialize(c, false, false).to_s
426
434
  end
435
+
436
+ begin
437
+ require 'active_support'
438
+ rescue LoadError
439
+ warn 'Could not test BSON with HashWithIndifferentAccess.'
440
+ end
441
+
442
+ if defined?(HashWithIndifferentAccess)
443
+ def test_keep_id_with_hash_with_indifferent_access
444
+ doc = HashWithIndifferentAccess.new
445
+ doc[:_id] = ObjectID.new
446
+ BSON.serialize(doc, false, false).to_a
447
+ assert doc.has_key?("_id")
448
+
449
+ doc['_id'] = ObjectID.new
450
+ BSON.serialize(doc, false, false).to_a
451
+ assert doc.has_key?("_id")
452
+ end
453
+ end
427
454
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kbaum-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.3.2
4
+ version: "0.19"
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2010-02-26 00:00:00 -05:00
13
+ date: 2010-03-01 00:00:00 -05:00
14
14
  default_executable:
15
15
  dependencies: []
16
16