kbaum-mongo 0.18.3p
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE.txt +202 -0
- data/README.rdoc +339 -0
- data/Rakefile +138 -0
- data/bin/bson_benchmark.rb +59 -0
- data/bin/fail_if_no_c.rb +11 -0
- data/examples/admin.rb +42 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +88 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +70 -0
- data/examples/simple.rb +24 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/lib/mongo/collection.rb +609 -0
- data/lib/mongo/connection.rb +672 -0
- data/lib/mongo/cursor.rb +403 -0
- data/lib/mongo/db.rb +555 -0
- data/lib/mongo/exceptions.rb +66 -0
- data/lib/mongo/gridfs/chunk.rb +91 -0
- data/lib/mongo/gridfs/grid.rb +79 -0
- data/lib/mongo/gridfs/grid_file_system.rb +101 -0
- data/lib/mongo/gridfs/grid_io.rb +338 -0
- data/lib/mongo/gridfs/grid_store.rb +580 -0
- data/lib/mongo/gridfs.rb +25 -0
- data/lib/mongo/types/binary.rb +52 -0
- data/lib/mongo/types/code.rb +36 -0
- data/lib/mongo/types/dbref.rb +40 -0
- data/lib/mongo/types/min_max_keys.rb +58 -0
- data/lib/mongo/types/objectid.rb +180 -0
- data/lib/mongo/types/regexp_of_holding.rb +45 -0
- data/lib/mongo/util/bson_c.rb +18 -0
- data/lib/mongo/util/bson_ruby.rb +606 -0
- data/lib/mongo/util/byte_buffer.rb +222 -0
- data/lib/mongo/util/conversions.rb +87 -0
- data/lib/mongo/util/ordered_hash.rb +140 -0
- data/lib/mongo/util/server_version.rb +69 -0
- data/lib/mongo/util/support.rb +26 -0
- data/lib/mongo.rb +63 -0
- data/mongo-ruby-driver.gemspec +28 -0
- data/test/auxillary/autoreconnect_test.rb +42 -0
- data/test/binary_test.rb +15 -0
- data/test/bson_test.rb +427 -0
- data/test/byte_buffer_test.rb +81 -0
- data/test/chunk_test.rb +82 -0
- data/test/collection_test.rb +515 -0
- data/test/connection_test.rb +160 -0
- data/test/conversions_test.rb +120 -0
- data/test/cursor_test.rb +379 -0
- data/test/db_api_test.rb +780 -0
- data/test/db_connection_test.rb +16 -0
- data/test/db_test.rb +272 -0
- data/test/grid_file_system_test.rb +210 -0
- data/test/grid_io_test.rb +78 -0
- data/test/grid_store_test.rb +334 -0
- data/test/grid_test.rb +87 -0
- data/test/objectid_test.rb +125 -0
- data/test/ordered_hash_test.rb +172 -0
- data/test/replica/count_test.rb +34 -0
- data/test/replica/insert_test.rb +50 -0
- data/test/replica/pooled_insert_test.rb +54 -0
- data/test/replica/query_test.rb +39 -0
- data/test/slave_connection_test.rb +36 -0
- data/test/test_helper.rb +42 -0
- data/test/threading/test_threading_large_pool.rb +90 -0
- data/test/threading_test.rb +87 -0
- data/test/unit/collection_test.rb +61 -0
- data/test/unit/connection_test.rb +117 -0
- data/test/unit/cursor_test.rb +93 -0
- data/test/unit/db_test.rb +98 -0
- metadata +127 -0
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class CursorTest < Test::Unit::TestCase
|
4
|
+
context "Cursor options" do
|
5
|
+
setup do
|
6
|
+
@connection = stub(:class => Connection)
|
7
|
+
@db = stub(:name => "testing", :slave_ok? => false, :connection => @connection)
|
8
|
+
@collection = stub(:db => @db, :name => "items")
|
9
|
+
@cursor = Cursor.new(@collection)
|
10
|
+
end
|
11
|
+
|
12
|
+
should "set admin to false" do
|
13
|
+
assert_equal false, @cursor.admin
|
14
|
+
|
15
|
+
@cursor = Cursor.new(@collection, :admin => true)
|
16
|
+
assert_equal true, @cursor.admin
|
17
|
+
end
|
18
|
+
|
19
|
+
should "set selector" do
|
20
|
+
assert @cursor.selector == {}
|
21
|
+
|
22
|
+
@cursor = Cursor.new(@collection, :selector => {:name => "Jones"})
|
23
|
+
assert @cursor.selector == {:name => "Jones"}
|
24
|
+
end
|
25
|
+
|
26
|
+
should "set fields" do
|
27
|
+
assert_nil @cursor.fields
|
28
|
+
|
29
|
+
@cursor = Cursor.new(@collection, :fields => [:name, :date])
|
30
|
+
assert @cursor.fields == {:name => 1, :date => 1}
|
31
|
+
end
|
32
|
+
|
33
|
+
should "set limit" do
|
34
|
+
assert_equal 0, @cursor.limit
|
35
|
+
|
36
|
+
@cursor = Cursor.new(@collection, :limit => 10)
|
37
|
+
assert_equal 10, @cursor.limit
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
should "set skip" do
|
42
|
+
assert_equal 0, @cursor.skip
|
43
|
+
|
44
|
+
@cursor = Cursor.new(@collection, :skip => 5)
|
45
|
+
assert_equal 5, @cursor.skip
|
46
|
+
end
|
47
|
+
|
48
|
+
should "set sort order" do
|
49
|
+
assert_nil @cursor.order
|
50
|
+
|
51
|
+
@cursor = Cursor.new(@collection, :order => "last_name")
|
52
|
+
assert_equal "last_name", @cursor.order
|
53
|
+
end
|
54
|
+
|
55
|
+
should "set hint" do
|
56
|
+
assert_nil @cursor.hint
|
57
|
+
|
58
|
+
@cursor = Cursor.new(@collection, :hint => "name")
|
59
|
+
assert_equal "name", @cursor.hint
|
60
|
+
end
|
61
|
+
|
62
|
+
should "cache full collection name" do
|
63
|
+
assert_equal "testing.items", @cursor.full_collection_name
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
context "Query fields" do
|
68
|
+
setup do
|
69
|
+
@connection = stub(:class => Collection)
|
70
|
+
@db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
|
71
|
+
@collection = stub(:db => @db, :name => "items")
|
72
|
+
end
|
73
|
+
|
74
|
+
should "when an array should return a hash with each key" do
|
75
|
+
@cursor = Cursor.new(@collection, :fields => [:name, :age])
|
76
|
+
result = @cursor.fields
|
77
|
+
assert_equal result.keys.sort{|a,b| a.to_s <=> b.to_s}, [:age, :name].sort{|a,b| a.to_s <=> b.to_s}
|
78
|
+
assert result.values.all? {|v| v == 1}
|
79
|
+
end
|
80
|
+
|
81
|
+
should "when a string, return a hash with just the key" do
|
82
|
+
@cursor = Cursor.new(@collection, :fields => "name")
|
83
|
+
result = @cursor.fields
|
84
|
+
assert_equal result.keys.sort, ["name"]
|
85
|
+
assert result.values.all? {|v| v == 1}
|
86
|
+
end
|
87
|
+
|
88
|
+
should "return nil when neither hash nor string nor symbol" do
|
89
|
+
@cursor = Cursor.new(@collection, :fields => 1234567)
|
90
|
+
assert_nil @cursor.fields
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class DBTest < Test::Unit::TestCase
|
4
|
+
context "DBTest: " do
|
5
|
+
setup do
|
6
|
+
def insert_message(db, documents)
|
7
|
+
documents = [documents] unless documents.is_a?(Array)
|
8
|
+
message = ByteBuffer.new
|
9
|
+
message.put_int(0)
|
10
|
+
BSON.serialize_cstr(message, "#{db.name}.test")
|
11
|
+
documents.each { |doc| message.put_array(BSON.new.serialize(doc, true).to_a) }
|
12
|
+
message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
context "DB commands" do
|
17
|
+
setup do
|
18
|
+
@conn = stub()
|
19
|
+
@db = DB.new("testing", @conn)
|
20
|
+
@collection = mock()
|
21
|
+
@db.stubs(:system_command_collection).returns(@collection)
|
22
|
+
end
|
23
|
+
|
24
|
+
should "raise an error if given a hash with more than one key" do
|
25
|
+
assert_raise MongoArgumentError do
|
26
|
+
@db.command(:buildinfo => 1, :somekey => 1)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
should "raise an error if the selector is omitted" do
|
31
|
+
assert_raise MongoArgumentError do
|
32
|
+
@db.command({}, true)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
should "create the proper cursor" do
|
37
|
+
@cursor = mock(:next_document => {"ok" => 1})
|
38
|
+
Cursor.expects(:new).with(@collection, :admin => true,
|
39
|
+
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
40
|
+
command = {:buildinfo => 1}
|
41
|
+
@db.command(command, true)
|
42
|
+
end
|
43
|
+
|
44
|
+
should "raise an error when the command fails" do
|
45
|
+
@cursor = mock(:next_document => {"ok" => 0})
|
46
|
+
Cursor.expects(:new).with(@collection, :admin => true,
|
47
|
+
:limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
|
48
|
+
assert_raise OperationFailure do
|
49
|
+
command = {:buildinfo => 1}
|
50
|
+
@db.command(command, true, true)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
should "raise an error if logging out fails" do
|
55
|
+
@db.expects(:command).returns({})
|
56
|
+
assert_raise MongoDBError do
|
57
|
+
@db.logout
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
should "raise an error if collection creation fails" do
|
62
|
+
@db.expects(:collection_names).returns([])
|
63
|
+
@db.expects(:command).returns({})
|
64
|
+
assert_raise MongoDBError do
|
65
|
+
@db.create_collection("foo")
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
should "raise an error if getlasterror fails" do
|
70
|
+
@db.expects(:command).returns({})
|
71
|
+
assert_raise MongoDBError do
|
72
|
+
@db.error
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
should "raise an error if rename fails" do
|
77
|
+
@db.expects(:command).returns({})
|
78
|
+
assert_raise MongoDBError do
|
79
|
+
@db.rename_collection("foo", "bar")
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
should "raise an error if drop_index fails" do
|
84
|
+
@db.expects(:command).returns({})
|
85
|
+
assert_raise MongoDBError do
|
86
|
+
@db.drop_index("foo", "bar")
|
87
|
+
end
|
88
|
+
end
|
89
|
+
|
90
|
+
should "raise an error if set_profiling_level fails" do
|
91
|
+
@db.expects(:command).returns({})
|
92
|
+
assert_raise MongoDBError do
|
93
|
+
@db.profiling_level = :slow_only
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
metadata
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kbaum-mongo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.18.3p
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Menard
|
8
|
+
- Mike Dirolf
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2010-02-24 00:00:00 -08:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.
|
18
|
+
email: mongodb-dev@googlegroups.com
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- README.rdoc
|
27
|
+
- Rakefile
|
28
|
+
- mongo-ruby-driver.gemspec
|
29
|
+
- LICENSE.txt
|
30
|
+
- lib/mongo/util/byte_buffer.rb
|
31
|
+
- lib/mongo/util/server_version.rb
|
32
|
+
- lib/mongo/util/bson_ruby.rb
|
33
|
+
- lib/mongo/util/bson_c.rb
|
34
|
+
- lib/mongo/util/ordered_hash.rb
|
35
|
+
- lib/mongo/util/conversions.rb
|
36
|
+
- lib/mongo/util/support.rb
|
37
|
+
- lib/mongo/db.rb
|
38
|
+
- lib/mongo/types/binary.rb
|
39
|
+
- lib/mongo/types/code.rb
|
40
|
+
- lib/mongo/types/dbref.rb
|
41
|
+
- lib/mongo/types/objectid.rb
|
42
|
+
- lib/mongo/types/min_max_keys.rb
|
43
|
+
- lib/mongo/types/regexp_of_holding.rb
|
44
|
+
- lib/mongo/exceptions.rb
|
45
|
+
- lib/mongo/gridfs/grid_store.rb
|
46
|
+
- lib/mongo/gridfs/chunk.rb
|
47
|
+
- lib/mongo/gridfs/grid_file_system.rb
|
48
|
+
- lib/mongo/gridfs/grid.rb
|
49
|
+
- lib/mongo/gridfs/grid_io.rb
|
50
|
+
- lib/mongo/connection.rb
|
51
|
+
- lib/mongo/collection.rb
|
52
|
+
- lib/mongo/gridfs.rb
|
53
|
+
- lib/mongo/cursor.rb
|
54
|
+
- lib/mongo.rb
|
55
|
+
- examples/strict.rb
|
56
|
+
- examples/types.rb
|
57
|
+
- examples/capped.rb
|
58
|
+
- examples/gridfs.rb
|
59
|
+
- examples/index_test.rb
|
60
|
+
- examples/cursor.rb
|
61
|
+
- examples/admin.rb
|
62
|
+
- examples/simple.rb
|
63
|
+
- examples/queries.rb
|
64
|
+
- examples/info.rb
|
65
|
+
- bin/fail_if_no_c.rb
|
66
|
+
- bin/bson_benchmark.rb
|
67
|
+
has_rdoc: true
|
68
|
+
homepage: http://www.mongodb.org
|
69
|
+
licenses: []
|
70
|
+
|
71
|
+
post_install_message:
|
72
|
+
rdoc_options:
|
73
|
+
- --main
|
74
|
+
- README.rdoc
|
75
|
+
- --inline-source
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: "0"
|
83
|
+
version:
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">"
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: 1.3.1
|
89
|
+
version:
|
90
|
+
requirements: []
|
91
|
+
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.3.5
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Ruby driver for the MongoDB
|
97
|
+
test_files:
|
98
|
+
- test/unit/connection_test.rb
|
99
|
+
- test/unit/db_test.rb
|
100
|
+
- test/unit/collection_test.rb
|
101
|
+
- test/unit/cursor_test.rb
|
102
|
+
- test/grid_test.rb
|
103
|
+
- test/replica/insert_test.rb
|
104
|
+
- test/replica/query_test.rb
|
105
|
+
- test/replica/pooled_insert_test.rb
|
106
|
+
- test/replica/count_test.rb
|
107
|
+
- test/grid_store_test.rb
|
108
|
+
- test/connection_test.rb
|
109
|
+
- test/objectid_test.rb
|
110
|
+
- test/db_test.rb
|
111
|
+
- test/threading_test.rb
|
112
|
+
- test/auxillary/autoreconnect_test.rb
|
113
|
+
- test/threading/test_threading_large_pool.rb
|
114
|
+
- test/grid_file_system_test.rb
|
115
|
+
- test/conversions_test.rb
|
116
|
+
- test/collection_test.rb
|
117
|
+
- test/bson_test.rb
|
118
|
+
- test/byte_buffer_test.rb
|
119
|
+
- test/chunk_test.rb
|
120
|
+
- test/cursor_test.rb
|
121
|
+
- test/db_connection_test.rb
|
122
|
+
- test/db_api_test.rb
|
123
|
+
- test/binary_test.rb
|
124
|
+
- test/test_helper.rb
|
125
|
+
- test/slave_connection_test.rb
|
126
|
+
- test/grid_io_test.rb
|
127
|
+
- test/ordered_hash_test.rb
|