mongodb-mongo 0.5.2 → 0.5.3

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/bin/run_test_script CHANGED
@@ -6,7 +6,7 @@
6
6
  HERE=`dirname $0`
7
7
 
8
8
  begintime=`date`
9
- ruby $HERE/../tests/mongo-qa/$1
9
+ ruby $HERE/../tests/mongo-qa/$1 >> $2
10
10
  exitval=$?
11
11
  endtime=`date`
12
12
 
@@ -108,6 +108,7 @@ module XGen
108
108
  # Create a new index named +index_name+. +fields+ should be an array
109
109
  # of field names.
110
110
  def create_index(name, *fields)
111
+ fields = *fields if fields.kind_of?(Array) && fields.length == 1
111
112
  @db.create_index(@name, name, fields)
112
113
  end
113
114
 
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'mongo'
3
- s.version = '0.5.2'
3
+ s.version = '0.5.3'
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_admin.rb CHANGED
@@ -7,24 +7,21 @@ class AdminTest < Test::Unit::TestCase
7
7
 
8
8
  include XGen::Mongo::Driver
9
9
 
10
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
11
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
12
+ @@coll = @@db.collection('test')
13
+
10
14
  def setup
11
- host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
- @db = Mongo.new(host, port).db('ruby-mongo-test')
14
15
  # Insert some data to make sure the database itself exists.
15
- @coll = @db.collection('test')
16
- @coll.clear
17
- @r1 = @coll.insert('a' => 1) # collection not created until it's used
18
- @coll_full_name = 'ruby-mongo-test.test'
19
- @admin = @db.admin
16
+ @@coll.clear
17
+ @r1 = @@coll.insert('a' => 1) # collection not created until it's used
18
+ @@coll_full_name = 'ruby-mongo-test.test'
19
+ @admin = @@db.admin
20
20
  end
21
21
 
22
22
  def teardown
23
- if @db.connected?
24
- @admin.profiling_level = :off
25
- @coll.clear if @coll
26
- @db.close
27
- end
23
+ @admin.profiling_level = :off
24
+ @@coll.clear if @@coll
28
25
  end
29
26
 
30
27
  def test_default_profiling_level
@@ -41,7 +38,7 @@ class AdminTest < Test::Unit::TestCase
41
38
  def test_profiling_info
42
39
  # Perform at least one query while profiling so we have something to see.
43
40
  @admin.profiling_level = :all
44
- @coll.find()
41
+ @@coll.find()
45
42
  @admin.profiling_level = :off
46
43
 
47
44
  info = @admin.profiling_info
@@ -54,7 +51,7 @@ class AdminTest < Test::Unit::TestCase
54
51
  end
55
52
 
56
53
  def test_validate_collection
57
- doc = @admin.validate_collection(@coll.name)
54
+ doc = @admin.validate_collection(@@coll.name)
58
55
  assert_not_nil doc
59
56
  result = doc['result']
60
57
  assert_not_nil result
data/tests/test_chunk.rb CHANGED
@@ -8,26 +8,22 @@ class ChunkTest < Test::Unit::TestCase
8
8
  include XGen::Mongo::Driver
9
9
  include XGen::Mongo::GridFS
10
10
 
11
- def setup
12
- @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13
- @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
14
- @db = Mongo.new(@host, @port).db('ruby-mongo-utils-test')
11
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
12
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-utils-test')
13
+ @@files = @@db.collection('gridfs.files')
14
+ @@chunks = @@db.collection('gridfs.chunks')
15
15
 
16
- @files = @db.collection('gridfs.files')
17
- @chunks = @db.collection('gridfs.chunks')
18
- @chunks.clear
19
- @files.clear
16
+ def setup
17
+ @@chunks.clear
18
+ @@files.clear
20
19
 
21
- @f = GridStore.new(@db, 'foobar', 'w')
20
+ @f = GridStore.new(@@db, 'foobar', 'w')
22
21
  @c = @f.instance_variable_get('@curr_chunk')
23
22
  end
24
23
 
25
24
  def teardown
26
- if @db && @db.connected?
27
- @chunks.clear
28
- @files.clear
29
- @db.close
30
- end
25
+ @@chunks.clear
26
+ @@files.clear
31
27
  end
32
28
 
33
29
  def test_pos
data/tests/test_cursor.rb CHANGED
@@ -7,25 +7,22 @@ class CursorTest < Test::Unit::TestCase
7
7
 
8
8
  include XGen::Mongo::Driver
9
9
 
10
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
11
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
12
+ @@coll = @@db.collection('test')
13
+
10
14
  def setup
11
- host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
- @db = Mongo.new(host, port).db('ruby-mongo-test')
14
- @coll = @db.collection('test')
15
- @coll.clear
16
- @r1 = @coll.insert('a' => 1) # collection not created until it's used
17
- @coll_full_name = 'ruby-mongo-test.test'
15
+ @@coll.clear
16
+ @@coll.insert('a' => 1) # collection not created until it's used
17
+ @@coll_full_name = 'ruby-mongo-test.test'
18
18
  end
19
19
 
20
20
  def teardown
21
- if @db.connected?
22
- @coll.clear if @coll
23
- @db.close
24
- end
21
+ @@coll.clear
25
22
  end
26
23
 
27
24
  def test_explain
28
- cursor = @coll.find('a' => 1)
25
+ cursor = @@coll.find('a' => 1)
29
26
  explaination = cursor.explain
30
27
  assert_not_nil explaination['cursor']
31
28
  assert_kind_of Numeric, explaination['n']
@@ -35,7 +32,7 @@ class CursorTest < Test::Unit::TestCase
35
32
 
36
33
  def test_close_no_query_sent
37
34
  begin
38
- cursor = @coll.find('a' => 1)
35
+ cursor = @@coll.find('a' => 1)
39
36
  cursor.close
40
37
  assert cursor.closed?
41
38
  rescue => ex
@@ -45,7 +42,7 @@ class CursorTest < Test::Unit::TestCase
45
42
 
46
43
  def test_close_after_query_sent
47
44
  begin
48
- cursor = @coll.find('a' => 1)
45
+ cursor = @@coll.find('a' => 1)
49
46
  cursor.next_object
50
47
  cursor.close
51
48
  assert cursor.closed?
data/tests/test_db.rb CHANGED
@@ -15,50 +15,53 @@ class DBTest < Test::Unit::TestCase
15
15
 
16
16
  include XGen::Mongo::Driver
17
17
 
18
- def setup
19
- @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
20
- @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
21
- @db = Mongo.new(@host, @port).db('ruby-mongo-test')
18
+ @@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
19
+ @@port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
20
+ @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test')
21
+ @@users = @@db.collection('system.users')
22
22
 
23
+ def setup
23
24
  @spongebob = 'spongebob'
24
25
  @spongebob_password = 'squarepants'
25
- @users = @db.collection('system.users')
26
- @users.clear
27
- @users.insert(:user => @spongebob, :pwd => @db.send(:hash_password, @spongebob, @spongebob_password))
26
+ @@users.clear
27
+ @@users.insert(:user => @spongebob, :pwd => @@db.send(:hash_password, @spongebob, @spongebob_password))
28
28
  end
29
29
 
30
30
  def teardown
31
- if @db && @db.connected?
32
- @users.clear if @users
33
- @db.close
34
- end
31
+ @@users.clear if @@users
35
32
  end
36
33
 
37
34
  def test_close
38
- @db.close
39
- assert !@db.connected?
35
+ @@db.close
36
+ assert !@@db.connected?
40
37
  begin
41
- @db.collection('test').insert('a' => 1)
38
+ @@db.collection('test').insert('a' => 1)
42
39
  fail "expected 'NilClass' exception"
43
40
  rescue => ex
44
41
  assert_match /NilClass/, ex.to_s
42
+ ensure
43
+ @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test')
44
+ @@users = @@db.collection('system.users')
45
45
  end
46
46
  end
47
47
 
48
48
  def test_full_coll_name
49
- coll = @db.collection('test')
50
- assert_equal 'ruby-mongo-test.test', @db.full_coll_name(coll.name)
49
+ coll = @@db.collection('test')
50
+ assert_equal 'ruby-mongo-test.test', @@db.full_coll_name(coll.name)
51
51
  end
52
52
 
53
53
  def test_pair
54
- @db.close
55
- @users = nil
56
- @db = Mongo.new({:left => "this-should-fail", :right => [@host, @port]}).db('ruby-mongo-test')
57
- assert @db.connected?
54
+ @@db.close
55
+ @@users = nil
56
+ @@db = Mongo.new({:left => "this-should-fail", :right => [@@host, @@port]}).db('ruby-mongo-test')
57
+ assert @@db.connected?
58
+ ensure
59
+ @@db = Mongo.new(@@host, @@port) unless @@db.connected?
60
+ @@users = @@db.collection('system.users')
58
61
  end
59
62
 
60
63
  def test_pk_factory
61
- db = Mongo.new(@host, @port).db('ruby-mongo-test', :pk => TestPKFactory.new)
64
+ db = Mongo.new(@@host, @@port).db('ruby-mongo-test', :pk => TestPKFactory.new)
62
65
  coll = db.collection('test')
63
66
  coll.clear
64
67
 
@@ -80,28 +83,31 @@ class DBTest < Test::Unit::TestCase
80
83
  end
81
84
 
82
85
  def test_pk_factory_reset
83
- @db.pk_factory = Object.new # first time
86
+ db = Mongo.new(@@host, @@port).db('ruby-mongo-test')
87
+ db.pk_factory = Object.new # first time
84
88
  begin
85
- @db.pk_factory = Object.new
89
+ db.pk_factory = Object.new
86
90
  fail "error: expected exception"
87
91
  rescue => ex
88
92
  assert_match /can not change PK factory/, ex.to_s
93
+ ensure
94
+ db.close
89
95
  end
90
96
  end
91
97
 
92
98
  def test_authenticate
93
- assert !@db.authenticate('nobody', 'nopassword')
94
- assert !@db.authenticate(@spongebob, 'squareliederhosen')
95
- assert @db.authenticate(@spongebob, @spongebob_password)
99
+ assert !@@db.authenticate('nobody', 'nopassword')
100
+ assert !@@db.authenticate(@spongebob, 'squareliederhosen')
101
+ assert @@db.authenticate(@spongebob, @spongebob_password)
96
102
  end
97
103
 
98
104
  def test_logout
99
- @db.logout # only testing that we don't throw exception
105
+ @@db.logout # only testing that we don't throw exception
100
106
  end
101
107
 
102
108
  def test_auto_connect
103
- @db.close
104
- db = Mongo.new(@host, @port, :auto_reconnect => true).db('ruby-mongo-test')
109
+ @@db.close
110
+ db = Mongo.new(@@host, @@port, :auto_reconnect => true).db('ruby-mongo-test')
105
111
  assert db.connected?
106
112
  assert db.auto_reconnect?
107
113
  db.close
@@ -109,22 +115,25 @@ class DBTest < Test::Unit::TestCase
109
115
  assert db.auto_reconnect?
110
116
  db.collection('test').insert('a' => 1)
111
117
  assert db.connected?
118
+ ensure
119
+ @@db = Mongo.new(@@host, @@port).db('ruby-mongo-test')
120
+ @@users = @@db.collection('system.users')
112
121
  end
113
122
 
114
123
  def test_error
115
- doc = @db.send(:db_command, :forceerror => 1)
116
- assert @db.error?
117
- err = @db.error
124
+ doc = @@db.send(:db_command, :forceerror => 1)
125
+ assert @@db.error?
126
+ err = @@db.error
118
127
  assert_match /forced error/, err
119
128
 
120
129
  # ask again
121
- assert @db.error?
122
- err2 = @db.error
130
+ assert @@db.error?
131
+ err2 = @@db.error
123
132
  assert_equal err, err2
124
133
  end
125
134
 
126
135
  def test_text_port_number
127
- db = DB.new('ruby-mongo-test', [[@host, @port.to_s]])
136
+ db = DB.new('ruby-mongo-test', [[@@host, @@port.to_s]])
128
137
  # If there is no error, all is well
129
138
  db.collection('users').clear
130
139
  end
data/tests/test_db_api.rb CHANGED
@@ -7,51 +7,48 @@ class DBAPITest < Test::Unit::TestCase
7
7
 
8
8
  include XGen::Mongo::Driver
9
9
 
10
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
11
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
12
+ @@coll = @@db.collection('test')
13
+
10
14
  def setup
11
- host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
12
- port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
13
- @db = Mongo.new(host, port).db('ruby-mongo-test')
14
- @coll = @db.collection('test')
15
- @coll.clear
16
- @r1 = @coll.insert('a' => 1) # collection not created until it's used
17
- @coll_full_name = 'ruby-mongo-test.test'
15
+ @@coll.clear
16
+ @r1 = @@coll.insert('a' => 1) # collection not created until it's used
17
+ @@coll_full_name = 'ruby-mongo-test.test'
18
18
  end
19
19
 
20
20
  def teardown
21
- if @db.connected?
22
- @coll.clear unless @coll == nil
23
- @db.close
24
- end
21
+ @@coll.clear
25
22
  end
26
23
 
27
24
  def test_clear
28
- assert_equal 1, @coll.count
29
- @coll.clear
30
- assert_equal 0, @coll.count
25
+ assert_equal 1, @@coll.count
26
+ @@coll.clear
27
+ assert_equal 0, @@coll.count
31
28
  end
32
29
 
33
30
  def test_insert
34
- @coll.insert('a' => 2)
35
- @coll.insert('b' => 3)
31
+ @@coll.insert('a' => 2)
32
+ @@coll.insert('b' => 3)
36
33
 
37
- assert_equal 3, @coll.count
38
- docs = @coll.find().to_a
34
+ assert_equal 3, @@coll.count
35
+ docs = @@coll.find().to_a
39
36
  assert_equal 3, docs.length
40
37
  assert docs.detect { |row| row['a'] == 1 }
41
38
  assert docs.detect { |row| row['a'] == 2 }
42
39
  assert docs.detect { |row| row['b'] == 3 }
43
40
 
44
- @coll << {'b' => 4}
45
- docs = @coll.find().to_a
41
+ @@coll << {'b' => 4}
42
+ docs = @@coll.find().to_a
46
43
  assert_equal 4, docs.length
47
44
  assert docs.detect { |row| row['b'] == 4 }
48
45
  end
49
46
 
50
47
  def test_insert_multiple
51
- @coll.insert({'a' => 2}, {'b' => 3})
48
+ @@coll.insert({'a' => 2}, {'b' => 3})
52
49
 
53
- assert_equal 3, @coll.count
54
- docs = @coll.find().to_a
50
+ assert_equal 3, @@coll.count
51
+ docs = @@coll.find().to_a
55
52
  assert_equal 3, docs.length
56
53
  assert docs.detect { |row| row['a'] == 1 }
57
54
  assert docs.detect { |row| row['a'] == 2 }
@@ -59,15 +56,15 @@ class DBAPITest < Test::Unit::TestCase
59
56
  end
60
57
 
61
58
  def test_find_simple
62
- @r2 = @coll.insert('a' => 2)
63
- @r3 = @coll.insert('b' => 3)
59
+ @r2 = @@coll.insert('a' => 2)
60
+ @r3 = @@coll.insert('b' => 3)
64
61
  # Check sizes
65
- docs = @coll.find().to_a
62
+ docs = @@coll.find().to_a
66
63
  assert_equal 3, docs.size
67
- assert_equal 3, @coll.count
64
+ assert_equal 3, @@coll.count
68
65
 
69
66
  # Find by other value
70
- docs = @coll.find('a' => @r1['a']).to_a
67
+ docs = @@coll.find('a' => @r1['a']).to_a
71
68
  assert_equal 1, docs.size
72
69
  doc = docs.first
73
70
  # Can't compare _id values because at insert, an _id was added to @r1 by
@@ -78,58 +75,58 @@ class DBAPITest < Test::Unit::TestCase
78
75
  end
79
76
 
80
77
  def test_find_advanced
81
- @coll.insert('a' => 2)
82
- @coll.insert('b' => 3)
78
+ @@coll.insert('a' => 2)
79
+ @@coll.insert('b' => 3)
83
80
 
84
81
  # Find by advanced query (less than)
85
- docs = @coll.find('a' => { '$lt' => 10 }).to_a
82
+ docs = @@coll.find('a' => { '$lt' => 10 }).to_a
86
83
  assert_equal 2, docs.size
87
84
  assert docs.detect { |row| row['a'] == 1 }
88
85
  assert docs.detect { |row| row['a'] == 2 }
89
86
 
90
87
  # Find by advanced query (greater than)
91
- docs = @coll.find('a' => { '$gt' => 1 }).to_a
88
+ docs = @@coll.find('a' => { '$gt' => 1 }).to_a
92
89
  assert_equal 1, docs.size
93
90
  assert docs.detect { |row| row['a'] == 2 }
94
91
 
95
92
  # Find by advanced query (less than or equal to)
96
- docs = @coll.find('a' => { '$lte' => 1 }).to_a
93
+ docs = @@coll.find('a' => { '$lte' => 1 }).to_a
97
94
  assert_equal 1, docs.size
98
95
  assert docs.detect { |row| row['a'] == 1 }
99
96
 
100
97
  # Find by advanced query (greater than or equal to)
101
- docs = @coll.find('a' => { '$gte' => 1 }).to_a
98
+ docs = @@coll.find('a' => { '$gte' => 1 }).to_a
102
99
  assert_equal 2, docs.size
103
100
  assert docs.detect { |row| row['a'] == 1 }
104
101
  assert docs.detect { |row| row['a'] == 2 }
105
102
 
106
103
  # Find by advanced query (between)
107
- docs = @coll.find('a' => { '$gt' => 1, '$lt' => 3 }).to_a
104
+ docs = @@coll.find('a' => { '$gt' => 1, '$lt' => 3 }).to_a
108
105
  assert_equal 1, docs.size
109
106
  assert docs.detect { |row| row['a'] == 2 }
110
107
 
111
108
  # Find by advanced query (in clause)
112
- docs = @coll.find('a' => {'$in' => [1,2]}).to_a
109
+ docs = @@coll.find('a' => {'$in' => [1,2]}).to_a
113
110
  assert_equal 2, docs.size
114
111
  assert docs.detect { |row| row['a'] == 1 }
115
112
  assert docs.detect { |row| row['a'] == 2 }
116
113
 
117
114
  # Find by advanced query (regexp)
118
- docs = @coll.find('a' => /[1|2]/).to_a
115
+ docs = @@coll.find('a' => /[1|2]/).to_a
119
116
  assert_equal 2, docs.size
120
117
  assert docs.detect { |row| row['a'] == 1 }
121
118
  assert docs.detect { |row| row['a'] == 2 }
122
119
  end
123
120
 
124
121
  def test_find_sorting
125
- @coll.clear
126
- @coll.insert('a' => 1, 'b' => 2)
127
- @coll.insert('a' => 2, 'b' => 1)
128
- @coll.insert('a' => 3, 'b' => 2)
129
- @coll.insert('a' => 4, 'b' => 1)
122
+ @@coll.clear
123
+ @@coll.insert('a' => 1, 'b' => 2)
124
+ @@coll.insert('a' => 2, 'b' => 1)
125
+ @@coll.insert('a' => 3, 'b' => 2)
126
+ @@coll.insert('a' => 4, 'b' => 1)
130
127
 
131
128
  # Sorting (ascending)
132
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => 1}).to_a
129
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => 1}).to_a
133
130
  assert_equal 4, docs.size
134
131
  assert_equal 1, docs[0]['a']
135
132
  assert_equal 2, docs[1]['a']
@@ -137,7 +134,7 @@ class DBAPITest < Test::Unit::TestCase
137
134
  assert_equal 4, docs[3]['a']
138
135
 
139
136
  # Sorting (descending)
140
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => -1}).to_a
137
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => {'a' => -1}).to_a
141
138
  assert_equal 4, docs.size
142
139
  assert_equal 4, docs[0]['a']
143
140
  assert_equal 3, docs[1]['a']
@@ -145,7 +142,7 @@ class DBAPITest < Test::Unit::TestCase
145
142
  assert_equal 1, docs[3]['a']
146
143
 
147
144
  # Sorting using array of names; assumes ascending order.
148
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => ['a']).to_a
145
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => ['a']).to_a
149
146
  assert_equal 4, docs.size
150
147
  assert_equal 1, docs[0]['a']
151
148
  assert_equal 2, docs[1]['a']
@@ -153,14 +150,14 @@ class DBAPITest < Test::Unit::TestCase
153
150
  assert_equal 4, docs[3]['a']
154
151
 
155
152
  # Sorting using single name; assumes ascending order.
156
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => 'a').to_a
153
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => 'a').to_a
157
154
  assert_equal 4, docs.size
158
155
  assert_equal 1, docs[0]['a']
159
156
  assert_equal 2, docs[1]['a']
160
157
  assert_equal 3, docs[2]['a']
161
158
  assert_equal 4, docs[3]['a']
162
159
 
163
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => ['b', 'a']).to_a
160
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => ['b', 'a']).to_a
164
161
  assert_equal 4, docs.size
165
162
  assert_equal 2, docs[0]['a']
166
163
  assert_equal 4, docs[1]['a']
@@ -169,19 +166,19 @@ class DBAPITest < Test::Unit::TestCase
169
166
 
170
167
  # Sorting using empty array; no order guarantee (Mongo bug #898) but
171
168
  # should not blow up.
172
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => []).to_a
169
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => []).to_a
173
170
  assert_equal 4, docs.size
174
171
 
175
172
  # Sorting using array of hashes; no order guarantee (Mongo bug #898) but
176
173
  # should not blow up.
177
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => [{'b' => 1}, {'a' => -1}]).to_a
174
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => [{'b' => 1}, {'a' => -1}]).to_a
178
175
  assert_equal 4, docs.size
179
176
 
180
177
  # Sorting using ordered hash. You can use an unordered one, but then the
181
178
  # order of the keys won't be guaranteed thus your sort won't make sense.
182
179
  oh = OrderedHash.new
183
180
  oh['a'] = -1
184
- docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => oh).to_a
181
+ docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => oh).to_a
185
182
  assert_equal 4, docs.size
186
183
  assert_equal 4, docs[0]['a']
187
184
  assert_equal 3, docs[1]['a']
@@ -192,7 +189,7 @@ class DBAPITest < Test::Unit::TestCase
192
189
  # oh = OrderedHash.new
193
190
  # oh['b'] = -1
194
191
  # oh['a'] = 1
195
- # docs = @coll.find({'a' => { '$lt' => 10 }}, :sort => oh).to_a
192
+ # docs = @@coll.find({'a' => { '$lt' => 10 }}, :sort => oh).to_a
196
193
  # assert_equal 4, docs.size
197
194
  # assert_equal 1, docs[0]['a']
198
195
  # assert_equal 3, docs[1]['a']
@@ -201,90 +198,106 @@ class DBAPITest < Test::Unit::TestCase
201
198
  end
202
199
 
203
200
  def test_find_limits
204
- @coll.insert('b' => 2)
205
- @coll.insert('c' => 3)
206
- @coll.insert('d' => 4)
201
+ @@coll.insert('b' => 2)
202
+ @@coll.insert('c' => 3)
203
+ @@coll.insert('d' => 4)
207
204
 
208
- docs = @coll.find({}, :limit => 1).to_a
205
+ docs = @@coll.find({}, :limit => 1).to_a
209
206
  assert_equal 1, docs.size
210
- docs = @coll.find({}, :limit => 2).to_a
207
+ docs = @@coll.find({}, :limit => 2).to_a
211
208
  assert_equal 2, docs.size
212
- docs = @coll.find({}, :limit => 3).to_a
209
+ docs = @@coll.find({}, :limit => 3).to_a
213
210
  assert_equal 3, docs.size
214
- docs = @coll.find({}, :limit => 4).to_a
211
+ docs = @@coll.find({}, :limit => 4).to_a
215
212
  assert_equal 4, docs.size
216
- docs = @coll.find({}).to_a
213
+ docs = @@coll.find({}).to_a
217
214
  assert_equal 4, docs.size
218
- docs = @coll.find({}, :limit => 99).to_a
215
+ docs = @@coll.find({}, :limit => 99).to_a
219
216
  assert_equal 4, docs.size
220
217
  end
221
218
 
222
219
  def test_drop_collection
223
- assert @db.drop_collection(@coll.name), "drop of collection #{@coll.name} failed"
224
- assert !@db.collection_names.include?(@coll_full_name)
225
- @coll = nil
220
+ assert @@db.drop_collection(@@coll.name), "drop of collection #{@@coll.name} failed"
221
+ assert !@@db.collection_names.include?(@@coll_full_name)
226
222
  end
227
223
 
228
224
  def test_collection_names
229
- names = @db.collection_names
225
+ names = @@db.collection_names
230
226
  assert names.length >= 1
231
- assert names.include?(@coll_full_name)
227
+ assert names.include?(@@coll_full_name)
232
228
 
233
- coll2 = @db.collection('test2')
229
+ coll2 = @@db.collection('test2')
234
230
  coll2.insert('a' => 1) # collection not created until it's used
235
- names = @db.collection_names
231
+ names = @@db.collection_names
236
232
  assert names.length >= 2
237
- assert names.include?(@coll_full_name)
233
+ assert names.include?(@@coll_full_name)
238
234
  assert names.include?('ruby-mongo-test.test2')
239
235
  ensure
240
- @db.drop_collection('test2')
236
+ @@db.drop_collection('test2')
241
237
  end
242
238
 
243
239
  def test_collections_info
244
- cursor = @db.collections_info
240
+ cursor = @@db.collections_info
245
241
  rows = cursor.to_a
246
242
  assert rows.length >= 1
247
- row = rows.detect { |r| r['name'] == @coll_full_name }
243
+ row = rows.detect { |r| r['name'] == @@coll_full_name }
248
244
  assert_not_nil row
249
245
  end
250
246
 
251
247
  def test_collection_options
252
- @db.drop_collection('foobar')
253
- @db.strict = true
248
+ @@db.drop_collection('foobar')
249
+ @@db.strict = true
254
250
 
255
251
  begin
256
- coll = @db.create_collection('foobar', :capped => true, :size => 1024)
252
+ coll = @@db.create_collection('foobar', :capped => true, :size => 1024)
257
253
  options = coll.options()
258
254
  assert_equal 'foobar', options['create']
259
255
  assert_equal true, options['capped']
260
256
  assert_equal 1024, options['size']
261
257
  rescue => ex
262
- @db.drop_collection('foobar')
258
+ @@db.drop_collection('foobar')
263
259
  fail "did not expect exception \"#{ex}\""
260
+ ensure
261
+ @@db.strict = false
264
262
  end
265
263
  end
266
264
 
267
265
  def test_index_information
268
- @db.create_index(@coll.name, 'index_name', ['a'])
269
- list = @db.index_information(@coll.name)
266
+ @@db.create_index(@@coll.name, 'index_name', ['a'])
267
+ list = @@db.index_information(@@coll.name)
270
268
  assert_equal 1, list.length
271
269
 
272
270
  info = list[0]
273
271
  assert_equal 'index_name', info[:name]
274
272
  assert_equal 1, info[:keys]['a']
273
+ ensure
274
+ @@db.drop_index(@@coll.name, 'index_name')
275
+ end
276
+
277
+ def test_multiple_index_cols
278
+ @@db.create_index(@@coll.name, 'index_name', ['a', 'b', 'c'])
279
+ list = @@db.index_information(@@coll.name)
280
+ assert_equal 1, list.length
281
+
282
+ info = list[0]
283
+ assert_equal 'index_name', info[:name]
284
+ keys = info[:keys].keys
285
+ assert_equal ['a', 'b', 'c'], keys.sort
286
+ ensure
287
+ @@db.drop_index(@@coll.name, 'index_name')
275
288
  end
276
289
 
277
290
  def test_array
278
- @coll << {'b' => [1, 2, 3]}
279
- rows = @coll.find({}, {:fields => ['b']}).to_a
291
+ @@coll << {'b' => [1, 2, 3]}
292
+ rows = @@coll.find({}, {:fields => ['b']}).to_a
280
293
  assert_equal 1, rows.length
281
294
  assert_equal [1, 2, 3], rows[0]['b']
282
295
  end
283
296
 
284
297
  def test_regex
285
298
  regex = /foobar/i
286
- @coll << {'b' => regex}
287
- rows = @coll.find({}, {:fields => ['b']}).to_a
299
+ @@coll << {'b' => regex}
300
+ rows = @@coll.find({}, {:fields => ['b']}).to_a
288
301
  assert_equal 1, rows.length
289
302
  assert_equal regex, rows[0]['b']
290
303
  end
@@ -293,37 +306,39 @@ class DBAPITest < Test::Unit::TestCase
293
306
  # Note: can't use Time.new because that will include fractional seconds,
294
307
  # which Mongo does not store.
295
308
  t = Time.at(1234567890)
296
- @coll << {'_id' => t}
297
- rows = @coll.find({'_id' => t}).to_a
309
+ @@coll << {'_id' => t}
310
+ rows = @@coll.find({'_id' => t}).to_a
298
311
  assert_equal 1, rows.length
299
312
  assert_equal t, rows[0]['_id']
300
313
  end
301
314
 
302
315
  def test_strict
303
- assert !@db.strict?
304
- @db.strict = true
305
- assert @db.strict?
316
+ assert !@@db.strict?
317
+ @@db.strict = true
318
+ assert @@db.strict?
319
+ ensure
320
+ @@db.strict = false
306
321
  end
307
322
 
308
323
  def test_strict_access_collection
309
- @db.strict = true
324
+ @@db.strict = true
310
325
  begin
311
- @db.collection('does-not-exist')
326
+ @@db.collection('does-not-exist')
312
327
  fail "expected exception"
313
328
  rescue => ex
314
329
  assert_equal "Collection does-not-exist doesn't exist. Currently in strict mode.", ex.to_s
315
330
  ensure
316
- @db.strict = false
317
- @db.drop_collection('does-not-exist')
331
+ @@db.strict = false
332
+ @@db.drop_collection('does-not-exist')
318
333
  end
319
334
  end
320
335
 
321
336
  def test_strict_create_collection
322
- @db.drop_collection('foobar')
323
- @db.strict = true
337
+ @@db.drop_collection('foobar')
338
+ @@db.strict = true
324
339
 
325
340
  begin
326
- @db.create_collection('foobar')
341
+ @@db.create_collection('foobar')
327
342
  assert true
328
343
  rescue => ex
329
344
  fail "did not expect exception \"#{ex}\""
@@ -331,18 +346,18 @@ class DBAPITest < Test::Unit::TestCase
331
346
 
332
347
  # Now the collection exists. This time we should see an exception.
333
348
  begin
334
- @db.create_collection('foobar')
349
+ @@db.create_collection('foobar')
335
350
  fail "expected exception"
336
351
  rescue => ex
337
352
  assert_equal "Collection foobar already exists. Currently in strict mode.", ex.to_s
338
353
  ensure
339
- @db.strict = false
340
- @db.drop_collection('foobar')
354
+ @@db.strict = false
355
+ @@db.drop_collection('foobar')
341
356
  end
342
357
  end
343
358
 
344
359
  def test_to_a
345
- cursor = @coll.find()
360
+ cursor = @@coll.find()
346
361
  rows = cursor.to_a
347
362
 
348
363
  # Make sure we get back exactly the same array the next time we ask
@@ -357,7 +372,7 @@ class DBAPITest < Test::Unit::TestCase
357
372
  end
358
373
 
359
374
  def test_to_a_after_each
360
- cursor = @coll.find
375
+ cursor = @@coll.find
361
376
  cursor.each { |row| row }
362
377
  begin
363
378
  cursor.to_a
@@ -368,40 +383,40 @@ class DBAPITest < Test::Unit::TestCase
368
383
  end
369
384
 
370
385
  def test_ismaster
371
- assert @db.master?
386
+ assert @@db.master?
372
387
  end
373
388
 
374
389
  def test_master
375
- assert_equal "#{@db.host}:#{@db.port}", @db.master
390
+ assert_equal "#{@@db.host}:#{@@db.port}", @@db.master
376
391
  end
377
392
 
378
393
  def test_hint
379
- @coll.create_index('test_a_index', 'a')
394
+ @@coll.create_index('test_a_index', 'a')
380
395
  begin
381
- assert_nil @coll.hint
382
- assert_equal 1, @coll.find({'a' => 1}, :hint => 'a').to_a.size
383
- assert_equal 1, @coll.find({'a' => 1}, :hint => ['a']).to_a.size
384
- assert_equal 1, @coll.find({'a' => 1}, :hint => {'a' => 1}).to_a.size
385
-
386
- @coll.hint = 'a'
387
- assert_equal({'a' => 1}, @coll.hint)
388
- assert_equal 1, @coll.find('a' => 1).to_a.size
389
-
390
- @coll.hint = ['a']
391
- assert_equal({'a' => 1}, @coll.hint)
392
- assert_equal 1, @coll.find('a' => 1).to_a.size
393
-
394
- @coll.hint = {'a' => 1}
395
- assert_equal({'a' => 1}, @coll.hint)
396
- assert_equal 1, @coll.find('a' => 1).to_a.size
397
-
398
- @coll.hint = nil
399
- assert_nil @coll.hint
400
- assert_equal 1, @coll.find('a' => 1).to_a.size
396
+ assert_nil @@coll.hint
397
+ assert_equal 1, @@coll.find({'a' => 1}, :hint => 'a').to_a.size
398
+ assert_equal 1, @@coll.find({'a' => 1}, :hint => ['a']).to_a.size
399
+ assert_equal 1, @@coll.find({'a' => 1}, :hint => {'a' => 1}).to_a.size
400
+
401
+ @@coll.hint = 'a'
402
+ assert_equal({'a' => 1}, @@coll.hint)
403
+ assert_equal 1, @@coll.find('a' => 1).to_a.size
404
+
405
+ @@coll.hint = ['a']
406
+ assert_equal({'a' => 1}, @@coll.hint)
407
+ assert_equal 1, @@coll.find('a' => 1).to_a.size
408
+
409
+ @@coll.hint = {'a' => 1}
410
+ assert_equal({'a' => 1}, @@coll.hint)
411
+ assert_equal 1, @@coll.find('a' => 1).to_a.size
412
+
413
+ @@coll.hint = nil
414
+ assert_nil @@coll.hint
415
+ assert_equal 1, @@coll.find('a' => 1).to_a.size
401
416
  rescue => ex
402
417
  fail ex.to_s
403
418
  ensure
404
- @coll.drop_index('test_a_index')
419
+ @@coll.drop_index('test_a_index')
405
420
  end
406
421
  end
407
422
 
@@ -410,11 +425,11 @@ class DBAPITest < Test::Unit::TestCase
410
425
 
411
426
  # def test_insert_undefined
412
427
  # doc = {'undef' => Undefined.new}
413
- # @coll.clear
414
- # @coll.insert(doc)
415
- # p @db.error # DEBUG
416
- # assert_equal 1, @coll.count
417
- # row = @coll.find().next_object
428
+ # @@coll.clear
429
+ # @@coll.insert(doc)
430
+ # p @@db.error # DEBUG
431
+ # assert_equal 1, @@coll.count
432
+ # row = @@coll.find().next_object
418
433
  # assert_not_nil row
419
434
  # end
420
435
 
@@ -8,35 +8,30 @@ class GridStoreTest < Test::Unit::TestCase
8
8
  include XGen::Mongo::Driver
9
9
  include XGen::Mongo::GridFS
10
10
 
11
- def setup
12
- @host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
13
- @port = ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT
14
- @db = Mongo.new(@host, @port).db('ruby-mongo-utils-test')
15
-
16
- @files = @db.collection('gridfs.files')
17
- @chunks = @db.collection('gridfs.chunks')
18
- @chunks.clear
19
- @files.clear
11
+ @@db = Mongo.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost',
12
+ ENV['MONGO_RUBY_DRIVER_PORT'] || Mongo::DEFAULT_PORT).db('ruby-mongo-test')
13
+ @@files = @@db.collection('gridfs.files')
14
+ @@chunks = @@db.collection('gridfs.chunks')
20
15
 
21
- GridStore.open(@db, 'foobar', 'w') { |f| f.write("hello, world!") }
16
+ def setup
17
+ @@chunks.clear
18
+ @@files.clear
19
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write("hello, world!") }
22
20
  end
23
21
 
24
22
  def teardown
25
- if @db && @db.connected?
26
- @chunks.clear
27
- @files.clear
28
- @db.close
29
- end
23
+ @@chunks.clear
24
+ @@files.clear
30
25
  end
31
26
 
32
27
  def test_exist
33
- assert GridStore.exist?(@db, 'foobar')
34
- assert !GridStore.exist?(@db, 'does_not_exist')
35
- assert !GridStore.exist?(@db, 'foobar', 'another_root')
28
+ assert GridStore.exist?(@@db, 'foobar')
29
+ assert !GridStore.exist?(@@db, 'does_not_exist')
30
+ assert !GridStore.exist?(@@db, 'foobar', 'another_root')
36
31
  end
37
32
 
38
33
  def test_small_write
39
- rows = @files.find({'filename' => 'foobar'}).to_a
34
+ rows = @@files.find({'filename' => 'foobar'}).to_a
40
35
  assert_not_nil rows
41
36
  assert_equal 1, rows.length
42
37
  row = rows[0]
@@ -44,37 +39,37 @@ class GridStoreTest < Test::Unit::TestCase
44
39
 
45
40
  file_id = row['_id']
46
41
  assert_kind_of ObjectID, file_id
47
- rows = @chunks.find({'files_id' => file_id}).to_a
42
+ rows = @@chunks.find({'files_id' => file_id}).to_a
48
43
  assert_not_nil rows
49
44
  assert_equal 1, rows.length
50
45
  end
51
46
 
52
47
  def test_small_file
53
- rows = @files.find({'filename' => 'foobar'}).to_a
48
+ rows = @@files.find({'filename' => 'foobar'}).to_a
54
49
  assert_not_nil rows
55
50
  assert_equal 1, rows.length
56
51
  row = rows[0]
57
52
  assert_not_nil row
58
- assert_equal "hello, world!", GridStore.read(@db, 'foobar')
53
+ assert_equal "hello, world!", GridStore.read(@@db, 'foobar')
59
54
  end
60
55
 
61
56
  def test_overwrite
62
- GridStore.open(@db, 'foobar', 'w') { |f| f.write("overwrite") }
63
- assert_equal "overwrite", GridStore.read(@db, 'foobar')
57
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write("overwrite") }
58
+ assert_equal "overwrite", GridStore.read(@@db, 'foobar')
64
59
  end
65
60
 
66
61
  def test_read_length
67
- assert_equal "hello", GridStore.read(@db, 'foobar', 5)
62
+ assert_equal "hello", GridStore.read(@@db, 'foobar', 5)
68
63
  end
69
64
 
70
65
  # Also tests seek
71
66
  def test_read_with_offset
72
- assert_equal "world", GridStore.read(@db, 'foobar', 5, 7)
73
- assert_equal "world!", GridStore.read(@db, 'foobar', nil, 7)
67
+ assert_equal "world", GridStore.read(@@db, 'foobar', 5, 7)
68
+ assert_equal "world!", GridStore.read(@@db, 'foobar', nil, 7)
74
69
  end
75
70
 
76
71
  def test_seek
77
- GridStore.open(@db, 'foobar', 'r') { |f|
72
+ GridStore.open(@@db, 'foobar', 'r') { |f|
78
73
  f.seek(0)
79
74
  assert_equal 'h', f.getc.chr
80
75
  f.seek(7)
@@ -100,84 +95,84 @@ class GridStoreTest < Test::Unit::TestCase
100
95
  end
101
96
 
102
97
  def test_multi_chunk
103
- @chunks.clear
104
- @files.clear
98
+ @@chunks.clear
99
+ @@files.clear
105
100
 
106
101
  size = 512
107
- GridStore.open(@db, 'biggie', 'w') { |f|
102
+ GridStore.open(@@db, 'biggie', 'w') { |f|
108
103
  f.chunk_size = size
109
104
  f.write('x' * size)
110
105
  f.write('y' * size)
111
106
  f.write('z' * size)
112
107
  }
113
108
 
114
- assert_equal 3, @chunks.count
115
- assert_equal ('x' * size) + ('y' * size) + ('z' * size), GridStore.read(@db, 'biggie')
109
+ assert_equal 3, @@chunks.count
110
+ assert_equal ('x' * size) + ('y' * size) + ('z' * size), GridStore.read(@@db, 'biggie')
116
111
  end
117
112
 
118
113
  def test_puts_and_readlines
119
- GridStore.open(@db, 'multiline', 'w') { |f|
114
+ GridStore.open(@@db, 'multiline', 'w') { |f|
120
115
  f.puts "line one"
121
116
  f.puts "line two\n"
122
117
  f.puts "line three"
123
118
  }
124
119
 
125
- lines = GridStore.readlines(@db, 'multiline')
120
+ lines = GridStore.readlines(@@db, 'multiline')
126
121
  assert_equal ["line one\n", "line two\n", "line three\n"], lines
127
122
  end
128
123
 
129
124
  def test_unlink
130
- assert_equal 1, @files.count
131
- assert_equal 1, @chunks.count
132
- GridStore.unlink(@db, 'foobar')
133
- assert_equal 0, @files.count
134
- assert_equal 0, @chunks.count
125
+ assert_equal 1, @@files.count
126
+ assert_equal 1, @@chunks.count
127
+ GridStore.unlink(@@db, 'foobar')
128
+ assert_equal 0, @@files.count
129
+ assert_equal 0, @@chunks.count
135
130
  end
136
131
 
137
132
  def test_append
138
- GridStore.open(@db, 'foobar', 'w+') { |f| f.write(" how are you?") }
139
- assert_equal 1, @chunks.count
140
- assert_equal "hello, world! how are you?", GridStore.read(@db, 'foobar')
133
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.write(" how are you?") }
134
+ assert_equal 1, @@chunks.count
135
+ assert_equal "hello, world! how are you?", GridStore.read(@@db, 'foobar')
141
136
  end
142
137
 
143
138
  def test_rewind_and_truncate_on_write
144
- GridStore.open(@db, 'foobar', 'w') { |f|
139
+ GridStore.open(@@db, 'foobar', 'w') { |f|
145
140
  f.write("some text is inserted here")
146
141
  f.rewind
147
142
  f.write("abc")
148
143
  }
149
- assert_equal "abc", GridStore.read(@db, 'foobar')
144
+ assert_equal "abc", GridStore.read(@@db, 'foobar')
150
145
  end
151
146
 
152
147
  def test_tell
153
- GridStore.open(@db, 'foobar', 'r') { |f|
148
+ GridStore.open(@@db, 'foobar', 'r') { |f|
154
149
  f.read(5)
155
150
  assert_equal 5, f.tell
156
151
  }
157
152
  end
158
153
 
159
154
  def test_empty_block_ok
160
- GridStore.open(@db, 'empty', 'w')
155
+ GridStore.open(@@db, 'empty', 'w')
161
156
  end
162
157
 
163
158
  def test_save_empty_file
164
- @chunks.clear
165
- @files.clear
166
- GridStore.open(@db, 'empty', 'w') {} # re-write with zero bytes
167
- assert_equal 1, @files.count
168
- assert_equal 0, @chunks.count
159
+ @@chunks.clear
160
+ @@files.clear
161
+ GridStore.open(@@db, 'empty', 'w') {} # re-write with zero bytes
162
+ assert_equal 1, @@files.count
163
+ assert_equal 0, @@chunks.count
169
164
  end
170
165
 
171
166
  def test_empty_file_eof
172
- GridStore.open(@db, 'empty', 'w')
173
- GridStore.open(@db, 'empty', 'r') { |f|
167
+ GridStore.open(@@db, 'empty', 'w')
168
+ GridStore.open(@@db, 'empty', 'r') { |f|
174
169
  assert f.eof?
175
170
  }
176
171
  end
177
172
 
178
173
  def test_cannot_change_chunk_size_on_read
179
174
  begin
180
- GridStore.open(@db, 'foobar', 'r') { |f| f.chunk_size = 42 }
175
+ GridStore.open(@@db, 'foobar', 'r') { |f| f.chunk_size = 42 }
181
176
  fail "should have seen error"
182
177
  rescue => ex
183
178
  assert_match /error: can only change chunk size/, ex.to_s
@@ -186,7 +181,7 @@ class GridStoreTest < Test::Unit::TestCase
186
181
 
187
182
  def test_cannot_change_chunk_size_after_data_written
188
183
  begin
189
- GridStore.open(@db, 'foobar', 'w') { |f|
184
+ GridStore.open(@@db, 'foobar', 'w') { |f|
190
185
  f.write("some text")
191
186
  f.chunk_size = 42
192
187
  }
@@ -197,18 +192,18 @@ class GridStoreTest < Test::Unit::TestCase
197
192
  end
198
193
 
199
194
  def test_change_chunk_size
200
- GridStore.open(@db, 'new-file', 'w') { |f|
195
+ GridStore.open(@@db, 'new-file', 'w') { |f|
201
196
  f.chunk_size = 42
202
197
  f.write("foo")
203
198
  }
204
- GridStore.open(@db, 'new-file', 'r') { |f|
199
+ GridStore.open(@@db, 'new-file', 'r') { |f|
205
200
  assert f.chunk_size == 42
206
201
  }
207
202
  end
208
203
 
209
204
  def test_chunk_size_in_option
210
- GridStore.open(@db, 'new-file', 'w', :chunk_size => 42) { |f| f.write("foo") }
211
- GridStore.open(@db, 'new-file', 'r') { |f|
205
+ GridStore.open(@@db, 'new-file', 'w', :chunk_size => 42) { |f| f.write("foo") }
206
+ GridStore.open(@@db, 'new-file', 'r') { |f|
212
207
  assert f.chunk_size == 42
213
208
  }
214
209
  end
@@ -216,46 +211,46 @@ class GridStoreTest < Test::Unit::TestCase
216
211
  def test_upload_date
217
212
  now = Time.now
218
213
  orig_file_upload_date = nil
219
- GridStore.open(@db, 'foobar', 'r') { |f| orig_file_upload_date = f.upload_date }
214
+ GridStore.open(@@db, 'foobar', 'r') { |f| orig_file_upload_date = f.upload_date }
220
215
  assert_not_nil orig_file_upload_date
221
216
  assert (orig_file_upload_date - now) < 5 # even a really slow system < 5 secs
222
217
 
223
218
  sleep(2)
224
- GridStore.open(@db, 'foobar', 'w') { |f| f.write "new data" }
219
+ GridStore.open(@@db, 'foobar', 'w') { |f| f.write "new data" }
225
220
  file_upload_date = nil
226
- GridStore.open(@db, 'foobar', 'r') { |f| file_upload_date = f.upload_date }
221
+ GridStore.open(@@db, 'foobar', 'r') { |f| file_upload_date = f.upload_date }
227
222
  assert_equal orig_file_upload_date, file_upload_date
228
223
  end
229
224
 
230
225
  def test_content_type
231
226
  ct = nil
232
- GridStore.open(@db, 'foobar', 'r') { |f| ct = f.content_type }
227
+ GridStore.open(@@db, 'foobar', 'r') { |f| ct = f.content_type }
233
228
  assert_equal GridStore::DEFAULT_CONTENT_TYPE, ct
234
229
 
235
- GridStore.open(@db, 'foobar', 'w+') { |f| f.content_type = 'text/html' }
230
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.content_type = 'text/html' }
236
231
  ct2 = nil
237
- GridStore.open(@db, 'foobar', 'r') { |f| ct2 = f.content_type }
232
+ GridStore.open(@@db, 'foobar', 'r') { |f| ct2 = f.content_type }
238
233
  assert_equal 'text/html', ct2
239
234
  end
240
235
 
241
236
  def test_content_type_option
242
- GridStore.open(@db, 'new-file', 'w', :content_type => 'image/jpg') { |f| f.write('foo') }
237
+ GridStore.open(@@db, 'new-file', 'w', :content_type => 'image/jpg') { |f| f.write('foo') }
243
238
  ct = nil
244
- GridStore.open(@db, 'new-file', 'r') { |f| ct = f.content_type }
239
+ GridStore.open(@@db, 'new-file', 'r') { |f| ct = f.content_type }
245
240
  assert_equal 'image/jpg', ct
246
241
  end
247
242
 
248
243
  def test_unknown_mode
249
- GridStore.open(@db, 'foobar', 'x')
244
+ GridStore.open(@@db, 'foobar', 'x')
250
245
  fail 'should have seen "illegal mode" error raised'
251
246
  rescue => ex
252
247
  assert_equal "error: illegal mode x", ex.to_s
253
248
  end
254
249
 
255
250
  def test_metadata
256
- GridStore.open(@db, 'foobar', 'r') { |f| assert_nil f.metadata }
257
- GridStore.open(@db, 'foobar', 'w+') { |f| f.metadata = {'a' => 1} }
258
- GridStore.open(@db, 'foobar', 'r') { |f| assert_equal({'a' => 1}, f.metadata) }
251
+ GridStore.open(@@db, 'foobar', 'r') { |f| assert_nil f.metadata }
252
+ GridStore.open(@@db, 'foobar', 'w+') { |f| f.metadata = {'a' => 1} }
253
+ GridStore.open(@@db, 'foobar', 'r') { |f| assert_equal({'a' => 1}, f.metadata) }
259
254
  end
260
255
 
261
256
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb-mongo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.2
4
+ version: 0.5.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jim Menard