jmongo 1.1.1 → 1.1.2

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.
@@ -1,29 +1,15 @@
1
1
  require './test/test_helper'
2
2
  require 'logger'
3
3
 
4
- CONNECTION ||= Mongo::Connection.new(TEST_HOST, TEST_PORT, :op_timeout => 10)
5
- $db = CONNECTION.db(MONGO_TEST_DB)
6
-
7
- VERSION = CONNECTION.server_version
8
- apr VERSION
9
-
10
- def clear_collections
11
- $db.collection_names.each do |n|
12
- $db.drop_collection(n) unless n =~ /system/
13
- end
14
- end
15
-
16
- clear_collections
17
-
18
- $coll = $db.collection("test")
19
- $coll_full_name = "#{MONGO_TEST_DB}.test"
4
+ Cfg.connection :op_timeout => 10
5
+ Cfg.db
20
6
 
21
7
  class CursorTest < MiniTest::Unit::TestCase
22
8
  include Mongo
23
9
 
24
10
  def setup
25
- clear_collections
26
- #$coll.insert('a' => 1) # collection not created until it's used
11
+ Cfg.clear_all
12
+ #Cfg.coll.insert('a' => 1) # collection not created until it's used
27
13
  end
28
14
 
29
15
  def test_alive
@@ -32,8 +18,8 @@ class CursorTest < MiniTest::Unit::TestCase
32
18
  batch << {:a => n}
33
19
  end
34
20
 
35
- $coll.insert(batch)
36
- cursor = $coll.find
21
+ Cfg.coll.insert(batch)
22
+ cursor = Cfg.coll.find
37
23
  assert !cursor.alive?
38
24
  cursor.next
39
25
  assert cursor.alive?
@@ -42,8 +28,8 @@ class CursorTest < MiniTest::Unit::TestCase
42
28
  end
43
29
 
44
30
  def test_add_and_remove_options
45
- $coll.insert('a' => 1)
46
- c = $coll.find
31
+ Cfg.coll.insert('a' => 1)
32
+ c = Cfg.coll.find
47
33
  assert_equal 0, c.options & OP_QUERY_EXHAUST
48
34
  c.add_option(OP_QUERY_EXHAUST)
49
35
  assert_equal OP_QUERY_EXHAUST, c.options & OP_QUERY_EXHAUST
@@ -61,19 +47,19 @@ class CursorTest < MiniTest::Unit::TestCase
61
47
  end
62
48
 
63
49
  def test_exhaust
64
- skip("Mongo Version is not >= 2.0") unless VERSION >= "2.0"
50
+ skip("Mongo Version is not >= 2.0") unless Cfg.version >= "2.0"
65
51
 
66
52
  data = "1" * 100_000
67
53
  10_000.times do |n|
68
- $coll.insert({:n => n, :data => data})
54
+ Cfg.coll.insert({:n => n, :data => data})
69
55
  end
70
56
 
71
- c = Cursor.new($coll)
57
+ c = Cursor.new(Cfg.coll)
72
58
  c.add_option(OP_QUERY_EXHAUST)
73
- assert_equal $coll.count, c.to_a.size
59
+ assert_equal Cfg.coll.count, c.to_a.size
74
60
  assert c.closed?
75
61
 
76
- c = Cursor.new($coll)
62
+ c = Cursor.new(Cfg.coll)
77
63
  c.add_option(OP_QUERY_EXHAUST)
78
64
  9999.times do
79
65
  c.next
@@ -87,14 +73,14 @@ class CursorTest < MiniTest::Unit::TestCase
87
73
 
88
74
  # def test_inspect
89
75
  # selector = {:a => 1}
90
- # cursor = $coll.find(selector)
91
- # assert_equal "<Mongo::Cursor:0x#{cursor.object_id.to_s(16)} namespace='#{$db.name}.#{$coll.name}' " +
76
+ # cursor = Cfg.coll.find(selector)
77
+ # assert_equal "<Mongo::Cursor:0x#{cursor.object_id.to_s(16)} namespace='#{Cfg.db.name}.#{Cfg.coll.name}' " +
92
78
  # "@selector=#{selector.inspect} @cursor_id=#{cursor.cursor_id}>", cursor.inspect
93
79
  # end
94
80
 
95
81
  def test_explain
96
- $coll.insert('a' => 1)
97
- cursor = $coll.find('a' => 1)
82
+ Cfg.coll.insert('a' => 1)
83
+ cursor = Cfg.coll.find('a' => 1)
98
84
  explaination = cursor.explain
99
85
  assert explaination['cursor']
100
86
  assert_kind_of Numeric, explaination['n']
@@ -104,89 +90,89 @@ class CursorTest < MiniTest::Unit::TestCase
104
90
 
105
91
  def test_count
106
92
 
107
- assert_equal 0, $coll.find().count()
93
+ assert_equal 0, Cfg.coll.find().count()
108
94
 
109
95
  10.times do |i|
110
- $coll.save("x" => i)
96
+ Cfg.coll.save("x" => i)
111
97
  end
112
98
 
113
- assert_equal 10, $coll.find().count()
114
- assert_kind_of Integer, $coll.find().count()
115
- assert_equal 10, $coll.find({}, :limit => 5).count()
116
- assert_equal 10, $coll.find({}, :skip => 5).count()
99
+ assert_equal 10, Cfg.coll.find().count()
100
+ assert_kind_of Integer, Cfg.coll.find().count()
101
+ assert_equal 10, Cfg.coll.find({}, :limit => 5).count()
102
+ assert_equal 10, Cfg.coll.find({}, :skip => 5).count()
117
103
 
118
- assert_equal 5, $coll.find({}, :limit => 5).count(true)
119
- assert_equal 5, $coll.find({}, :skip => 5).count(true)
120
- assert_equal 2, $coll.find({}, :skip => 5, :limit => 2).count(true)
104
+ assert_equal 5, Cfg.coll.find({}, :limit => 5).count(true)
105
+ assert_equal 5, Cfg.coll.find({}, :skip => 5).count(true)
106
+ assert_equal 2, Cfg.coll.find({}, :skip => 5, :limit => 2).count(true)
121
107
 
122
- assert_equal 1, $coll.find({"x" => 1}).count()
123
- assert_equal 5, $coll.find({"x" => {"$lt" => 5}}).count()
108
+ assert_equal 1, Cfg.coll.find({"x" => 1}).count()
109
+ assert_equal 5, Cfg.coll.find({"x" => {"$lt" => 5}}).count()
124
110
 
125
- a = $coll.find()
111
+ a = Cfg.coll.find()
126
112
  b = a.count()
127
113
  a.each do |doc|
128
114
  break
129
115
  end
130
116
  assert_equal b, a.count()
131
117
 
132
- assert_equal 0, $db['acollectionthatdoesn'].count()
118
+ assert_equal 0, Cfg.db['acollectionthatdoesn'].count()
133
119
  end
134
120
 
135
121
  def test_sort
136
122
 
137
- 5.times{|x| $coll.insert({"age" => x}) }
123
+ 5.times{|x| Cfg.coll.insert({"age" => x}) }
138
124
 
139
- assert_kind_of Cursor, $coll.find().sort(:age, 1)
125
+ assert_kind_of Cursor, Cfg.coll.find().sort(:age, 1)
140
126
 
141
- assert_equal 0, $coll.find().sort(:age, 1).next_document["age"]
142
- assert_equal 4, $coll.find().sort(:age, -1).next_document["age"]
143
- assert_equal 0, $coll.find().sort([["age", :asc]]).next_document["age"]
127
+ assert_equal 0, Cfg.coll.find().sort(:age, 1).next_document["age"]
128
+ assert_equal 4, Cfg.coll.find().sort(:age, -1).next_document["age"]
129
+ assert_equal 0, Cfg.coll.find().sort([["age", :asc]]).next_document["age"]
144
130
 
145
- assert_kind_of Cursor, $coll.find().sort([[:age, -1], [:b, 1]])
131
+ assert_kind_of Cursor, Cfg.coll.find().sort([[:age, -1], [:b, 1]])
146
132
 
147
- assert_equal 4, $coll.find().sort(:age, 1).sort(:age, -1).next_document["age"]
148
- assert_equal 0, $coll.find().sort(:age, -1).sort(:age, 1).next_document["age"]
133
+ assert_equal 4, Cfg.coll.find().sort(:age, 1).sort(:age, -1).next_document["age"]
134
+ assert_equal 0, Cfg.coll.find().sort(:age, -1).sort(:age, 1).next_document["age"]
149
135
 
150
- assert_equal 4, $coll.find().sort([:age, :asc]).sort(:age, -1).next_document["age"]
151
- assert_equal 0, $coll.find().sort([:age, :desc]).sort(:age, 1).next_document["age"]
136
+ assert_equal 4, Cfg.coll.find().sort([:age, :asc]).sort(:age, -1).next_document["age"]
137
+ assert_equal 0, Cfg.coll.find().sort([:age, :desc]).sort(:age, 1).next_document["age"]
152
138
 
153
- cursor = $coll.find()
139
+ cursor = Cfg.coll.find()
154
140
  cursor.next_document
155
141
  assert_raises InvalidOperation do
156
142
  cursor.sort(["age", 1])
157
143
  end
158
144
 
159
145
  assert_raises InvalidSortValueError do
160
- $coll.find().sort(:age, 25).next_document
146
+ Cfg.coll.find().sort(:age, 25).next_document
161
147
  end
162
148
 
163
149
  assert_raises InvalidSortValueError do
164
- $coll.find().sort(25).next_document
150
+ Cfg.coll.find().sort(25).next_document
165
151
  end
166
152
  end
167
153
 
168
154
  def test_sort_date
169
155
 
170
- 5.times{|x| $coll.insert({"created_at" => Time.utc(2000 + x)}) }
156
+ 5.times{|x| Cfg.coll.insert({"created_at" => Time.utc(2000 + x)}) }
171
157
 
172
- assert_equal 2000, $coll.find().sort(:created_at, :asc).next_document["created_at"].year
173
- assert_equal 2004, $coll.find().sort(:created_at, :desc).next_document["created_at"].year
158
+ assert_equal 2000, Cfg.coll.find().sort(:created_at, :asc).next_document["created_at"].year
159
+ assert_equal 2004, Cfg.coll.find().sort(:created_at, :desc).next_document["created_at"].year
174
160
 
175
- assert_equal 2000, $coll.find().sort([:created_at, :asc]).next_document["created_at"].year
176
- assert_equal 2004, $coll.find().sort([:created_at, :desc]).next_document["created_at"].year
161
+ assert_equal 2000, Cfg.coll.find().sort([:created_at, :asc]).next_document["created_at"].year
162
+ assert_equal 2004, Cfg.coll.find().sort([:created_at, :desc]).next_document["created_at"].year
177
163
 
178
- assert_equal 2000, $coll.find().sort([[:created_at, :asc]]).next_document["created_at"].year
179
- assert_equal 2004, $coll.find().sort([[:created_at, :desc]]).next_document["created_at"].year
164
+ assert_equal 2000, Cfg.coll.find().sort([[:created_at, :asc]]).next_document["created_at"].year
165
+ assert_equal 2004, Cfg.coll.find().sort([[:created_at, :desc]]).next_document["created_at"].year
180
166
  end
181
167
 
182
168
  def test_sort_min_max_keys
183
169
 
184
- $coll.insert({"n" => 1000000})
185
- $coll.insert({"n" => -1000000})
186
- $coll.insert({"n" => MaxKey.new})
187
- $coll.insert({"n" => MinKey.new})
170
+ Cfg.coll.insert({"n" => 1000000})
171
+ Cfg.coll.insert({"n" => -1000000})
172
+ Cfg.coll.insert({"n" => MaxKey.new})
173
+ Cfg.coll.insert({"n" => MinKey.new})
188
174
 
189
- results = $coll.find.sort([:n, :asc]).to_a
175
+ results = Cfg.coll.find.sort([:n, :asc]).to_a
190
176
 
191
177
  assert_equal MinKey.new, results[0]['n']
192
178
  assert_equal(-1000000, results[1]['n'])
@@ -198,18 +184,18 @@ class CursorTest < MiniTest::Unit::TestCase
198
184
 
199
185
  t1 = Time.now
200
186
  t1_id = ObjectId.from_time(t1)
201
- $coll.save({:t => 't1'})
202
- $coll.save({:t => 't1'})
203
- $coll.save({:t => 't1'})
187
+ Cfg.coll.save({:t => 't1'})
188
+ Cfg.coll.save({:t => 't1'})
189
+ Cfg.coll.save({:t => 't1'})
204
190
  sleep(2)
205
191
  t2 = Time.now
206
192
  t2_id = ObjectId.from_time(t2)
207
- $coll.save({:t => 't2'})
208
- $coll.save({:t => 't2'})
209
- $coll.save({:t => 't2'})
193
+ Cfg.coll.save({:t => 't2'})
194
+ Cfg.coll.save({:t => 't2'})
195
+ Cfg.coll.save({:t => 't2'})
210
196
 
211
- assert_equal 3, $coll.find({'_id' => {'$gt' => t1_id, '$lt' => t2_id}}).count
212
- $coll.find({'_id' => {'$gt' => t2_id}}).each do |doc|
197
+ assert_equal 3, Cfg.coll.find({'_id' => {'$gt' => t1_id, '$lt' => t2_id}}).count
198
+ Cfg.coll.find({'_id' => {'$gt' => t2_id}}).each do |doc|
213
199
  assert_equal 't2', doc['t']
214
200
  end
215
201
  end
@@ -217,49 +203,49 @@ class CursorTest < MiniTest::Unit::TestCase
217
203
  def test_limit
218
204
 
219
205
  10.times do |i|
220
- $coll.save("x" => i)
206
+ Cfg.coll.save("x" => i)
221
207
  end
222
- assert_equal 10, $coll.find().count()
208
+ assert_equal 10, Cfg.coll.find().count()
223
209
 
224
- results = $coll.find().limit(5).to_a
210
+ results = Cfg.coll.find().limit(5).to_a
225
211
  assert_equal 5, results.length
226
212
  end
227
213
 
228
214
  def test_timeout_options
229
- cursor = Cursor.new($coll)
215
+ cursor = Cursor.new(Cfg.coll)
230
216
  assert_equal true, cursor.timeout
231
217
 
232
- cursor = $coll.find
218
+ cursor = Cfg.coll.find
233
219
  assert_equal true, cursor.timeout
234
220
 
235
- cursor = $coll.find({}, :timeout => nil)
221
+ cursor = Cfg.coll.find({}, :timeout => nil)
236
222
  assert_equal true, cursor.timeout
237
223
 
238
- cursor = Cursor.new($coll, :timeout => false)
224
+ cursor = Cursor.new(Cfg.coll, :timeout => false)
239
225
  assert_equal false, cursor.timeout
240
226
 
241
- $coll.find({}, :timeout => false) do |c|
227
+ Cfg.coll.find({}, :timeout => false) do |c|
242
228
  assert_equal false, c.timeout
243
229
  end
244
230
  end
245
231
 
246
232
  def test_timeout
247
- opts = Cursor.new($coll).query_opts
233
+ opts = Cursor.new(Cfg.coll).query_opts
248
234
  assert_equal 0, opts & Mongo::OP_QUERY_NO_CURSOR_TIMEOUT
249
235
 
250
- opts = Cursor.new($coll, :timeout => false).query_opts
236
+ opts = Cursor.new(Cfg.coll, :timeout => false).query_opts
251
237
  assert_equal Mongo::OP_QUERY_NO_CURSOR_TIMEOUT,
252
238
  opts & Mongo::OP_QUERY_NO_CURSOR_TIMEOUT
253
239
  end
254
240
 
255
241
  def test_limit_exceptions
256
- cursor = $coll.find()
242
+ cursor = Cfg.coll.find()
257
243
  firstResult = cursor.next_document
258
244
  assert_raises InvalidOperation, "Cannot modify the query once it has been run or closed." do
259
245
  cursor.limit(1)
260
246
  end
261
247
 
262
- cursor = $coll.find()
248
+ cursor = Cfg.coll.find()
263
249
  cursor.close
264
250
  assert_raises InvalidOperation, "Cannot modify the query once it has been run or closed." do
265
251
  cursor.limit(1)
@@ -270,12 +256,12 @@ class CursorTest < MiniTest::Unit::TestCase
270
256
 
271
257
 
272
258
  10.times do |i|
273
- $coll.save("x" => i)
259
+ Cfg.coll.save("x" => i)
274
260
  end
275
- assert_equal 10, $coll.find().count()
261
+ assert_equal 10, Cfg.coll.find().count()
276
262
 
277
- all_results = $coll.find().to_a
278
- skip_results = $coll.find().skip(2).to_a
263
+ all_results = Cfg.coll.find().to_a
264
+ skip_results = Cfg.coll.find().skip(2).to_a
279
265
  assert_equal 10, all_results.length
280
266
  assert_equal 8, skip_results.length
281
267
 
@@ -283,13 +269,13 @@ class CursorTest < MiniTest::Unit::TestCase
283
269
  end
284
270
 
285
271
  def test_skip_exceptions
286
- cursor = $coll.find()
272
+ cursor = Cfg.coll.find()
287
273
  firstResult = cursor.next_document
288
274
  assert_raises InvalidOperation, "Cannot modify the query once it has been run or closed." do
289
275
  cursor.skip(1)
290
276
  end
291
277
 
292
- cursor = $coll.find()
278
+ cursor = Cfg.coll.find()
293
279
  cursor.close
294
280
  assert_raises InvalidOperation, "Cannot modify the query once it has been run or closed." do
295
281
  cursor.skip(1)
@@ -299,18 +285,18 @@ class CursorTest < MiniTest::Unit::TestCase
299
285
  def test_limit_skip_chaining
300
286
 
301
287
  10.times do |i|
302
- $coll.save("x" => i)
288
+ Cfg.coll.save("x" => i)
303
289
  end
304
290
 
305
- all_results = $coll.find().to_a
306
- limited_skip_results = $coll.find().limit(5).skip(3).to_a
291
+ all_results = Cfg.coll.find().to_a
292
+ limited_skip_results = Cfg.coll.find().limit(5).skip(3).to_a
307
293
 
308
294
  assert_equal all_results.slice(3...8), limited_skip_results
309
295
  end
310
296
 
311
297
  def test_close_no_query_sent
312
298
  begin
313
- cursor = $coll.find('a' => 1)
299
+ cursor = Cfg.coll.find('a' => 1)
314
300
  cursor.close
315
301
  assert cursor.closed?
316
302
  rescue => ex
@@ -319,34 +305,34 @@ class CursorTest < MiniTest::Unit::TestCase
319
305
  end
320
306
 
321
307
  def test_refill_via_get_more
322
- $coll.insert('a' => 1)
323
- assert_equal 1, $coll.count
308
+ Cfg.coll.insert('a' => 1)
309
+ assert_equal 1, Cfg.coll.count
324
310
  1000.times { |i|
325
- assert_equal 1 + i, $coll.count
326
- $coll.insert('a' => i)
311
+ assert_equal 1 + i, Cfg.coll.count
312
+ Cfg.coll.insert('a' => i)
327
313
  }
328
314
 
329
- assert_equal 1001, $coll.count
315
+ assert_equal 1001, Cfg.coll.count
330
316
  count = 0
331
- $coll.find.each { |obj|
317
+ Cfg.coll.find.each { |obj|
332
318
  count += obj['a']
333
319
  }
334
- assert_equal 1001, $coll.count
320
+ assert_equal 1001, Cfg.coll.count
335
321
 
336
322
  # do the same thing again for debugging
337
- assert_equal 1001, $coll.count
323
+ assert_equal 1001, Cfg.coll.count
338
324
  count2 = 0
339
- $coll.find.each { |obj|
325
+ Cfg.coll.find.each { |obj|
340
326
  count2 += obj['a']
341
327
  }
342
- assert_equal 1001, $coll.count
328
+ assert_equal 1001, Cfg.coll.count
343
329
 
344
330
  assert_equal count, count2
345
331
  assert_equal 499501, count
346
332
  end
347
333
 
348
334
  def test_refill_via_get_more_alt_coll
349
- coll = $db.collection('test-alt-coll')
335
+ coll = Cfg.db.collection('test-alt-coll')
350
336
  coll.remove
351
337
  coll.insert('a' => 1) # collection not created until it's used
352
338
  assert_equal 1, coll.count
@@ -377,7 +363,7 @@ class CursorTest < MiniTest::Unit::TestCase
377
363
 
378
364
  def test_close_after_query_sent
379
365
  begin
380
- cursor = $coll.find('a' => 1)
366
+ cursor = Cfg.coll.find('a' => 1)
381
367
  cursor.next_document
382
368
  cursor.close
383
369
  assert cursor.closed?
@@ -387,77 +373,77 @@ class CursorTest < MiniTest::Unit::TestCase
387
373
  end
388
374
 
389
375
  def test_kill_cursors
390
- $coll.drop
376
+ Cfg.coll.drop
391
377
 
392
- client_cursors = $db.command("cursorInfo" => 1)["clientCursors_size"]
378
+ client_cursors = Cfg.db.command("cursorInfo" => 1)["clientCursors_size"]
393
379
 
394
380
  10000.times do |i|
395
- $coll.insert("i" => i)
381
+ Cfg.coll.insert("i" => i)
396
382
  end
397
383
 
398
384
  assert_equal(client_cursors,
399
- $db.command("cursorInfo" => 1)["clientCursors_size"])
385
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
400
386
 
401
387
  10.times do |i|
402
- $coll.find_one()
388
+ Cfg.coll.find_one()
403
389
  end
404
390
 
405
391
  assert_equal(client_cursors,
406
- $db.command("cursorInfo" => 1)["clientCursors_size"])
392
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
407
393
 
408
394
  10.times do |i|
409
- a = $coll.find()
395
+ a = Cfg.coll.find()
410
396
  a.next_document
411
397
  a.close()
412
398
  end
413
399
 
414
400
  assert_equal(client_cursors,
415
- $db.command("cursorInfo" => 1)["clientCursors_size"])
401
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
416
402
 
417
- a = $coll.find()
403
+ a = Cfg.coll.find()
418
404
  a.next_document
419
405
 
420
406
  refute_equal(client_cursors,
421
- $db.command("cursorInfo" => 1)["clientCursors_size"])
407
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
422
408
 
423
409
  a.close()
424
410
 
425
411
  assert_equal(client_cursors,
426
- $db.command("cursorInfo" => 1)["clientCursors_size"])
412
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
427
413
 
428
- a = $coll.find({}, :limit => 10).next_document
414
+ a = Cfg.coll.find({}, :limit => 10).next_document
429
415
 
430
416
  assert_equal(client_cursors,
431
- $db.command("cursorInfo" => 1)["clientCursors_size"])
417
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
432
418
 
433
- $coll.find() do |cursor|
419
+ Cfg.coll.find() do |cursor|
434
420
  cursor.next_document
435
421
  end
436
422
 
437
423
  assert_equal(client_cursors,
438
- $db.command("cursorInfo" => 1)["clientCursors_size"])
424
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
439
425
 
440
- $coll.find() { |cursor|
426
+ Cfg.coll.find() { |cursor|
441
427
  cursor.next_document
442
428
  }
443
429
 
444
430
  assert_equal(client_cursors,
445
- $db.command("cursorInfo" => 1)["clientCursors_size"])
431
+ Cfg.db.command("cursorInfo" => 1)["clientCursors_size"])
446
432
  end
447
433
 
448
434
  def test_count_with_fields
449
- $coll.save("x" => 1)
435
+ Cfg.coll.save("x" => 1)
450
436
 
451
- assert_equal(1, $coll.find({}, :fields => ["a"]).count())
437
+ assert_equal(1, Cfg.coll.find({}, :fields => ["a"]).count())
452
438
  end
453
439
 
454
440
  def test_has_next
455
441
 
456
442
  200.times do |n|
457
- $coll.save("x" => n)
443
+ Cfg.coll.save("x" => n)
458
444
  end
459
445
 
460
- cursor = $coll.find
446
+ cursor = Cfg.coll.find
461
447
  n = 0
462
448
  while cursor.has_next?
463
449
  assert cursor.next
@@ -471,10 +457,10 @@ class CursorTest < MiniTest::Unit::TestCase
471
457
  def test_cursor_invalid
472
458
 
473
459
  10000.times do |n|
474
- $coll.insert({:a => n})
460
+ Cfg.coll.insert({:a => n})
475
461
  end
476
462
 
477
- cursor = $coll.find({})
463
+ cursor = Cfg.coll.find({})
478
464
 
479
465
  # assert_raises_error Mongo::OperationFailure, "CURSOR_NOT_FOUND" do
480
466
  # 9999.times do
@@ -487,13 +473,13 @@ class CursorTest < MiniTest::Unit::TestCase
487
473
  def test_enumberables
488
474
 
489
475
  100.times do |n|
490
- $coll.insert({:a => n})
476
+ Cfg.coll.insert({:a => n})
491
477
  end
492
478
 
493
- assert_equal 100, $coll.find.to_a.length
494
- assert_equal 100, $coll.find.to_set.length
479
+ assert_equal 100, Cfg.coll.find.to_a.length
480
+ assert_equal 100, Cfg.coll.find.to_set.length
495
481
 
496
- cursor = $coll.find
482
+ cursor = Cfg.coll.find
497
483
  50.times { |n| cursor.next_document }
498
484
  assert_equal 50, cursor.to_a.length
499
485
  end
@@ -501,10 +487,10 @@ class CursorTest < MiniTest::Unit::TestCase
501
487
  def test_rewind
502
488
 
503
489
  100.times do |n|
504
- $coll.insert({:a => n})
490
+ Cfg.coll.insert({:a => n})
505
491
  end
506
492
 
507
- cursor = $coll.find
493
+ cursor = Cfg.coll.find
508
494
  cursor.to_a
509
495
  assert_equal false, cursor.has_next?
510
496
 
@@ -519,15 +505,15 @@ class CursorTest < MiniTest::Unit::TestCase
519
505
 
520
506
  def test_transformer
521
507
  transformer = Proc.new { |doc| doc }
522
- cursor = Cursor.new($coll, :transformer => transformer)
508
+ cursor = Cursor.new(Cfg.coll, :transformer => transformer)
523
509
  assert_equal(transformer, cursor.transformer)
524
510
  end
525
511
 
526
512
  def test_instance_transformation_with_next
527
- $coll.insert('a' => 1)
513
+ Cfg.coll.insert('a' => 1)
528
514
  klass = Struct.new(:id, :a)
529
515
  transformer = Proc.new { |doc| klass.new(doc['_id'], doc['a']) }
530
- cursor = Cursor.new($coll, :transformer => transformer)
516
+ cursor = Cursor.new(Cfg.coll, :transformer => transformer)
531
517
  instance = cursor.next
532
518
 
533
519
  assert_instance_of(klass, instance)
@@ -538,7 +524,7 @@ class CursorTest < MiniTest::Unit::TestCase
538
524
  def test_instance_transformation_with_each
539
525
  klass = Struct.new(:id, :a)
540
526
  transformer = Proc.new { |doc| klass.new(doc['_id'], doc['a']) }
541
- cursor = Cursor.new($coll, :transformer => transformer)
527
+ cursor = Cursor.new(Cfg.coll, :transformer => transformer)
542
528
 
543
529
  cursor.each do |instance|
544
530
  assert_instance_of(klass, instance)