mongo 1.1 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,172 +0,0 @@
1
- # encoding:utf-8
2
- require './test/test_helper'
3
- require 'complex'
4
- require 'bigdecimal'
5
- require 'rational'
6
- require 'benchmark'
7
-
8
- MEDIUM = {
9
- 'integer' => 5,
10
- 'number' => 5.05,
11
- 'boolean' => false,
12
- 'array' => ['test', 'benchmark']
13
- }
14
-
15
-
16
- LARGE = {
17
- 'base_url' => 'http://www.example.com/test-me',
18
- 'total_word_count' => 6743,
19
- 'access_time' => 1,# Time.now,
20
- 'meta_tags' => {
21
- 'description' => 'i am a long description string',
22
- 'author' => 'Holly Man',
23
- 'dynamically_created_meta_tag' => 'who know\n what'
24
- },
25
- 'page_structure' => {
26
- 'counted_tags' => 3450,
27
- 'no_of_js_attached' => 10,
28
- 'no_of_images' => 6
29
- },
30
- 'harvested_words' => ['10gen','web','open','source','application','paas',
31
- 'platform-as-a-service','technology','helps',
32
- 'developers','focus','building','mongodb','mongo'] * 20
33
- }
34
-
35
-
36
-
37
- begin
38
- require 'active_support/core_ext'
39
- require 'active_support/hash_with_indifferent_access'
40
- Time.zone = "Pacific Time (US & Canada)"
41
- Zone = Time.zone.now
42
- rescue LoadError
43
- warn 'Could not test BSON with HashWithIndifferentAccess.'
44
- module ActiveSupport
45
- class TimeWithZone
46
- end
47
- end
48
- Zone = ActiveSupport::TimeWithZone.new
49
- end
50
-
51
- class BSONTest < Test::Unit::TestCase
52
- include BSON
53
-
54
- def setup
55
- @encoder = BSON::BSON_RUBY
56
- @decoder = BSON::BSON_RUBY
57
- @con = Mongo::Connection.new
58
- end
59
-
60
- def assert_doc_pass(doc, options={})
61
- bson = @encoder.serialize(doc)
62
- if options[:debug]
63
- puts "DEBUGGIN DOC:"
64
- p bson.to_a
65
- puts "DESERIALIZES TO:"
66
- p @decoder.deserialize(bson)
67
- end
68
- assert_equal @decoder.serialize(doc).to_a, bson.to_a
69
- assert_equal doc, @decoder.deserialize(bson)
70
- end
71
-
72
- # def test_bench_big_string
73
- # t0 = Time.now
74
- # @con['foo']['bar'].remove
75
- # doc = {'doc' => 'f' * 2_000_000}
76
- # 10.times do
77
- # @con['foo']['bar'].save({'d' => doc})
78
- # @con['foo']['bar'].find.to_a
79
- # end
80
- # puts "Big String"
81
- # puts Time.now - t0
82
- # end
83
- #
84
- # def test_big_array
85
- # t0 = Time.now
86
- # @con['foo']['bar'].remove
87
- # doc = {'doc' => 'f' * 2_000_000}
88
- # 10.times do
89
- # @con['foo']['bar'].save({'d' => doc})
90
- # @con['foo']['bar'].find.to_a
91
- # end
92
- # puts "Big String"
93
- # puts Time.now - t0
94
- # end
95
- #
96
- # def test_string
97
- # doc = {'doc' => "Hello world!", 'awesome' => true, 'a' => 1, 'b' => 4_333_433_232, 'c' => 2.33, 'd' => nil,
98
- # 'f' => BSON::Code.new("function"), 'g' => BSON::ObjectId.new, 'h' => [1, 2, 3]}
99
- # bson = @encoder.serialize(doc)
100
- # d = @encoder.deserialize(bson)
101
- # puts "Array"
102
- # puts d
103
- # puts d['h']
104
- # puts "End Array"
105
- # puts d['h'][0]
106
- # puts d['h'][1]
107
- # puts (d['h'][2] + 100).class
108
- # puts "ObjecId Info"
109
- # bson2 = @encoder.serialize(d)
110
- # doc2 = @encoder.deserialize(bson2)
111
- # assert_equal doc2, @encoder.deserialize(bson)
112
- # end
113
- #
114
-
115
- def test_eval
116
- code = BSON::Code.new('f')
117
- oh = BSON::OrderedHash.new
118
- oh[:$eval] = code
119
- oh[:args] = [1]
120
-
121
- assert_equal BSON::BSON_RUBY.serialize(oh).to_a, BSON::BSON_JAVA.serialize(oh).to_a
122
- assert_equal 3, @con['admin'].eval('function (x) {return x;}', 3)
123
- end
124
-
125
- # def test_oid
126
- # b = Java::OrgBsonTypes::ObjectId.new.toByteArray
127
- # o = ObjectId.new(b)
128
- # p o
129
- # end
130
- #
131
- def test_speed
132
- @con['foo']['bar'].remove
133
-
134
- puts "Test OID"
135
- t0 = Time.now
136
- 5000.times do
137
- ids = [BSON::ObjectId.new] * 1000
138
- @encoder.serialize({'doc' => BSON::ObjectId.new})
139
- end
140
- puts Time.now - t0
141
-
142
- puts "Decode OID"
143
- ids = [BSON::ObjectId.new] * 1000
144
- doc = {'doc' => ids}
145
- bson = @encoder.serialize(doc)
146
- t0 = Time.now
147
- 50.times do
148
- @encoder.deserialize(bson)
149
- end
150
- puts Time.now - t0
151
-
152
-
153
- puts "Test insert"
154
- t0 = Time.now
155
- 1000.times do |n|
156
- if n % 1000 == 0
157
- puts Time.now - t0
158
- t0 = Time.now
159
- end
160
- @con['foo']['bar'].insert({'doc' => MEDIUM})
161
- end
162
- puts Time.now - t0
163
-
164
- puts "Test query / deserialize"
165
- t0 = Time.now
166
- @con['foo']['bar'].find.to_a
167
- t1 = Time.now
168
- puts t1 - t0
169
- end
170
-
171
-
172
- end
@@ -1,51 +0,0 @@
1
- # encoding:utf-8
2
- require 'test/test_helper'
3
- require 'complex'
4
- require 'bigdecimal'
5
- require 'rational'
6
- require 'benchmark'
7
-
8
- MEDIUM = {
9
- 'integer' => 5,
10
- 'number' => 5.05,
11
- 'boolean' => false,
12
- 'array' => ['test', 'benchmark']
13
- }
14
-
15
-
16
- LARGE = {
17
- 'base_url' => 'http://www.example.com/test-me',
18
- 'total_word_count' => 6743,
19
- 'access_time' => 123, #Time.now,
20
- 'meta_tags' => {
21
- 'description' => 'i am a long description string',
22
- 'author' => 'Holly Man',
23
- 'dynamically_created_meta_tag' => 'who know\n what'
24
- },
25
- 'page_structure' => {
26
- 'counted_tags' => 3450,
27
- 'no_of_js_attached' => 10,
28
- 'no_of_images' => 6
29
- },
30
- 'harvested_words' => ['10gen','web','open','source','application','paas',
31
- 'platform-as-a-service','technology','helps',
32
- 'developers','focus','building','mongodb','mongo'] * 20
33
- }
34
-
35
- class CBSONTest < Test::Unit::TestCase
36
- include BSON
37
-
38
- def setup
39
- @encoder = BSON::BSON_CODER
40
- end
41
-
42
- def test_nested_string
43
- t0 = Time.now
44
- 50000.times do
45
- @encoder.serialize({'doc' => MEDIUM})
46
- end
47
- t1 = Time.now
48
- puts t1 - t0
49
- end
50
-
51
- end
@@ -1,146 +0,0 @@
1
- # encoding:utf-8
2
- require './test/test_helper'
3
- require 'complex'
4
- require 'bigdecimal'
5
- require 'rational'
6
- require 'benchmark'
7
-
8
- MEDIUM = {
9
- 'integer' => 5,
10
- 'number' => 5.05,
11
- 'boolean' => false,
12
- 'array' => ['test', 'benchmark']
13
- }
14
-
15
-
16
- LARGE = {
17
- 'base_url' => 'http://www.example.com/test-me',
18
- 'total_word_count' => 6743,
19
- 'access_time' => 1,# Time.now,
20
- 'meta_tags' => {
21
- 'description' => 'i am a long description string',
22
- 'author' => 'Holly Man',
23
- 'dynamically_created_meta_tag' => 'who know\n what'
24
- },
25
- 'page_structure' => {
26
- 'counted_tags' => 3450,
27
- 'no_of_js_attached' => 10,
28
- 'no_of_images' => 6
29
- },
30
- 'harvested_words' => ['10gen','web','open','source','application','paas',
31
- 'platform-as-a-service','technology','helps',
32
- 'developers','focus','building','mongodb','mongo'] * 20
33
- }
34
-
35
- # Tests and benchmarks specific to the JRuby BSON serializer
36
- if RUBY_PLATFORM =~ /java/
37
- class BSONTest < Test::Unit::TestCase
38
- include BSON
39
-
40
- def setup
41
- @encoder = BSON::BSON_RUBY
42
- @decoder = BSON::BSON_RUBY
43
- @con = Mongo::Connection.new
44
- end
45
-
46
- def assert_doc_pass(doc, options={})
47
- bson = @encoder.serialize(doc)
48
- if options[:debug]
49
- puts "DEBUGGIN DOC:"
50
- p bson.to_a
51
- puts "DESERIALIZES TO:"
52
- p @decoder.deserialize(bson)
53
- end
54
- assert_equal @decoder.serialize(doc).to_a, bson.to_a
55
- assert_equal doc, @decoder.deserialize(bson)
56
- end
57
-
58
- # def test_bench_big_string
59
- # t0 = Time.now
60
- # @con['foo']['bar'].remove
61
- # doc = {'doc' => 'f' * 2_000_000}
62
- # 10.times do
63
- # @con['foo']['bar'].save({'d' => doc})
64
- # @con['foo']['bar'].find.to_a
65
- # end
66
- # puts "Big String"
67
- # puts Time.now - t0
68
- # end
69
- #
70
- # def test_big_array
71
- # t0 = Time.now
72
- # @con['foo']['bar'].remove
73
- # doc = {'doc' => 'f' * 2_000_000}
74
- # 10.times do
75
- # @con['foo']['bar'].save({'d' => doc})
76
- # @con['foo']['bar'].find.to_a
77
- # end
78
- # puts "Big String"
79
- # puts Time.now - t0
80
- # end
81
- #
82
- # def test_string
83
- # doc = {'doc' => "Hello world!", 'awesome' => true, 'a' => 1, 'b' => 4_333_433_232, 'c' => 2.33, 'd' => nil,
84
- # 'f' => BSON::Code.new("function"), 'g' => BSON::ObjectId.new, 'h' => [1, 2, 3]}
85
- # bson = @encoder.serialize(doc)
86
- # d = @encoder.deserialize(bson)
87
- # puts "Array"
88
- # puts d
89
- # puts d['h']
90
- # puts "End Array"
91
- # puts d['h'][0]
92
- # puts d['h'][1]
93
- # puts (d['h'][2] + 100).class
94
- # puts "ObjecId Info"
95
- # bson2 = @encoder.serialize(d)
96
- # doc2 = @encoder.deserialize(bson2)
97
- # assert_equal doc2, @encoder.deserialize(bson)
98
- # end
99
- #
100
-
101
- def test_eval
102
- code = BSON::Code.new('f')
103
- oh = BSON::OrderedHash.new
104
- oh[:$eval] = code
105
- oh[:args] = [1]
106
-
107
- assert_equal BSON::BSON_RUBY.serialize(oh).to_a, BSON::BSON_JAVA.serialize(oh).to_a
108
- end
109
-
110
- # def test_oid
111
- # b = Java::OrgBsonTypes::ObjectId.new.toByteArray
112
- # o = ObjectId.new(b)
113
- # p o
114
- # end
115
- #
116
- # def test_speed
117
- # @con['foo']['bar'].remove
118
- #
119
- # puts "Test OID"
120
- # t0 = Time.now
121
- # 5000.times do
122
- # BSON::ObjectId.new
123
- # end
124
- # puts Time.now - t0
125
- #
126
- # puts "Test insert"
127
- # t0 = Time.now
128
- # 1000.times do |n|
129
- # if n % 1000 == 0
130
- # puts Time.now - t0
131
- # t0 = Time.now
132
- # end
133
- # @con['foo']['bar'].insert({'doc' => MEDIUM})
134
- # end
135
- # puts Time.now - t0
136
- #
137
- # puts "Test query / deserialize"
138
- # t0 = Time.now
139
- # @con['foo']['bar'].find.to_a
140
- # t1 = Time.now
141
- # puts t1 - t0
142
- # end
143
-
144
-
145
- end
146
- end
@@ -1,24 +0,0 @@
1
- # encoding:utf-8
2
- require './test/test_helper'
3
-
4
- # Special tests for the JRuby encoder only
5
- if RUBY_PLATFORM =~ /java/
6
-
7
- class JRubyBSONTest < Test::Unit::TestCase
8
- include BSON
9
-
10
- def setup
11
- @encoder = BSON::BSON_CODER
12
- @decoder = BSON::BSON_RUBY
13
- end
14
-
15
- def test_object_id
16
- oid = {'doc' => BSON::ObjectId.new}
17
- p oid['doc'].data
18
- bson = @encoder.serialize(oid)
19
- assert_equal oid, @encoder.deserialize(bson)
20
- end
21
-
22
- end
23
-
24
- end
@@ -1,438 +0,0 @@
1
- # encoding:utf-8
2
- require 'test/test_helper'
3
- require 'complex'
4
- require 'bigdecimal'
5
- require 'rational'
6
- require 'benchmark'
7
-
8
- MEDIUM = {
9
- 'integer' => 5,
10
- 'number' => 5.05,
11
- 'boolean' => false,
12
- 'array' => ['test', 'benchmark']
13
- }
14
-
15
-
16
- LARGE = {
17
- 'base_url' => 'http://www.example.com/test-me',
18
- 'total_word_count' => 6743,
19
- 'access_time' => 123, #Time.now,
20
- 'meta_tags' => {
21
- 'description' => 'i am a long description string',
22
- 'author' => 'Holly Man',
23
- 'dynamically_created_meta_tag' => 'who know\n what'
24
- },
25
- 'page_structure' => {
26
- 'counted_tags' => 3450,
27
- 'no_of_js_attached' => 10,
28
- 'no_of_images' => 6
29
- },
30
- 'harvested_words' => ['10gen','web','open','source','application','paas',
31
- 'platform-as-a-service','technology','helps',
32
- 'developers','focus','building','mongodb','mongo'] * 20
33
- }
34
-
35
- class BSONTest < Test::Unit::TestCase
36
- include BSON
37
-
38
- def setup
39
- @encoder = BSON::BSON_CODER
40
- end
41
-
42
- def assert_doc_pass(doc)
43
- bson = @encoder.serialize(doc)
44
- p bson.to_a
45
- puts "#{doc.inspect} serializes to #{bson.inspect}"
46
-
47
- assert_equal doc, BSON::BSON_RUBY.deserialize(bson)
48
- end
49
-
50
- def test_string
51
- doc = {'doc' => 'the well-tempered clavier'}
52
- BSON::BSON_RUBY.serialize(doc)
53
- bson = @encoder.serialize(doc)
54
- assert_equal doc, BSON::BSON_RUBY.deserialize(bson.to_s)
55
- end
56
-
57
- def test_nested_string
58
- t0 = Time.now
59
- 500.times do
60
- @encoder.serialize({'doc' => MEDIUM})
61
- end
62
- t1 = Time.now
63
- puts t1 - t0
64
- end
65
-
66
- def test_array
67
- doc = {'doc' => ['1', '2', '3']}
68
- assert_doc_pass(doc)
69
- puts "Here's the doc"
70
- p doc.class
71
- bson = @encoder.serialize(doc)
72
- assert_equal bson.to_s, BSON::BSON_RUBY.serialize(doc).to_s
73
- end
74
-
75
- def test_number
76
- assert_doc_pass({'doc' => 1})
77
- end
78
-
79
- def test_object
80
- assert_doc_pass({'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}})
81
- end
82
-
83
- def test_code
84
- @reduce_function = "function (obj, prev) { prev.count += inc_value; }"
85
- doc = {"a" => Code.new(@reduce_function, {"a" => 1})}
86
- assert_doc_pass(doc)
87
- end
88
-
89
- def test_date
90
- doc = {'date' => Time.now}
91
- d = BSON::BSON_RUBY.serialize(doc)
92
- p d.to_s
93
- e = BSON::BSON_JAVA.serialize(doc)
94
- p e.to_s
95
- assert_doc_pass(doc)
96
- #bson = @e.serialize(doc)
97
- #doc2 = BSON::BSON_CODER.deserialize(bson)
98
- # Mongo only stores up to the millisecond
99
- #assert_in_delta doc['date'], doc2['date'], 0.001
100
- end
101
-
102
- # def test_float
103
- # doc = {'a' => 1}
104
- # assert_doc_pass(doc)
105
- # end
106
- #
107
- # def test_group_cmd
108
- # initial = {"c" => 0}
109
- # reduce = "function (obj, prev) { prev.c += inc_value; }"
110
- # group_command = {
111
- # "group" => {
112
- # "ns" => 'col',
113
- # "$reduce" => reduce,
114
- # "cond" => {},
115
- # "initial" => initial
116
- # }
117
- # }
118
- #
119
- # assert_doc_pass(group_command)
120
- # end
121
- #
122
- # context "Grouping" do
123
- # setup do
124
- # @@test.remove
125
- # @@test.save("a" => 1)
126
- # @@test.save("b" => 1)
127
- # @initial = {"count" => 0}
128
- # @reduce_function = "function (obj, prev) { prev.count += inc_value; }"
129
- # end
130
- #
131
- # should "group results using eval form" do
132
- # p @@test.group([], {}, @initial, Code.new(@reduce_function, {"inc_value" => 1}))
133
- # p @@test.group([], {}, @initial, Code.new(@reduce_function, {"inc_value" => 2}))
134
- # assert_equal 2, @@test.group([], {}, @initial, Code.new(@reduce_function, {"inc_value" => 1}))[0]["count"]
135
- # assert_equal 4, @@test.group([], {}, @initial, Code.new(@reduce_function, {"inc_value" => 2}))[0]["count"]
136
- # end
137
- # end
138
- #
139
- # def test_find_and_modify
140
- # @@test << { :a => 1, :processed => false }
141
- # @@test << { :a => 2, :processed => false }
142
- # @@test << { :a => 3, :processed => false }
143
- # p @@test.find.to_a
144
- #
145
- # @@test.find_and_modify(:query => {}, :sort => [['a', -1]], :update => {"$set" => {"processed" => true}})
146
- #
147
- # p @@test.find.to_a
148
- # assert @@test.find_one({:a => 3})['processed']
149
- # end
150
- #
151
- # def test_invalid_string
152
- # require 'iconv'
153
- # string = Iconv.conv('iso-8859-1', 'utf-8', 'aé')
154
- # doc = {'doc' => string}
155
- # bson = @encoder.serialize(doc)
156
- # assert_equal doc, @encoder.deserialize(bson)
157
- # end
158
- #
159
- # def test_null
160
- # #doc = {"\x00" => "foo"}
161
- # #@encoder.serialize(doc)
162
- # @encoder.serialize({"a" => (Regexp.compile "ab\x00c")})
163
- # end
164
-
165
- # def test_dbref
166
- # oid = ObjectID.new
167
- # doc = {}
168
- # doc['dbref'] = DBRef.new('namespace', oid)
169
- # bson = BSON::BSON_CODER.serialize(doc)
170
- # doc2 = BSON::BSON_CODER.deserialize(bson)
171
- # puts doc2.class
172
- # puts doc2
173
- # assert_equal 'namespace', doc2['dbref'].namespace
174
- # assert_equal oid, doc2['dbref'].object_id
175
- # end
176
-
177
- # def test_null_character
178
- # #assert_raise InvalidDocument do
179
- # bson = @encoder.serialize({"\x00" => "a"})
180
- # puts bson
181
- # #end
182
- # puts BSON_RUBY.deserialize(bson)
183
- #
184
- # #assert_raise InvalidDocument do
185
- # # @encoder.serialize({"a" => (Regexp.compile "ab\x00c")})
186
- # #end
187
- # end
188
- #
189
- ## def test_symbol_key
190
- # doc = {:foo => "bar"}
191
- # p doc.keys
192
- # bson = @coder.serialize(doc)
193
- # new_doc = {"foo" => "bar"}
194
- # assert_equal new_doc, @coder.deserialize(bson)
195
- # end
196
- #
197
- #
198
- # def test_string
199
- # assert_doc_pass({'doc' => 'hello, world'})
200
- # end
201
- #
202
- ##
203
- # require 'iconv'
204
- # def test_invalid_string
205
- # require 'iconv'
206
- # string = Iconv.conv('iso-8859-1', 'utf-8', 'aé')
207
- # doc = {'doc' => string}
208
- # bson = @coder.serialize(doc)
209
- # assert_equal doc, @coder.deserialize(bson)
210
- # end
211
- #
212
- #
213
- # def test_nested_string
214
- # assert_doc_pass({'doc' => {'text' => 'hello, world'}})
215
- # end
216
- #
217
- # def test_array
218
- # assert_doc_pass({'doc' => ['1', '2', '3']})
219
- # end
220
- #
221
- # def test_number
222
- # assert_doc_pass({'doc' => 1})
223
- # end
224
- #
225
- # def test_object
226
- # assert_doc_pass({'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}})
227
- # end
228
- #
229
- # def test_boolean
230
- # assert_doc_pass({'foo' => true})
231
- # assert_doc_pass({'foo' => false})
232
- # end
233
- #
234
- # def test_nil
235
- # assert_doc_pass({'foo' => nil})
236
- # end
237
- #
238
- # def test_time
239
- # assert_doc_pass({'foo' => Time.now})
240
- # end
241
- #
242
- # def test_simple_regex
243
- # assert_doc_pass({'foo' => /^a/})
244
- # end
245
- #
246
- # def test_regex_with_options
247
- # assert_doc_pass({'foo' => /^a/imx})
248
- # end
249
- #
250
- # def test_symbol
251
- # assert_doc_pass({'foo' => :bar})
252
- # end
253
- #
254
- # def test_binary
255
- # doc = {'foo' => BSON::Binary.new("ABCDE".unpack("C*"))}
256
- # bson = @coder.serialize(doc)
257
- # de = @coder.deserialize(bson)
258
- # assert_equal doc, de
259
- # end
260
- #
261
- # def test_valid_utf8_string
262
- # doc = {'doc' => 'aé'}
263
- # bson = bson = BSON::BSON_CODER.serialize(doc)
264
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
265
- # end
266
- #
267
- # def test_valid_utf8_key
268
- # doc = {'aé' => 'hello'}
269
- # bson = bson = BSON::BSON_CODER.serialize(doc)
270
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
271
- # end
272
- #
273
- # def test_number
274
- # doc = {'doc' => 41.99}
275
- # bson = BSON::BSON_CODER.serialize(doc)
276
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
277
- # end
278
- #
279
- # def test_int
280
- # doc = {'doc' => 42}
281
- # bson = BSON::BSON_CODER.serialize(doc)
282
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
283
- #
284
- # doc = {"doc" => -5600}
285
- # bson = BSON::BSON_CODER.serialize(doc)
286
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
287
- #
288
- # doc = {"doc" => 2147483647}
289
- # bson = BSON::BSON_CODER.serialize(doc)
290
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
291
- #
292
- # doc = {"doc" => -2147483648}
293
- # bson = BSON::BSON_CODER.serialize(doc)
294
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
295
- # end
296
- #
297
- # def test_obj
298
- # doc = {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}}
299
- # bson = BSON::BSON_CODER.serialize(doc)
300
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
301
- #
302
- # doc = {"a" => 10, "b" => 20}# {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}}
303
- # bson = BSON::BSON_CODER.serialize(doc)
304
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
305
- # end
306
- #
307
- # def test_oh
308
- # oh = BSON::OrderedHash.new
309
- # oh["z"] = 10
310
- # oh["a"] = 1
311
- # bson = BSON::BSON_CODER.serialize(oh)
312
- # p bson
313
- # assert_equal oh, BSON::BSON_CODER.deserialize(bson)
314
- # end
315
- #
316
- def test_ordered_hash
317
- # doc = BSON::OrderedHash.new
318
- # doc["b"] = 1
319
- # doc["a"] = 2
320
- # doc["c"] = 3
321
- # doc["d"] = 4
322
- # bson1 = BSON::BSON_CODER.serialize(doc)
323
- # bson2 = BSON::BSON_RUBY.serialize({"b" => 1, "a" => 2, "c" => 3, "d" => 4})
324
- # bson3 = BSON::BSON_RUBY.serialize({"b" => '1', "a" => '2', "c" => '3', "d" => '4'})
325
- # p bson1
326
- # p bson2
327
- # p bson3
328
- # p BSON::BSON_CODER.deserialize(bson3)
329
- # assert_equal doc, BSON::BSON_RUBY.deserialize(bson3)
330
- end
331
- #
332
- # def test_object
333
- # doc = {'doc' => {'age' => 42, 'name' => 'Spongebob', 'shoe_size' => 9.5}}
334
- # bson = BSON::BSON_CODER.serialize(doc)
335
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
336
- # end
337
- #
338
- ## def test_oid
339
- ## doc = {'doc' => ObjectID.new}
340
- ## bson = BSON::BSON_CODER.serialize(doc)
341
- ## assert_equal doc, BSON::BSON_CODER.deserialize(bson)
342
- ## end
343
- ##
344
- ## def test_array
345
- ## doc = {'doc' => [1, 2, 'a', 'b']}
346
- ## bson = BSON::BSON_CODER.serialize(doc)
347
- ## assert_equal doc, BSON::BSON_CODER.deserialize(bson)
348
- ## end
349
- ##
350
- ## def test_invalid_object
351
- ## doc = {'foo' => Object.new}
352
- ## assert_raise InvalidDocument do
353
- ## @coder.serialize(doc)
354
- ## end
355
- ##
356
- ## assert_raise InvalidDocument do
357
- ## @coder.serialize({'date' => Date.today})
358
- ## end
359
- ## end
360
- ##
361
- ##
362
- ## def test_regex
363
- ## doc = {'doc' => /foobar/i}
364
- ## bson = BSON::BSON_CODER.serialize(doc)
365
- ## doc2 = BSON::BSON_CODER.deserialize(bson)
366
- ## assert_equal doc, doc2
367
- ##
368
- ## r = doc2['doc']
369
- ## assert_kind_of Regexp, r
370
- ##
371
- ## doc = {'doc' => r}
372
- ## bson_doc = BSON::BSON_CODER.serialize(doc)
373
- ## doc2 = nil
374
- ## doc2 = BSON::BSON_CODER.deserialize(bson_doc)
375
- ## assert_equal doc, doc2
376
- ## end
377
- ##
378
- # def test_boolean
379
- # doc = {'doc' => true}
380
- # bson = BSON::BSON_CODER.serialize(doc)
381
- # assert_equal doc, BSON::BSON_CODER.deserialize(bson)
382
- # end
383
- #
384
- # def test_date
385
- # doc = {'date' => Time.now}
386
- # bson = BSON::BSON_CODER.serialize(doc)
387
- # doc2 = BSON::BSON_CODER.deserialize(bson)
388
- # # Mongo only stores up to the millisecond
389
- # assert_in_delta doc['date'], doc2['date'], 0.001
390
- # end
391
- #
392
- # def test_date_returns_as_utc
393
- # doc = {'date' => Time.now}
394
- # bson = BSON::BSON_CODER.serialize(doc)
395
- # doc2 = BSON::BSON_CODER.deserialize(bson)
396
- # assert doc2['date'].utc?
397
- # end
398
- #
399
- ## def test_dbref
400
- ## oid = ObjectID.new
401
- ## doc = {}
402
- ## doc['dbref'] = DBRef.new('namespace', oid)
403
- ## bson = BSON::BSON_CODER.serialize(doc)
404
- ## doc2 = BSON::BSON_CODER.deserialize(bson)
405
- ## assert_equal 'namespace', doc2['dbref'].namespace
406
- ## assert_equal oid, doc2['dbref'].object_id
407
- ## end
408
- ##
409
- # def test_symbol
410
- # doc = {'sym' => :foo}
411
- # bson = BSON::BSON_CODER.serialize(doc)
412
- # doc2 = BSON::BSON_CODER.deserialize(bson)
413
- # assert_equal :foo, doc2['sym']
414
- # end
415
- ##
416
- ### def test_regex_extended
417
- ### assert_doc_pass({'foo' => /^a/x})
418
- ### end
419
- ###
420
- # def test_object_id
421
- # assert_doc_pass({'_id' => BSON::ObjectID.new})
422
- # end
423
- #
424
- # def test_where
425
- # assert_doc_pass({'$where' => "function() { print('hello'); }"})
426
- # end
427
- #
428
- # def test_min_max_keys
429
- # assert_doc_pass({'doc' => BSON::MaxKey.new})
430
- # assert_doc_pass({'doc' => BSON::MinKey.new})
431
- # end
432
- #
433
- # def test_code
434
- # code = BSON::Code.new("print('hello')")
435
- # code.scope = {:foo => 2}
436
- # assert_doc_pass({'doc' => code})
437
- # end
438
- end