mongo 1.1 → 1.1.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.
- data/HISTORY +5 -0
- data/README.rdoc +8 -3
- data/Rakefile +4 -10
- data/lib/mongo.rb +6 -1
- data/lib/mongo/connection.rb +1 -2
- data/lib/mongo/gridfs/grid_io_fix.rb +38 -0
- data/mongo.gemspec +1 -1
- data/test/bson/bson_test.rb +65 -58
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +38 -0
- data/test/bson/json_test.rb +7 -6
- data/test/bson/object_id_test.rb +1 -3
- data/test/collection_test.rb +3 -3
- data/test/connection_test.rb +12 -18
- data/test/cursor_fail_test.rb +1 -2
- data/test/cursor_message_test.rb +1 -2
- data/test/cursor_test.rb +1 -2
- data/test/db_api_test.rb +7 -5
- data/test/db_test.rb +8 -10
- data/test/grid_file_system_test.rb +2 -3
- data/test/grid_io_test.rb +1 -2
- data/test/grid_test.rb +1 -2
- data/test/replica_sets/connect_test.rb +23 -0
- data/test/support/hash_with_indifferent_access.rb +199 -0
- data/test/support/keys.rb +45 -0
- data/test/test_helper.rb +37 -2
- data/test/threading/test_threading_large_pool.rb +1 -1
- data/test/threading_test.rb +1 -1
- metadata +169 -118
- data/test/bson/basic_test.rb +0 -99
- data/test/bson/bench_test.rb +0 -172
- data/test/bson/c_encode_test.rb +0 -51
- data/test/bson/java_bson_test.rb +0 -146
- data/test/bson/jruby_bson_test.rb +0 -24
- data/test/bson/jruby_encode_test.rb +0 -438
data/HISTORY
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
1.1.1 2010-10-14
|
2
|
+
* Several critical JRuby bug fixes
|
3
|
+
* Fixes for JRuby in 1.9 mode
|
4
|
+
* Check keys and move id only when necessary for JRuby encoder
|
5
|
+
|
1
6
|
1.1 2010-10-4
|
2
7
|
* Official JRuby support via Java extensons for BSON (beta)
|
3
8
|
* Connection#lock! and Connection#unlock! for easy fsync lock
|
data/README.rdoc
CHANGED
@@ -23,7 +23,7 @@ Here's a quick code sample. See the MongoDB Ruby Tutorial
|
|
23
23
|
|
24
24
|
=== Ruby Versions
|
25
25
|
|
26
|
-
The driver works and is consistently tested on Ruby 1.8.6, 1.8.7, and 1.9.1.
|
26
|
+
The driver works and is consistently tested on Ruby 1.8.6, 1.8.7, and 1.9.2, and JRuby 1.5.1.
|
27
27
|
|
28
28
|
Note that if you're on 1.8.7, be sure that you're using a patchlevel >= 249. There
|
29
29
|
are some IO bugs in earlier versions.
|
@@ -39,7 +39,7 @@ Then you can install the mongo gem as follows:
|
|
39
39
|
|
40
40
|
$ gem install mongo
|
41
41
|
|
42
|
-
The driver also requires the
|
42
|
+
The driver also requires the bson gem:
|
43
43
|
|
44
44
|
$ gem install bson
|
45
45
|
|
@@ -47,6 +47,11 @@ And for a significant performance boost, you'll want to install the C extensions
|
|
47
47
|
|
48
48
|
$ gem install bson_ext
|
49
49
|
|
50
|
+
Note that bson_ext isn't used with JRuby. Instead, some native Java extensions are bundled with the bson gem.
|
51
|
+
If you ever need to modify these extenions, you can recompile with the following rake task:
|
52
|
+
|
53
|
+
$ rake build:java
|
54
|
+
|
50
55
|
=== From the GitHub source
|
51
56
|
|
52
57
|
The source code is available at http://github.com/mongodb/mongo-ruby-driver.
|
@@ -290,7 +295,7 @@ the bson_ext C extension enabled.
|
|
290
295
|
|
291
296
|
$ rake test:c
|
292
297
|
|
293
|
-
|
298
|
+
If you want to test the basic Ruby encoder, or if you're running JRuby:
|
294
299
|
|
295
300
|
$ rake test:ruby
|
296
301
|
|
data/Rakefile
CHANGED
@@ -26,8 +26,8 @@ namespace :build do
|
|
26
26
|
jar_dir = File.join(java_dir, 'jar')
|
27
27
|
|
28
28
|
jruby_jar = File.join(jar_dir, 'jruby.jar')
|
29
|
-
mongo_jar = File.join(jar_dir, 'mongo.jar')
|
30
|
-
bson_jar = File.join(jar_dir, 'bson.jar')
|
29
|
+
mongo_jar = File.join(jar_dir, 'mongo-2.2.jar')
|
30
|
+
bson_jar = File.join(jar_dir, 'bson-2.2.jar')
|
31
31
|
|
32
32
|
src_base = File.join(java_dir, 'src')
|
33
33
|
|
@@ -65,7 +65,7 @@ namespace :test do
|
|
65
65
|
Rake::Task['test:pooled_threading'].invoke
|
66
66
|
Rake::Task['test:drop_databases'].invoke
|
67
67
|
end
|
68
|
-
|
68
|
+
|
69
69
|
Rake::TestTask.new(:unit) do |t|
|
70
70
|
t.test_files = FileList['test/unit/*_test.rb']
|
71
71
|
t.verbose = true
|
@@ -142,7 +142,7 @@ namespace :test do
|
|
142
142
|
end
|
143
143
|
|
144
144
|
Rake::TestTask.new(:bson) do |t|
|
145
|
-
t.test_files = FileList['test/
|
145
|
+
t.test_files = FileList['test/bson/*_test.rb']
|
146
146
|
t.verbose = true
|
147
147
|
end
|
148
148
|
|
@@ -172,12 +172,6 @@ task :ydoc do
|
|
172
172
|
system "yardoc lib/**/*.rb lib/mongo/**/*.rb lib/bson/**/*.rb -e docs/yard_ext.rb -p docs/templates -o #{out} --title MongoRuby-#{Mongo::VERSION}"
|
173
173
|
end
|
174
174
|
|
175
|
-
desc "Publish documentation to mongo.rubyforge.org"
|
176
|
-
task :publish => [:rdoc] do
|
177
|
-
# Assumes docs are in ./html
|
178
|
-
Rake::RubyForgePublisher.new(GEM, RUBYFORGE_USER).upload
|
179
|
-
end
|
180
|
-
|
181
175
|
namespace :gem do
|
182
176
|
|
183
177
|
desc "Install the gem locally"
|
data/lib/mongo.rb
CHANGED
@@ -3,7 +3,7 @@
|
|
3
3
|
$:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
4
4
|
|
5
5
|
module Mongo
|
6
|
-
VERSION = "1.1"
|
6
|
+
VERSION = "1.1.1"
|
7
7
|
end
|
8
8
|
|
9
9
|
module Mongo
|
@@ -50,4 +50,9 @@ require 'mongo/exceptions'
|
|
50
50
|
require 'mongo/gridfs/grid_ext'
|
51
51
|
require 'mongo/gridfs/grid'
|
52
52
|
require 'mongo/gridfs/grid_io'
|
53
|
+
if RUBY_PLATFORM =~ /java/
|
54
|
+
require 'mongo/gridfs/grid_io_fix'
|
55
|
+
end
|
53
56
|
require 'mongo/gridfs/grid_file_system'
|
57
|
+
|
58
|
+
|
data/lib/mongo/connection.rb
CHANGED
@@ -106,7 +106,6 @@ module Mongo
|
|
106
106
|
# Mutex for synchronizing pool access
|
107
107
|
@connection_mutex = Mutex.new
|
108
108
|
|
109
|
-
|
110
109
|
# Create a mutex when a new key, in this case a socket,
|
111
110
|
# is added to the hash.
|
112
111
|
@safe_mutexes = Hash.new { |h, k| h[k] = Mutex.new }
|
@@ -157,7 +156,7 @@ module Mongo
|
|
157
156
|
# @return [Mongo::Connection]
|
158
157
|
def self.multi(nodes, opts={})
|
159
158
|
unless nodes.length > 0 && nodes.all? {|n| n.is_a? Array}
|
160
|
-
raise MongoArgumentError, "Connection.
|
159
|
+
raise MongoArgumentError, "Connection.multi requires at least one node to be specified."
|
161
160
|
end
|
162
161
|
# Block returns an array, the first element being an array of nodes and the second an array
|
163
162
|
# of authorizations for the database.
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
# --
|
4
|
+
# Copyright (C) 2008-2010 10gen Inc.
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
# ++
|
18
|
+
|
19
|
+
module Mongo
|
20
|
+
class GridIO
|
21
|
+
|
22
|
+
# This fixes a comparson issue in JRuby 1.9
|
23
|
+
def get_md5
|
24
|
+
md5_command = BSON::OrderedHash.new
|
25
|
+
md5_command['filemd5'] = @files_id
|
26
|
+
md5_command['root'] = @fs_name
|
27
|
+
@server_md5 = @files.db.command(md5_command)['md5']
|
28
|
+
if @safe
|
29
|
+
@client_md5 = @local_md5.hexdigest
|
30
|
+
if @local_md5.to_s != @server_md5.to_s
|
31
|
+
raise GridMD5Failure, "File on server failed MD5 check"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@server_md5
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
data/mongo.gemspec
CHANGED
data/test/bson/bson_test.rb
CHANGED
@@ -12,32 +12,30 @@ rescue LoadError
|
|
12
12
|
warn 'Mocking time with zone'
|
13
13
|
module ActiveSupport
|
14
14
|
class TimeWithZone
|
15
|
+
def initialize(utc_time, zone)
|
16
|
+
end
|
15
17
|
end
|
16
18
|
end
|
17
|
-
Zone = ActiveSupport::TimeWithZone.new
|
19
|
+
Zone = ActiveSupport::TimeWithZone.new(Time.now.utc, 'EST')
|
18
20
|
end
|
19
21
|
|
20
22
|
class BSONTest < Test::Unit::TestCase
|
21
23
|
|
22
24
|
include BSON
|
23
25
|
|
24
|
-
# This setup allows us to change the decoders for
|
25
|
-
# cross-coder compatibility testing
|
26
26
|
def setup
|
27
27
|
@encoder = BSON::BSON_CODER
|
28
|
-
@decoder = @encoder
|
29
28
|
end
|
30
29
|
|
31
30
|
def assert_doc_pass(doc, options={})
|
32
31
|
bson = @encoder.serialize(doc)
|
33
32
|
if options[:debug]
|
34
|
-
puts "
|
33
|
+
puts "DEBUGGING DOC:"
|
35
34
|
p bson.to_a
|
36
35
|
puts "DESERIALIZES TO:"
|
37
|
-
p @decoder.deserialize(bson)
|
38
36
|
end
|
39
|
-
assert_equal @
|
40
|
-
assert_equal doc, @
|
37
|
+
assert_equal @encoder.serialize(doc).to_a, bson.to_a
|
38
|
+
assert_equal doc, @encoder.deserialize(bson)
|
41
39
|
end
|
42
40
|
|
43
41
|
def test_require_hash
|
@@ -76,23 +74,31 @@ class BSONTest < Test::Unit::TestCase
|
|
76
74
|
end
|
77
75
|
end
|
78
76
|
|
77
|
+
def test_round_trip
|
78
|
+
doc = {'doc' => 123}
|
79
|
+
@encoder.deserialize(@encoder.serialize(doc))
|
80
|
+
end
|
81
|
+
|
79
82
|
# In 1.8 we test that other string encodings raise an exception.
|
80
83
|
# In 1.9 we test that they get auto-converted.
|
81
84
|
if RUBY_VERSION < '1.9'
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
85
|
+
if ! RUBY_PLATFORM =~ /java/
|
86
|
+
require 'iconv'
|
87
|
+
def test_non_utf8_string
|
88
|
+
string = Iconv.conv('iso-8859-1', 'utf-8', 'aé')
|
89
|
+
doc = {'doc' => string}
|
90
|
+
assert_doc_pass(doc)
|
91
|
+
assert_raise InvalidStringEncoding do
|
92
|
+
@encoder.serialize(doc)
|
93
|
+
end
|
88
94
|
end
|
89
|
-
end
|
90
95
|
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
+
def test_non_utf8_key
|
97
|
+
key = Iconv.conv('iso-8859-1', 'utf-8', 'aé')
|
98
|
+
doc = {key => 'hello'}
|
99
|
+
assert_raise InvalidStringEncoding do
|
100
|
+
@encoder.serialize(doc)
|
101
|
+
end
|
96
102
|
end
|
97
103
|
end
|
98
104
|
else
|
@@ -167,7 +173,21 @@ class BSONTest < Test::Unit::TestCase
|
|
167
173
|
def test_object
|
168
174
|
doc = {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}}
|
169
175
|
assert_doc_pass(doc)
|
170
|
-
|
176
|
+
end
|
177
|
+
|
178
|
+
def test_embedded_document_with_nil
|
179
|
+
doc = {'doc' => {'age' => 42, 'name' => nil, 'shoe_size' => 9.5}}
|
180
|
+
assert_doc_pass(doc)
|
181
|
+
end
|
182
|
+
|
183
|
+
def test_embedded_document_with_date
|
184
|
+
doc = {'doc' => {'age' => 42, 'date' => Time.now.utc, 'shoe_size' => 9.5}}
|
185
|
+
bson = @encoder.serialize(doc)
|
186
|
+
doc2 = @encoder.deserialize(bson)
|
187
|
+
assert doc['doc']
|
188
|
+
assert_equal 42, doc['doc']['age']
|
189
|
+
assert_equal 9.5, doc['doc']['shoe_size']
|
190
|
+
assert_in_delta Time.now, doc['doc']['date'], 1
|
171
191
|
end
|
172
192
|
|
173
193
|
def test_oid
|
@@ -193,7 +213,7 @@ class BSONTest < Test::Unit::TestCase
|
|
193
213
|
def test_date
|
194
214
|
doc = {'date' => Time.now}
|
195
215
|
bson = @encoder.serialize(doc)
|
196
|
-
doc2 = @
|
216
|
+
doc2 = @encoder.deserialize(bson)
|
197
217
|
# Mongo only stores up to the millisecond
|
198
218
|
assert_in_delta doc['date'], doc2['date'], 0.001
|
199
219
|
end
|
@@ -201,7 +221,7 @@ class BSONTest < Test::Unit::TestCase
|
|
201
221
|
def test_date_returns_as_utc
|
202
222
|
doc = {'date' => Time.now}
|
203
223
|
bson = @encoder.serialize(doc)
|
204
|
-
doc2 = @
|
224
|
+
doc2 = @encoder.deserialize(bson)
|
205
225
|
assert doc2['date'].utc?
|
206
226
|
end
|
207
227
|
|
@@ -209,7 +229,7 @@ class BSONTest < Test::Unit::TestCase
|
|
209
229
|
begin
|
210
230
|
doc = {'date' => Time.utc(1600)}
|
211
231
|
bson = @encoder.serialize(doc)
|
212
|
-
doc2 = @
|
232
|
+
doc2 = @encoder.deserialize(bson)
|
213
233
|
# Mongo only stores up to the millisecond
|
214
234
|
assert_in_delta doc['date'], doc2['date'], 2
|
215
235
|
rescue ArgumentError
|
@@ -240,7 +260,7 @@ class BSONTest < Test::Unit::TestCase
|
|
240
260
|
doc = {}
|
241
261
|
doc['dbref'] = DBRef.new('namespace', oid)
|
242
262
|
bson = @encoder.serialize(doc)
|
243
|
-
doc2 = @
|
263
|
+
doc2 = @encoder.deserialize(bson)
|
244
264
|
|
245
265
|
# Java doesn't deserialize to DBRefs
|
246
266
|
if RUBY_PLATFORM =~ /java/
|
@@ -255,7 +275,7 @@ class BSONTest < Test::Unit::TestCase
|
|
255
275
|
def test_symbol
|
256
276
|
doc = {'sym' => :foo}
|
257
277
|
bson = @encoder.serialize(doc)
|
258
|
-
doc2 = @
|
278
|
+
doc2 = @encoder.deserialize(bson)
|
259
279
|
assert_equal :foo, doc2['sym']
|
260
280
|
end
|
261
281
|
|
@@ -265,7 +285,7 @@ class BSONTest < Test::Unit::TestCase
|
|
265
285
|
|
266
286
|
doc = {'bin' => bin}
|
267
287
|
bson = @encoder.serialize(doc)
|
268
|
-
doc2 = @
|
288
|
+
doc2 = @encoder.deserialize(bson)
|
269
289
|
bin2 = doc2['bin']
|
270
290
|
assert_kind_of Binary, bin2
|
271
291
|
assert_equal 'binstring', bin2.to_s
|
@@ -276,7 +296,7 @@ class BSONTest < Test::Unit::TestCase
|
|
276
296
|
b = Binary.new('somebinarystring')
|
277
297
|
doc = {'bin' => b}
|
278
298
|
bson = @encoder.serialize(doc)
|
279
|
-
doc2 = @
|
299
|
+
doc2 = @encoder.deserialize(bson)
|
280
300
|
bin2 = doc2['bin']
|
281
301
|
assert_kind_of Binary, bin2
|
282
302
|
assert_equal 'somebinarystring', bin2.to_s
|
@@ -288,7 +308,7 @@ class BSONTest < Test::Unit::TestCase
|
|
288
308
|
|
289
309
|
doc = {'bin' => bin}
|
290
310
|
bson = @encoder.serialize(doc)
|
291
|
-
doc2 = @
|
311
|
+
doc2 = @encoder.deserialize(bson)
|
292
312
|
bin2 = doc2['bin']
|
293
313
|
assert_kind_of Binary, bin2
|
294
314
|
assert_equal [1, 2, 3, 4, 5], bin2.to_a
|
@@ -302,7 +322,7 @@ class BSONTest < Test::Unit::TestCase
|
|
302
322
|
|
303
323
|
doc = {'bin' => bin}
|
304
324
|
bson = @encoder.serialize(doc)
|
305
|
-
doc2 = @
|
325
|
+
doc2 = @encoder.deserialize(bson)
|
306
326
|
bin2 = doc2['bin']
|
307
327
|
assert_kind_of Binary, bin2
|
308
328
|
assert_equal [1, 2, 3, 4, 5], bin2.to_a
|
@@ -316,7 +336,7 @@ class BSONTest < Test::Unit::TestCase
|
|
316
336
|
|
317
337
|
doc = {'bin' => bb}
|
318
338
|
bson = @encoder.serialize(doc)
|
319
|
-
doc2 = @
|
339
|
+
doc2 = @encoder.deserialize(bson)
|
320
340
|
bin2 = doc2['bin']
|
321
341
|
assert_kind_of Binary, bin2
|
322
342
|
assert_equal [1, 2, 3, 4, 5], bin2.to_a
|
@@ -327,12 +347,12 @@ class BSONTest < Test::Unit::TestCase
|
|
327
347
|
val = BSON::OrderedHash.new
|
328
348
|
val['not_id'] = 1
|
329
349
|
val['_id'] = 2
|
330
|
-
roundtrip = @
|
350
|
+
roundtrip = @encoder.deserialize(@encoder.serialize(val, false, true).to_s)
|
331
351
|
assert_kind_of BSON::OrderedHash, roundtrip
|
332
352
|
assert_equal '_id', roundtrip.keys.first
|
333
353
|
|
334
354
|
val = {'a' => 'foo', 'b' => 'bar', :_id => 42, 'z' => 'hello'}
|
335
|
-
roundtrip = @
|
355
|
+
roundtrip = @encoder.deserialize(@encoder.serialize(val, false, true).to_s)
|
336
356
|
assert_kind_of BSON::OrderedHash, roundtrip
|
337
357
|
assert_equal '_id', roundtrip.keys.first
|
338
358
|
end
|
@@ -345,7 +365,7 @@ class BSONTest < Test::Unit::TestCase
|
|
345
365
|
if !(RUBY_PLATFORM =~ /java/)
|
346
366
|
def test_timestamp
|
347
367
|
val = {"test" => [4, 20]}
|
348
|
-
assert_equal val, @
|
368
|
+
assert_equal val, @encoder.deserialize([0x13, 0x00, 0x00, 0x00,
|
349
369
|
0x11, 0x74, 0x65, 0x73,
|
350
370
|
0x74, 0x00, 0x04, 0x00,
|
351
371
|
0x00, 0x00, 0x14, 0x00,
|
@@ -424,6 +444,14 @@ class BSONTest < Test::Unit::TestCase
|
|
424
444
|
assert_equal @encoder.serialize(one).to_a, @encoder.serialize(dup).to_a
|
425
445
|
end
|
426
446
|
|
447
|
+
def test_duplicate_keys
|
448
|
+
#dup = {"_foo" => "foo", :_foo => "foo"}
|
449
|
+
#one = {"_foo" => "foo"}
|
450
|
+
|
451
|
+
#assert_equal @encoder.serialize(one).to_a, @encoder.serialize(dup).to_a
|
452
|
+
warn "Pending test for duplicate keys"
|
453
|
+
end
|
454
|
+
|
427
455
|
def test_no_duplicate_id_when_moving_id
|
428
456
|
dup = {"_id" => "foo", :_id => "foo"}
|
429
457
|
one = {:_id => "foo"}
|
@@ -477,12 +505,9 @@ class BSONTest < Test::Unit::TestCase
|
|
477
505
|
"\000\004\000\000\000abc\000\002key\000\004\000\000\000abc\000\000",
|
478
506
|
@encoder.serialize(a, false, true).to_s
|
479
507
|
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
"\000\004\000\000\000abc\000\020_id\000\001\000\000\000\000",
|
484
|
-
@encoder.serialize(a, false, false).to_s
|
485
|
-
end
|
508
|
+
assert_equal ")\000\000\000\002text\000\004\000\000\000abc\000\002key" +
|
509
|
+
"\000\004\000\000\000abc\000\020_id\000\001\000\000\000\000",
|
510
|
+
@encoder.serialize(a, false, false).to_s
|
486
511
|
end
|
487
512
|
|
488
513
|
def test_move_id_with_nested_doc
|
@@ -507,22 +532,4 @@ class BSONTest < Test::Unit::TestCase
|
|
507
532
|
end
|
508
533
|
end
|
509
534
|
|
510
|
-
# Mocking this class for testing
|
511
|
-
class ::HashWithIndifferentAccess < Hash; end
|
512
|
-
|
513
|
-
def test_keep_id_with_hash_with_indifferent_access
|
514
|
-
doc = HashWithIndifferentAccess.new
|
515
|
-
embedded = HashWithIndifferentAccess.new
|
516
|
-
embedded['_id'] = ObjectId.new
|
517
|
-
doc['_id'] = ObjectId.new
|
518
|
-
doc['embedded'] = [embedded]
|
519
|
-
@encoder.serialize(doc, false, true).to_a
|
520
|
-
assert doc.has_key?("_id")
|
521
|
-
assert doc['embedded'][0].has_key?("_id")
|
522
|
-
|
523
|
-
doc['_id'] = ObjectId.new
|
524
|
-
@encoder.serialize(doc, false, true).to_a
|
525
|
-
assert doc.has_key?("_id")
|
526
|
-
end
|
527
|
-
|
528
535
|
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding:utf-8
|
2
|
+
require './test/test_helper'
|
3
|
+
require './test/support/hash_with_indifferent_access'
|
4
|
+
|
5
|
+
class HashWithIndifferentAccessTest < Test::Unit::TestCase
|
6
|
+
include BSON
|
7
|
+
|
8
|
+
def setup
|
9
|
+
@encoder = BSON::BSON_CODER
|
10
|
+
end
|
11
|
+
|
12
|
+
def test_document
|
13
|
+
doc = HashWithIndifferentAccess.new
|
14
|
+
doc['foo'] = 1
|
15
|
+
doc['bar'] = 'baz'
|
16
|
+
|
17
|
+
bson = @encoder.serialize(doc)
|
18
|
+
assert_equal doc, @encoder.deserialize(bson.to_s)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_embedded_document
|
22
|
+
jimmy = HashWithIndifferentAccess.new
|
23
|
+
jimmy['name'] = 'Jimmy'
|
24
|
+
jimmy['species'] = 'Siberian Husky'
|
25
|
+
|
26
|
+
stats = HashWithIndifferentAccess.new
|
27
|
+
stats['eyes'] = 'blue'
|
28
|
+
|
29
|
+
person = HashWithIndifferentAccess.new
|
30
|
+
person['_id'] = BSON::ObjectId.new
|
31
|
+
person['name'] = 'Mr. Pet Lover'
|
32
|
+
person['pets'] = [jimmy, {'name' => 'Sasha'}]
|
33
|
+
person['stats'] = stats
|
34
|
+
|
35
|
+
bson = @encoder.serialize(person)
|
36
|
+
assert_equal person, @encoder.deserialize(bson.to_s)
|
37
|
+
end
|
38
|
+
end
|