mongo-find_replace 0.18.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.
Files changed (68) hide show
  1. data/LICENSE.txt +202 -0
  2. data/README.rdoc +358 -0
  3. data/Rakefile +133 -0
  4. data/bin/bson_benchmark.rb +59 -0
  5. data/bin/fail_if_no_c.rb +11 -0
  6. data/examples/admin.rb +42 -0
  7. data/examples/capped.rb +22 -0
  8. data/examples/cursor.rb +48 -0
  9. data/examples/gridfs.rb +88 -0
  10. data/examples/index_test.rb +126 -0
  11. data/examples/info.rb +31 -0
  12. data/examples/queries.rb +70 -0
  13. data/examples/simple.rb +24 -0
  14. data/examples/strict.rb +35 -0
  15. data/examples/types.rb +36 -0
  16. data/lib/mongo.rb +61 -0
  17. data/lib/mongo/admin.rb +95 -0
  18. data/lib/mongo/collection.rb +664 -0
  19. data/lib/mongo/connection.rb +555 -0
  20. data/lib/mongo/cursor.rb +393 -0
  21. data/lib/mongo/db.rb +527 -0
  22. data/lib/mongo/exceptions.rb +60 -0
  23. data/lib/mongo/gridfs.rb +22 -0
  24. data/lib/mongo/gridfs/chunk.rb +90 -0
  25. data/lib/mongo/gridfs/grid_store.rb +555 -0
  26. data/lib/mongo/types/binary.rb +48 -0
  27. data/lib/mongo/types/code.rb +36 -0
  28. data/lib/mongo/types/dbref.rb +38 -0
  29. data/lib/mongo/types/min_max_keys.rb +58 -0
  30. data/lib/mongo/types/objectid.rb +219 -0
  31. data/lib/mongo/types/regexp_of_holding.rb +45 -0
  32. data/lib/mongo/util/bson_c.rb +18 -0
  33. data/lib/mongo/util/bson_ruby.rb +595 -0
  34. data/lib/mongo/util/byte_buffer.rb +222 -0
  35. data/lib/mongo/util/conversions.rb +97 -0
  36. data/lib/mongo/util/ordered_hash.rb +135 -0
  37. data/lib/mongo/util/server_version.rb +69 -0
  38. data/lib/mongo/util/support.rb +26 -0
  39. data/lib/mongo/util/xml_to_ruby.rb +112 -0
  40. data/mongo-ruby-driver.gemspec +28 -0
  41. data/test/replica/count_test.rb +34 -0
  42. data/test/replica/insert_test.rb +50 -0
  43. data/test/replica/pooled_insert_test.rb +54 -0
  44. data/test/replica/query_test.rb +39 -0
  45. data/test/test_admin.rb +67 -0
  46. data/test/test_bson.rb +397 -0
  47. data/test/test_byte_buffer.rb +81 -0
  48. data/test/test_chunk.rb +82 -0
  49. data/test/test_collection.rb +534 -0
  50. data/test/test_connection.rb +160 -0
  51. data/test/test_conversions.rb +120 -0
  52. data/test/test_cursor.rb +386 -0
  53. data/test/test_db.rb +254 -0
  54. data/test/test_db_api.rb +783 -0
  55. data/test/test_db_connection.rb +16 -0
  56. data/test/test_grid_store.rb +306 -0
  57. data/test/test_helper.rb +42 -0
  58. data/test/test_objectid.rb +156 -0
  59. data/test/test_ordered_hash.rb +168 -0
  60. data/test/test_round_trip.rb +114 -0
  61. data/test/test_slave_connection.rb +36 -0
  62. data/test/test_threading.rb +87 -0
  63. data/test/threading/test_threading_large_pool.rb +90 -0
  64. data/test/unit/collection_test.rb +52 -0
  65. data/test/unit/connection_test.rb +59 -0
  66. data/test/unit/cursor_test.rb +94 -0
  67. data/test/unit/db_test.rb +97 -0
  68. metadata +123 -0
@@ -0,0 +1,52 @@
1
+ require 'test/test_helper'
2
+
3
+ class ConnectionTest < Test::Unit::TestCase
4
+
5
+ context "Basic operations: " do
6
+ setup do
7
+ @logger = mock()
8
+ end
9
+
10
+ should "send update message" do
11
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
12
+ @db = @conn['testing']
13
+ @coll = @db.collection('books')
14
+ @conn.expects(:send_message).with do |op, msg, log|
15
+ op == 2001 && log.include?("db.books.update")
16
+ end
17
+ @coll.update({}, {:title => 'Moby Dick'})
18
+ end
19
+
20
+ should "send insert message" do
21
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
22
+ @db = @conn['testing']
23
+ @coll = @db.collection('books')
24
+ @conn.expects(:send_message).with do |op, msg, log|
25
+ op == 2002 && log.include?("db.books.insert")
26
+ end
27
+ @coll.insert({:title => 'Moby Dick'})
28
+ end
29
+
30
+ should "send safe update message" do
31
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
32
+ @db = @conn['testing']
33
+ @coll = @db.collection('books')
34
+ @conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
35
+ op == 2001 && log.include?("db.books.update")
36
+ end
37
+ @coll.update({}, {:title => 'Moby Dick'}, :safe => true)
38
+ end
39
+
40
+ should "send safe insert message" do
41
+ @conn = Connection.new('localhost', 27017, :logger => @logger, :connect => false)
42
+ @db = @conn['testing']
43
+ @coll = @db.collection('books')
44
+ @conn.expects(:send_message_with_safe_check).with do |op, msg, db_name, log|
45
+ op == 2001 && log.include?("db.books.update")
46
+ end
47
+ @coll.update({}, {:title => 'Moby Dick'}, :safe => true)
48
+ end
49
+ end
50
+ end
51
+
52
+
@@ -0,0 +1,59 @@
1
+ require 'test/test_helper'
2
+
3
+ class ConnectionTest < Test::Unit::TestCase
4
+
5
+ def new_mock_socket
6
+ socket = Object.new
7
+ socket.stubs(:setsockopt).with(Socket::IPPROTO_TCP, Socket::TCP_NODELAY, 1)
8
+ socket
9
+ end
10
+
11
+ def new_mock_db
12
+ db = Object.new
13
+ end
14
+
15
+ context "Initialization: " do
16
+
17
+ context "given a single node" do
18
+ setup do
19
+ TCPSocket.stubs(:new).returns(new_mock_socket)
20
+ @conn = Connection.new('localhost', 27017, :connect => false)
21
+
22
+ admin_db = new_mock_db
23
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
24
+ @conn.expects(:[]).with('admin').returns(admin_db)
25
+ @conn.connect_to_master
26
+ end
27
+
28
+ should "set localhost and port to master" do
29
+ assert_equal 'localhost', @conn.host
30
+ assert_equal 27017, @conn.port
31
+ end
32
+
33
+ should "set connection pool to 1" do
34
+ assert_equal 1, @conn.size
35
+ end
36
+
37
+ should "default slave_ok to false" do
38
+ assert !@conn.slave_ok?
39
+ end
40
+ end
41
+ end
42
+
43
+ context "with a nonstandard port" do
44
+ setup do
45
+ TCPSocket.stubs(:new).returns(new_mock_socket)
46
+ @conn = Connection.new('255.255.255.255', 2500, :connect => false)
47
+ admin_db = new_mock_db
48
+ admin_db.expects(:command).returns({'ok' => 1, 'ismaster' => 1})
49
+ @conn.expects(:[]).with('admin').returns(admin_db)
50
+ @conn.connect_to_master
51
+ end
52
+
53
+ should "set localhost and port correctly" do
54
+ assert_equal '255.255.255.255', @conn.host
55
+ assert_equal 2500, @conn.port
56
+ end
57
+ end
58
+ end
59
+
@@ -0,0 +1,94 @@
1
+ require 'test/test_helper'
2
+
3
+ class TestCursor < Test::Unit::TestCase
4
+
5
+ context "Cursor options" do
6
+ setup do
7
+ @connection = stub(:class => Connection)
8
+ @db = stub(:name => "testing", :slave_ok? => false, :connection => @connection)
9
+ @collection = stub(:db => @db, :name => "items")
10
+ @cursor = Cursor.new(@collection)
11
+ end
12
+
13
+ should "set admin to false" do
14
+ assert_equal false, @cursor.admin
15
+
16
+ @cursor = Cursor.new(@collection, :admin => true)
17
+ assert_equal true, @cursor.admin
18
+ end
19
+
20
+ should "set selector" do
21
+ assert @cursor.selector == {}
22
+
23
+ @cursor = Cursor.new(@collection, :selector => {:name => "Jones"})
24
+ assert @cursor.selector == {:name => "Jones"}
25
+ end
26
+
27
+ should "set fields" do
28
+ assert_nil @cursor.fields
29
+
30
+ @cursor = Cursor.new(@collection, :fields => [:name, :date])
31
+ assert @cursor.fields == {:name => 1, :date => 1}
32
+ end
33
+
34
+ should "set limit" do
35
+ assert_equal 0, @cursor.limit
36
+
37
+ @cursor = Cursor.new(@collection, :limit => 10)
38
+ assert_equal 10, @cursor.limit
39
+ end
40
+
41
+
42
+ should "set skip" do
43
+ assert_equal 0, @cursor.skip
44
+
45
+ @cursor = Cursor.new(@collection, :skip => 5)
46
+ assert_equal 5, @cursor.skip
47
+ end
48
+
49
+ should "set sort order" do
50
+ assert_nil @cursor.order
51
+
52
+ @cursor = Cursor.new(@collection, :order => "last_name")
53
+ assert_equal "last_name", @cursor.order
54
+ end
55
+
56
+ should "set hint" do
57
+ assert_nil @cursor.hint
58
+
59
+ @cursor = Cursor.new(@collection, :hint => "name")
60
+ assert_equal "name", @cursor.hint
61
+ end
62
+
63
+ should "cache full collection name" do
64
+ assert_equal "testing.items", @cursor.full_collection_name
65
+ end
66
+ end
67
+
68
+ context "Query fields" do
69
+ setup do
70
+ @connection = stub(:class => Collection)
71
+ @db = stub(:slave_ok? => true, :name => "testing", :connection => @connection)
72
+ @collection = stub(:db => @db, :name => "items")
73
+ end
74
+
75
+ should "when an array should return a hash with each key" do
76
+ @cursor = Cursor.new(@collection, :fields => [:name, :age])
77
+ result = @cursor.fields
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
+ assert result.values.all? {|v| v == 1}
80
+ end
81
+
82
+ should "when a string, return a hash with just the key" do
83
+ @cursor = Cursor.new(@collection, :fields => "name")
84
+ result = @cursor.fields
85
+ assert_equal result.keys.sort, ["name"]
86
+ assert result.values.all? {|v| v == 1}
87
+ end
88
+
89
+ should "return nil when neither hash nor string nor symbol" do
90
+ @cursor = Cursor.new(@collection, :fields => 1234567)
91
+ assert_nil @cursor.fields
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,97 @@
1
+ require 'test/test_helper'
2
+
3
+ class DBTest < Test::Unit::TestCase
4
+
5
+ def insert_message(db, documents)
6
+ documents = [documents] unless documents.is_a?(Array)
7
+ message = ByteBuffer.new
8
+ message.put_int(0)
9
+ BSON.serialize_cstr(message, "#{db.name}.test")
10
+ documents.each { |doc| message.put_array(BSON.new.serialize(doc, true).to_a) }
11
+ message = db.add_message_headers(Mongo::Constants::OP_INSERT, message)
12
+ end
13
+
14
+ context "DB commands" do
15
+ setup do
16
+ @conn = stub()
17
+ @db = DB.new("testing", @conn)
18
+ @collection = mock()
19
+ @db.stubs(:system_command_collection).returns(@collection)
20
+ end
21
+
22
+ should "raise an error if given a hash with more than one key" do
23
+ assert_raise MongoArgumentError do
24
+ @db.command(:buildinfo => 1, :somekey => 1)
25
+ end
26
+ end
27
+
28
+ should "raise an error if the selector is omitted" do
29
+ assert_raise MongoArgumentError do
30
+ @db.command({}, true)
31
+ end
32
+ end
33
+
34
+ should "create the proper cursor" do
35
+ @cursor = mock(:next_document => {"ok" => 1})
36
+ Cursor.expects(:new).with(@collection, :admin => true,
37
+ :limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
38
+ command = {:buildinfo => 1}
39
+ @db.command(command, true)
40
+ end
41
+
42
+ should "raise an error when the command fails" do
43
+ @cursor = mock(:next_document => {"ok" => 0})
44
+ Cursor.expects(:new).with(@collection, :admin => true,
45
+ :limit => -1, :selector => {:buildinfo => 1}, :socket => nil).returns(@cursor)
46
+ assert_raise OperationFailure do
47
+ command = {:buildinfo => 1}
48
+ @db.command(command, true, true)
49
+ end
50
+ end
51
+
52
+ should "raise an error if logging out fails" do
53
+ @db.expects(:command).returns({})
54
+ assert_raise MongoDBError do
55
+ @db.logout
56
+ end
57
+ end
58
+
59
+ should "raise an error if collection creation fails" do
60
+ @db.expects(:collection_names).returns([])
61
+ @db.expects(:command).returns({})
62
+ assert_raise MongoDBError do
63
+ @db.create_collection("foo")
64
+ end
65
+ end
66
+
67
+ should "raise an error if getlasterror fails" do
68
+ @db.expects(:command).returns({})
69
+ assert_raise MongoDBError do
70
+ @db.error
71
+ end
72
+ end
73
+
74
+ should "raise an error if rename fails" do
75
+ @db.expects(:command).returns({})
76
+ assert_raise MongoDBError do
77
+ @db.rename_collection("foo", "bar")
78
+ end
79
+ end
80
+
81
+ should "raise an error if drop_index fails" do
82
+ @db.expects(:command).returns({})
83
+ assert_raise MongoDBError do
84
+ @db.drop_index("foo", "bar")
85
+ end
86
+ end
87
+
88
+ should "raise an error if set_profiling_level fails" do
89
+ @db.expects(:command).returns({})
90
+ assert_raise MongoDBError do
91
+ @db.profiling_level = :slow_only
92
+ end
93
+ end
94
+ end
95
+ end
96
+
97
+
metadata ADDED
@@ -0,0 +1,123 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: mongo-find_replace
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.18.3
5
+ platform: ruby
6
+ authors:
7
+ - Jim Menard
8
+ - Mike Dirolf
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2010-01-28 00:00:00 +02: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/gridfs/chunk.rb
31
+ - lib/mongo/gridfs/grid_store.rb
32
+ - lib/mongo/exceptions.rb
33
+ - lib/mongo/cursor.rb
34
+ - lib/mongo/types/objectid.rb
35
+ - lib/mongo/types/min_max_keys.rb
36
+ - lib/mongo/types/dbref.rb
37
+ - lib/mongo/types/code.rb
38
+ - lib/mongo/types/regexp_of_holding.rb
39
+ - lib/mongo/types/binary.rb
40
+ - lib/mongo/connection.rb
41
+ - lib/mongo/util/bson_c.rb
42
+ - lib/mongo/util/xml_to_ruby.rb
43
+ - lib/mongo/util/support.rb
44
+ - lib/mongo/util/byte_buffer.rb
45
+ - lib/mongo/util/server_version.rb
46
+ - lib/mongo/util/conversions.rb
47
+ - lib/mongo/util/bson_ruby.rb
48
+ - lib/mongo/util/ordered_hash.rb
49
+ - lib/mongo/collection.rb
50
+ - lib/mongo/db.rb
51
+ - lib/mongo/admin.rb
52
+ - lib/mongo/gridfs.rb
53
+ - lib/mongo.rb
54
+ - examples/types.rb
55
+ - examples/info.rb
56
+ - examples/cursor.rb
57
+ - examples/simple.rb
58
+ - examples/index_test.rb
59
+ - examples/capped.rb
60
+ - examples/queries.rb
61
+ - examples/admin.rb
62
+ - examples/strict.rb
63
+ - examples/gridfs.rb
64
+ - bin/bson_benchmark.rb
65
+ - bin/fail_if_no_c.rb
66
+ has_rdoc: true
67
+ homepage: http://www.mongodb.org
68
+ licenses: []
69
+
70
+ post_install_message:
71
+ rdoc_options:
72
+ - --main
73
+ - README.rdoc
74
+ - --inline-source
75
+ require_paths:
76
+ - lib
77
+ required_ruby_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ version: "0"
82
+ version:
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: "0"
88
+ version:
89
+ requirements: []
90
+
91
+ rubyforge_project:
92
+ rubygems_version: 1.3.5
93
+ signing_key:
94
+ specification_version: 3
95
+ summary: Ruby driver for the MongoDB implementing find_replace mongo 1.3.0 feature
96
+ test_files:
97
+ - test/test_slave_connection.rb
98
+ - test/test_helper.rb
99
+ - test/test_bson.rb
100
+ - test/test_db_api.rb
101
+ - test/test_grid_store.rb
102
+ - test/test_cursor.rb
103
+ - test/test_objectid.rb
104
+ - test/test_connection.rb
105
+ - test/test_round_trip.rb
106
+ - test/replica/insert_test.rb
107
+ - test/replica/count_test.rb
108
+ - test/replica/query_test.rb
109
+ - test/replica/pooled_insert_test.rb
110
+ - test/test_chunk.rb
111
+ - test/test_db_connection.rb
112
+ - test/test_conversions.rb
113
+ - test/test_threading.rb
114
+ - test/test_ordered_hash.rb
115
+ - test/unit/db_test.rb
116
+ - test/unit/cursor_test.rb
117
+ - test/unit/connection_test.rb
118
+ - test/unit/collection_test.rb
119
+ - test/test_collection.rb
120
+ - test/test_admin.rb
121
+ - test/test_byte_buffer.rb
122
+ - test/test_db.rb
123
+ - test/threading/test_threading_large_pool.rb