mongo 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +3 -59
- data/Rakefile +7 -13
- data/bin/perf.rb +30 -0
- data/examples/cursor.rb +4 -4
- data/examples/types.rb +1 -1
- data/lib/mongo.rb +2 -2
- data/lib/mongo/admin.rb +1 -2
- data/lib/mongo/collection.rb +85 -45
- data/lib/mongo/connection.rb +55 -102
- data/lib/mongo/constants.rb +3 -3
- data/lib/mongo/cursor.rb +48 -44
- data/lib/mongo/db.rb +8 -8
- data/lib/mongo/errors.rb +8 -2
- data/lib/mongo/gridfs/chunk.rb +0 -1
- data/lib/mongo/gridfs/grid_store.rb +57 -14
- data/lib/mongo/types/code.rb +1 -0
- data/lib/mongo/types/objectid.rb +5 -6
- data/lib/mongo/util/bson_ruby.rb +25 -15
- data/lib/mongo/util/conversions.rb +12 -4
- data/lib/mongo/util/ordered_hash.rb +18 -0
- data/lib/mongo/util/server_version.rb +3 -3
- data/test/replica/count_test.rb +3 -3
- data/test/replica/insert_test.rb +6 -6
- data/test/replica/pooled_insert_test.rb +8 -8
- data/test/replica/query_test.rb +3 -3
- data/test/test_bson.rb +32 -0
- data/test/test_collection.rb +140 -65
- data/test/test_connection.rb +2 -2
- data/test/test_conversions.rb +3 -3
- data/test/test_cursor.rb +44 -20
- data/test/test_db_api.rb +7 -1
- data/test/test_grid_store.rb +16 -2
- data/test/test_objectid.rb +12 -0
- data/test/test_ordered_hash.rb +16 -0
- data/test/test_threading.rb +3 -3
- data/test/threading/test_threading_large_pool.rb +7 -7
- data/test/unit/collection_test.rb +7 -7
- data/test/unit/connection_test.rb +0 -79
- data/test/unit/cursor_test.rb +12 -12
- data/test/unit/db_test.rb +11 -11
- metadata +7 -5
- data/bin/autoreconnect.rb +0 -26
data/test/unit/cursor_test.rb
CHANGED
@@ -2,15 +2,15 @@ require 'test/test_helper'
|
|
2
2
|
|
3
3
|
class TestCursor < Test::Unit::TestCase
|
4
4
|
|
5
|
-
context "Cursor options" do
|
6
|
-
setup do
|
5
|
+
context "Cursor options" do
|
6
|
+
setup do
|
7
7
|
@connection = stub(:class => Connection)
|
8
|
-
@db = stub(:name => "testing", :slave_ok? => false, :connection => @connection)
|
8
|
+
@db = stub(:name => "testing", :slave_ok? => false, :connection => @connection)
|
9
9
|
@collection = stub(:db => @db, :name => "items")
|
10
10
|
@cursor = Cursor.new(@collection)
|
11
11
|
end
|
12
12
|
|
13
|
-
should "set admin to false" do
|
13
|
+
should "set admin to false" do
|
14
14
|
assert_equal false, @cursor.admin
|
15
15
|
|
16
16
|
@cursor = Cursor.new(@collection, :admin => true)
|
@@ -60,35 +60,35 @@ class TestCursor < Test::Unit::TestCase
|
|
60
60
|
assert_equal "name", @cursor.hint
|
61
61
|
end
|
62
62
|
|
63
|
-
should "cache full collection name" do
|
63
|
+
should "cache full collection name" do
|
64
64
|
assert_equal "testing.items", @cursor.full_collection_name
|
65
65
|
end
|
66
66
|
end
|
67
67
|
|
68
|
-
context "Query fields" do
|
69
|
-
setup do
|
68
|
+
context "Query fields" do
|
69
|
+
setup do
|
70
70
|
@connection = stub(:class => Collection)
|
71
71
|
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
|
72
72
|
@collection = stub(:db => @db, :name => "items")
|
73
73
|
end
|
74
74
|
|
75
|
-
should "when an array should return a hash with each key" do
|
75
|
+
should "when an array should return a hash with each key" do
|
76
76
|
@cursor = Cursor.new(@collection, :fields => [:name, :age])
|
77
77
|
result = @cursor.fields
|
78
78
|
assert_equal result.keys.sort{|a,b| a.to_s <=> b.to_s}, [:age, :name].sort{|a,b| a.to_s <=> b.to_s}
|
79
79
|
assert result.values.all? {|v| v == 1}
|
80
80
|
end
|
81
81
|
|
82
|
-
should "when a string, return a hash with just the key" do
|
82
|
+
should "when a string, return a hash with just the key" do
|
83
83
|
@cursor = Cursor.new(@collection, :fields => "name")
|
84
|
-
result = @cursor.fields
|
84
|
+
result = @cursor.fields
|
85
85
|
assert_equal result.keys.sort, ["name"]
|
86
86
|
assert result.values.all? {|v| v == 1}
|
87
87
|
end
|
88
88
|
|
89
|
-
should "return nil when neither hash nor string nor symbol" do
|
89
|
+
should "return nil when neither hash nor string nor symbol" do
|
90
90
|
@cursor = Cursor.new(@collection, :fields => 1234567)
|
91
|
-
assert_nil @cursor.fields
|
91
|
+
assert_nil @cursor.fields
|
92
92
|
end
|
93
93
|
end
|
94
94
|
end
|
data/test/unit/db_test.rb
CHANGED
@@ -11,8 +11,8 @@ class DBTest < Test::Unit::TestCase
|
|
11
11
|
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
12
12
|
end
|
13
13
|
|
14
|
-
context "DB commands" do
|
15
|
-
setup do
|
14
|
+
context "DB commands" do
|
15
|
+
setup do
|
16
16
|
@conn = stub()
|
17
17
|
@db = DB.new("testing", @conn)
|
18
18
|
@collection = mock()
|
@@ -20,30 +20,30 @@ class DBTest < Test::Unit::TestCase
|
|
20
20
|
end
|
21
21
|
|
22
22
|
should "raise an error if given a hash with more than one key" do
|
23
|
-
assert_raise MongoArgumentError do
|
23
|
+
assert_raise MongoArgumentError do
|
24
24
|
@db.command(:buildinfo => 1, :somekey => 1)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
28
|
-
should "raise an error if the selector is omitted" do
|
29
|
-
assert_raise MongoArgumentError do
|
28
|
+
should "raise an error if the selector is omitted" do
|
29
|
+
assert_raise MongoArgumentError do
|
30
30
|
@db.command({}, true)
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
34
|
-
should "create the proper cursor" do
|
35
|
-
@cursor = mock(:
|
34
|
+
should "create the proper cursor" do
|
35
|
+
@cursor = mock(:next_document => {"ok" => 1})
|
36
36
|
Cursor.expects(:new).with(@collection, :admin => true,
|
37
37
|
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
38
38
|
command = {:buildinfo => 1}
|
39
39
|
@db.command(command, true)
|
40
40
|
end
|
41
41
|
|
42
|
-
should "raise an error when the command fails" do
|
43
|
-
@cursor = mock(:
|
42
|
+
should "raise an error when the command fails" do
|
43
|
+
@cursor = mock(:next_document => {"ok" => 0})
|
44
44
|
Cursor.expects(:new).with(@collection, :admin => true,
|
45
45
|
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
46
|
-
assert_raise OperationFailure do
|
46
|
+
assert_raise OperationFailure do
|
47
47
|
command = {:buildinfo => 1}
|
48
48
|
@db.command(command, true, true)
|
49
49
|
end
|
@@ -51,4 +51,4 @@ class DBTest < Test::Unit::TestCase
|
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
54
|
-
|
54
|
+
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mongo
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jim Menard
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2009-12-
|
13
|
+
date: 2009-12-29 00:00:00 -05:00
|
14
14
|
default_executable:
|
15
15
|
dependencies: []
|
16
16
|
|
@@ -63,11 +63,13 @@ files:
|
|
63
63
|
- examples/simple.rb
|
64
64
|
- examples/strict.rb
|
65
65
|
- examples/types.rb
|
66
|
-
- bin/autoreconnect.rb
|
67
66
|
- bin/bson_benchmark.rb
|
68
67
|
- bin/fail_if_no_c.rb
|
68
|
+
- bin/perf.rb
|
69
69
|
has_rdoc: true
|
70
70
|
homepage: http://www.mongodb.org
|
71
|
+
licenses: []
|
72
|
+
|
71
73
|
post_install_message:
|
72
74
|
rdoc_options:
|
73
75
|
- --main
|
@@ -90,9 +92,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
90
92
|
requirements: []
|
91
93
|
|
92
94
|
rubyforge_project:
|
93
|
-
rubygems_version: 1.3.
|
95
|
+
rubygems_version: 1.3.5
|
94
96
|
signing_key:
|
95
|
-
specification_version:
|
97
|
+
specification_version: 3
|
96
98
|
summary: Ruby driver for the MongoDB
|
97
99
|
test_files:
|
98
100
|
- test/mongo-qa/_common.rb
|
data/bin/autoreconnect.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib')
|
2
|
-
require 'mongo'
|
3
|
-
|
4
|
-
db = Mongo::Connection.new({:left => ["localhost", 27017], :right => ["localhost", 27018]}, nil, :auto_reconnect => true).db("ruby_test")
|
5
|
-
|
6
|
-
db['test'].clear
|
7
|
-
10.times do |i|
|
8
|
-
db['test'].save("x" => i)
|
9
|
-
end
|
10
|
-
|
11
|
-
while true do
|
12
|
-
begin
|
13
|
-
exit() if not db['test'].count() == 10
|
14
|
-
|
15
|
-
x = 0
|
16
|
-
db['test'].find().each do |doc|
|
17
|
-
x += doc['x']
|
18
|
-
end
|
19
|
-
exit() if not x == 45
|
20
|
-
print "."
|
21
|
-
STDOUT.flush
|
22
|
-
sleep 1
|
23
|
-
rescue
|
24
|
-
sleep 1
|
25
|
-
end
|
26
|
-
end
|