mongo 1.7.1 → 1.8.0
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/{LICENSE.txt → LICENSE} +0 -0
- data/README.md +124 -111
- data/Rakefile +9 -325
- data/VERSION +1 -0
- data/bin/mongo_console +4 -4
- data/examples/admin.rb +43 -0
- data/examples/capped.rb +22 -0
- data/examples/cursor.rb +48 -0
- data/examples/gridfs.rb +44 -0
- data/examples/index_test.rb +126 -0
- data/examples/info.rb +31 -0
- data/examples/queries.rb +74 -0
- data/examples/replica_set.rb +26 -0
- data/examples/simple.rb +25 -0
- data/examples/strict.rb +35 -0
- data/examples/types.rb +36 -0
- data/{test/load → examples/web}/thin/load.rb +3 -1
- data/{test/load → examples/web}/unicorn/load.rb +5 -3
- data/lib/mongo.rb +8 -10
- data/lib/mongo/collection.rb +134 -114
- data/lib/mongo/cursor.rb +21 -14
- data/lib/mongo/db.rb +30 -28
- data/lib/mongo/exceptions.rb +1 -1
- data/lib/mongo/gridfs/grid.rb +8 -7
- data/lib/mongo/gridfs/grid_ext.rb +1 -1
- data/lib/mongo/gridfs/grid_file_system.rb +6 -5
- data/lib/mongo/gridfs/grid_io.rb +22 -19
- data/lib/mongo/legacy.rb +82 -0
- data/lib/mongo/{connection.rb → mongo_client.rb} +82 -61
- data/lib/mongo/{repl_set_connection.rb → mongo_replica_set_client.rb} +54 -39
- data/lib/mongo/{sharded_connection.rb → mongo_sharded_client.rb} +9 -9
- data/lib/mongo/networking.rb +25 -20
- data/lib/mongo/util/conversions.rb +1 -1
- data/lib/mongo/util/core_ext.rb +1 -1
- data/lib/mongo/util/logging.rb +20 -4
- data/lib/mongo/util/node.rb +16 -16
- data/lib/mongo/util/pool.rb +56 -27
- data/lib/mongo/util/pool_manager.rb +28 -27
- data/lib/mongo/util/server_version.rb +1 -1
- data/lib/mongo/util/sharding_pool_manager.rb +8 -8
- data/lib/mongo/util/ssl_socket.rb +1 -5
- data/lib/mongo/util/support.rb +24 -8
- data/lib/mongo/util/tcp_socket.rb +0 -4
- data/lib/mongo/util/uri_parser.rb +54 -38
- data/lib/mongo/util/write_concern.rb +67 -0
- data/mongo.gemspec +21 -32
- data/test/auxillary/{1.4_features.rb → 1.4_feature_test.rb} +4 -5
- data/test/auxillary/authentication_test.rb +18 -20
- data/test/auxillary/autoreconnect_test.rb +3 -5
- data/test/auxillary/fork_test.rb +5 -7
- data/test/auxillary/repl_set_auth_test.rb +13 -15
- data/test/auxillary/slave_connection_test.rb +8 -7
- data/test/auxillary/threaded_authentication_test.rb +15 -17
- data/test/bson/binary_test.rb +1 -1
- data/test/bson/bson_test.rb +60 -36
- data/test/bson/byte_buffer_test.rb +1 -1
- data/test/bson/hash_with_indifferent_access_test.rb +2 -2
- data/test/bson/json_test.rb +1 -2
- data/test/bson/object_id_test.rb +1 -2
- data/test/bson/ordered_hash_test.rb +1 -1
- data/test/bson/timestamp_test.rb +1 -1
- data/test/{collection_test.rb → functional/collection_test.rb} +57 -57
- data/test/{connection_test.rb → functional/connection_test.rb} +75 -89
- data/test/{conversions_test.rb → functional/conversions_test.rb} +1 -1
- data/test/{cursor_fail_test.rb → functional/cursor_fail_test.rb} +3 -29
- data/test/{cursor_message_test.rb → functional/cursor_message_test.rb} +1 -1
- data/test/{cursor_test.rb → functional/cursor_test.rb} +5 -1
- data/test/{db_api_test.rb → functional/db_api_test.rb} +8 -9
- data/test/{db_connection_test.rb → functional/db_connection_test.rb} +3 -5
- data/test/{db_test.rb → functional/db_test.rb} +13 -13
- data/test/{grid_file_system_test.rb → functional/grid_file_system_test.rb} +2 -2
- data/test/{grid_io_test.rb → functional/grid_io_test.rb} +6 -6
- data/test/{grid_test.rb → functional/grid_test.rb} +4 -10
- data/test/{pool_test.rb → functional/pool_test.rb} +1 -1
- data/test/functional/safe_test.rb +84 -0
- data/test/{support_test.rb → functional/support_test.rb} +1 -1
- data/test/{threading_test.rb → functional/threading_test.rb} +9 -9
- data/test/{timeout_test.rb → functional/timeout_test.rb} +1 -1
- data/test/{uri_test.rb → functional/uri_test.rb} +1 -1
- data/test/functional/write_concern_test.rb +104 -0
- data/test/replica_set/basic_test.rb +139 -0
- data/test/replica_set/client_test.rb +255 -0
- data/test/replica_set/complex_connect_test.rb +62 -0
- data/test/replica_set/connection_test.rb +255 -0
- data/test/{replica_sets → replica_set}/count_test.rb +17 -14
- data/test/replica_set/cursor_test.rb +75 -0
- data/test/{replica_sets → replica_set}/insert_test.rb +19 -16
- data/test/replica_set/query_test.rb +64 -0
- data/test/replica_set/refresh_test.rb +153 -0
- data/test/{replica_sets → replica_set}/replication_ack_test.rb +21 -17
- data/test/sharded_cluster/basic_test.rb +31 -50
- data/test/support/hash_with_indifferent_access.rb +1 -1
- data/test/test_helper.rb +56 -9
- data/test/threading/threading_with_large_pool_test.rb +8 -8
- data/test/tools/mongo_config.rb +270 -58
- data/test/tools/mongo_config_test.rb +146 -0
- data/test/unit/client_test.rb +230 -0
- data/test/unit/collection_test.rb +45 -32
- data/test/unit/connection_test.rb +82 -74
- data/test/unit/cursor_test.rb +14 -6
- data/test/unit/db_test.rb +8 -8
- data/test/unit/grid_test.rb +11 -11
- data/test/unit/node_test.rb +24 -24
- data/test/unit/pool_manager_test.rb +13 -13
- data/test/unit/pool_test.rb +1 -1
- data/test/unit/read_test.rb +21 -26
- data/test/unit/safe_test.rb +52 -33
- data/test/unit/util_test.rb +55 -0
- data/test/unit/write_concern_test.rb +161 -0
- metadata +158 -171
- data/docs/CREDITS.md +0 -123
- data/docs/FAQ.md +0 -116
- data/docs/GRID_FS.md +0 -158
- data/docs/HISTORY.md +0 -392
- data/docs/READ_PREFERENCE.md +0 -99
- data/docs/RELEASES.md +0 -54
- data/docs/REPLICA_SETS.md +0 -113
- data/docs/TAILABLE_CURSORS.md +0 -51
- data/docs/TUTORIAL.md +0 -356
- data/docs/WRITE_CONCERN.md +0 -31
- data/lib/mongo/gridfs/grid_io_fix.rb +0 -38
- data/lib/mongo/version.rb +0 -3
- data/test/bson/test_helper.rb +0 -30
- data/test/replica_sets/basic_test.rb +0 -119
- data/test/replica_sets/complex_connect_test.rb +0 -57
- data/test/replica_sets/complex_read_preference_test.rb +0 -237
- data/test/replica_sets/connect_test.rb +0 -156
- data/test/replica_sets/cursor_test.rb +0 -70
- data/test/replica_sets/pooled_insert_test.rb +0 -57
- data/test/replica_sets/query_test.rb +0 -50
- data/test/replica_sets/read_preference_test.rb +0 -234
- data/test/replica_sets/refresh_test.rb +0 -156
- data/test/replica_sets/refresh_with_threads_test.rb +0 -60
- data/test/replica_sets/rs_test_helper.rb +0 -39
- data/test/safe_test.rb +0 -68
- data/test/sharded_cluster/mongo_config_test.rb +0 -126
- data/test/sharded_cluster/sc_test_helper.rb +0 -39
- data/test/tools/repl_set_manager.rb +0 -418
data/mongo.gemspec
CHANGED
@@ -1,34 +1,23 @@
|
|
1
|
-
require File.expand_path('../lib/mongo/version', __FILE__)
|
2
|
-
|
3
1
|
Gem::Specification.new do |s|
|
4
|
-
s.name
|
5
|
-
|
6
|
-
s.version
|
7
|
-
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
|
12
|
-
s.
|
13
|
-
|
14
|
-
|
15
|
-
s.files
|
16
|
-
s.files
|
17
|
-
s.files
|
18
|
-
|
19
|
-
|
20
|
-
s.executables
|
21
|
-
|
22
|
-
s.has_rdoc
|
23
|
-
|
24
|
-
|
25
|
-
s.has_rdoc = true
|
26
|
-
s.rdoc_options = ['--main', 'README.md', '--inline-source']
|
27
|
-
s.extra_rdoc_files = ['README.md']
|
28
|
-
|
29
|
-
s.authors = ['Jim Menard', 'Mike Dirolf', 'Kyle Banker', 'Tyler Brock']
|
30
|
-
s.email = 'mongodb-dev@googlegroups.com'
|
31
|
-
s.homepage = 'http://www.mongodb.org'
|
32
|
-
|
33
|
-
s.add_dependency('bson', "~> #{Mongo::VERSION}")
|
2
|
+
s.name = 'mongo'
|
3
|
+
|
4
|
+
s.version = File.read(File.join(File.dirname(__FILE__), 'VERSION'))
|
5
|
+
s.platform = Gem::Platform::RUBY
|
6
|
+
s.authors = ['Tyler Brock', 'Gary Murakami', 'Emily Stolfo', 'Brandon Black']
|
7
|
+
s.email = 'mongodb-dev@googlegroups.com'
|
8
|
+
s.homepage = 'http://www.mongodb.org'
|
9
|
+
s.summary = 'Ruby driver for MongoDB'
|
10
|
+
s.description = 'A Ruby driver for MongoDB. For more information about Mongo, see http://www.mongodb.org.'
|
11
|
+
s.rubyforge_project = 'mongo'
|
12
|
+
|
13
|
+
s.files = ['mongo.gemspec', 'LICENSE', 'VERSION']
|
14
|
+
s.files += ['README.md', 'Rakefile', 'bin/mongo_console']
|
15
|
+
s.files += ['lib/mongo.rb'] + Dir['lib/mongo/**/*.rb'] + Dir['examples/**/*.rb']
|
16
|
+
|
17
|
+
s.test_files = Dir['test/**/*.rb']
|
18
|
+
s.executables = ['mongo_console']
|
19
|
+
s.require_paths = ['lib']
|
20
|
+
s.has_rdoc = 'yard'
|
21
|
+
|
22
|
+
s.add_dependency('bson', "~> #{s.version}")
|
34
23
|
end
|
@@ -1,15 +1,14 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
require 'mongo'
|
3
|
-
|
4
|
-
require File.expand_path("../../test_helper", __FILE__)
|
3
|
+
|
5
4
|
|
6
5
|
# Demonstrate features in MongoDB 1.4
|
7
6
|
class Features14Test < Test::Unit::TestCase
|
8
7
|
|
9
8
|
context "MongoDB 1.4" do
|
10
9
|
setup do
|
11
|
-
@
|
12
|
-
@db = @
|
10
|
+
@client = MongoClient.new
|
11
|
+
@db = @client['mongo-ruby-test']
|
13
12
|
@col = @db['new-features']
|
14
13
|
end
|
15
14
|
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require File.expand_path("../../test_helper", __FILE__)
|
5
3
|
|
6
4
|
# NOTE: This test requires bouncing the server.
|
7
5
|
# It also requires that a user exists on the admin database.
|
@@ -9,17 +7,17 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
9
7
|
include Mongo
|
10
8
|
|
11
9
|
def setup
|
12
|
-
@
|
13
|
-
@db1 = @
|
14
|
-
@db2 = @
|
15
|
-
@admin = @
|
10
|
+
@client = MongoClient.new
|
11
|
+
@db1 = @client.db('mongo-ruby-test-auth1')
|
12
|
+
@db2 = @client.db('mongo-ruby-test-auth2')
|
13
|
+
@admin = @client.db('admin')
|
16
14
|
end
|
17
15
|
|
18
16
|
def teardown
|
19
17
|
@db1.authenticate('user1', 'secret')
|
20
18
|
@db2.authenticate('user2', 'secret')
|
21
|
-
@
|
22
|
-
@
|
19
|
+
@client.drop_database('mongo-ruby-test-auth1')
|
20
|
+
@client.drop_database('mongo-ruby-test-auth2')
|
23
21
|
end
|
24
22
|
|
25
23
|
def test_authenticate
|
@@ -30,18 +28,18 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
30
28
|
@admin.logout
|
31
29
|
|
32
30
|
assert_raise Mongo::OperationFailure do
|
33
|
-
@db1['stuff'].insert({:a => 2}
|
31
|
+
@db1['stuff'].insert({:a => 2})
|
34
32
|
end
|
35
33
|
|
36
34
|
assert_raise Mongo::OperationFailure do
|
37
|
-
@db2['stuff'].insert({:a => 2}
|
35
|
+
@db2['stuff'].insert({:a => 2})
|
38
36
|
end
|
39
37
|
|
40
38
|
@db1.authenticate('user1', 'secret')
|
41
39
|
@db2.authenticate('user2', 'secret')
|
42
40
|
|
43
|
-
assert @db1['stuff'].insert({:a => 2}
|
44
|
-
assert @db2['stuff'].insert({:a => 2}
|
41
|
+
assert @db1['stuff'].insert({:a => 2})
|
42
|
+
assert @db2['stuff'].insert({:a => 2})
|
45
43
|
|
46
44
|
puts "Please bounce the server."
|
47
45
|
gets
|
@@ -52,24 +50,24 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
52
50
|
rescue Mongo::ConnectionFailure
|
53
51
|
end
|
54
52
|
|
55
|
-
assert @db1['stuff'].insert({:a => 2}
|
56
|
-
assert @db2['stuff'].insert({:a => 2}
|
57
|
-
assert @db2['stuff'].find(
|
53
|
+
assert @db1['stuff'].insert({:a => 2})
|
54
|
+
assert @db2['stuff'].insert({:a => 2})
|
55
|
+
assert @db2['stuff'].find({})
|
58
56
|
|
59
57
|
@db1.logout
|
60
58
|
assert_raise Mongo::OperationFailure do
|
61
|
-
@db1['stuff'].insert({:a => 2}
|
59
|
+
@db1['stuff'].insert({:a => 2})
|
62
60
|
end
|
63
61
|
|
64
62
|
@db2.logout
|
65
63
|
assert_raise Mongo::OperationFailure do
|
66
|
-
assert @db2['stuff'].insert({:a => 2}
|
64
|
+
assert @db2['stuff'].insert({:a => 2})
|
67
65
|
end
|
68
66
|
|
69
67
|
@db2.authenticate('userRO', 'secret')
|
70
|
-
assert @db2['stuff'].find(
|
68
|
+
assert @db2['stuff'].find({})
|
71
69
|
assert_raise Mongo::OperationFailure do
|
72
|
-
assert @db2['stuff'].insert({:a => 2}
|
70
|
+
assert @db2['stuff'].insert({:a => 2})
|
73
71
|
end
|
74
72
|
end
|
75
73
|
|
@@ -1,15 +1,13 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require File.expand_path("../../test_helper", __FILE__)
|
5
3
|
|
6
4
|
# NOTE: This test requires bouncing the server
|
7
5
|
class AutoreconnectTest < Test::Unit::TestCase
|
8
6
|
include Mongo
|
9
7
|
|
10
8
|
def setup
|
11
|
-
@
|
12
|
-
@db = @
|
9
|
+
@client = MongoClient.new
|
10
|
+
@db = @client.db('mongo-ruby-test')
|
13
11
|
@db.drop_collection("test-connect")
|
14
12
|
@coll = @db.collection("test-connect")
|
15
13
|
end
|
data/test/auxillary/fork_test.rb
CHANGED
@@ -1,29 +1,27 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
require 'mongo'
|
3
|
-
require 'test/unit'
|
4
|
-
require File.expand_path("../../test_helper", __FILE__)
|
5
3
|
|
6
4
|
class ForkTest < Test::Unit::TestCase
|
7
5
|
include Mongo
|
8
6
|
|
9
7
|
def setup
|
10
|
-
@
|
8
|
+
@client = standard_connection
|
11
9
|
end
|
12
10
|
|
13
11
|
def test_fork
|
14
12
|
# Now insert some data
|
15
13
|
10.times do |n|
|
16
|
-
@
|
14
|
+
@client[MONGO_TEST_DB]['nums'].insert({:a => n})
|
17
15
|
end
|
18
16
|
|
19
17
|
# Now fork. You'll almost always see an exception here.
|
20
18
|
if !Kernel.fork
|
21
19
|
10.times do
|
22
|
-
assert @
|
20
|
+
assert @client[MONGO_TEST_DB]['nums'].find_one
|
23
21
|
end
|
24
22
|
else
|
25
23
|
10.times do
|
26
|
-
assert @
|
24
|
+
assert @client[MONGO_TEST_DB]['nums'].find_one
|
27
25
|
end
|
28
26
|
end
|
29
27
|
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
|
2
|
-
require
|
3
|
-
require './test/tools/auth_repl_set_manager'
|
4
|
-
require './test/replica_sets/rs_test_helper'
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mongo'
|
5
3
|
|
6
4
|
class AuthTest < Test::Unit::TestCase
|
7
5
|
include Mongo
|
@@ -16,35 +14,35 @@ class AuthTest < Test::Unit::TestCase
|
|
16
14
|
end
|
17
15
|
|
18
16
|
def test_repl_set_auth
|
19
|
-
@
|
17
|
+
@client = MongoReplicaSetClient.new(build_seeds(3), :name => @rs.name)
|
20
18
|
|
21
19
|
# Add an admin user
|
22
|
-
@
|
20
|
+
@client['admin'].add_user("me", "secret")
|
23
21
|
|
24
22
|
# Ensure that insert fails
|
25
23
|
assert_raise_error Mongo::OperationFailure, "unauthorized" do
|
26
|
-
@
|
24
|
+
@client['foo']['stuff'].insert({:a => 2}, {:w => 3})
|
27
25
|
end
|
28
26
|
|
29
27
|
# Then authenticate
|
30
|
-
assert @
|
28
|
+
assert @client['admin'].authenticate("me", "secret")
|
31
29
|
|
32
30
|
# Insert should succeed now
|
33
|
-
assert @
|
31
|
+
assert @client['foo']['stuff'].insert({:a => 2}, {:w => 3})
|
34
32
|
|
35
33
|
# So should a query
|
36
|
-
assert @
|
34
|
+
assert @client['foo']['stuff'].find_one
|
37
35
|
|
38
36
|
# But not when we logout
|
39
|
-
@
|
37
|
+
@client['admin'].logout
|
40
38
|
|
41
39
|
assert_raise_error Mongo::OperationFailure, "unauthorized" do
|
42
|
-
@
|
40
|
+
@client['foo']['stuff'].find_one
|
43
41
|
end
|
44
42
|
|
45
43
|
# Same should apply to a random secondary
|
46
|
-
@slave1 =
|
47
|
-
@
|
44
|
+
@slave1 = MongoClient.new(@client.secondary_pools[0].host,
|
45
|
+
@client.secondary_pools[0].port, :slave_ok => true)
|
48
46
|
|
49
47
|
# Find should fail
|
50
48
|
assert_raise_error Mongo::OperationFailure, "unauthorized" do
|
@@ -56,7 +54,7 @@ class AuthTest < Test::Unit::TestCase
|
|
56
54
|
assert @slave1['foo']['stuff'].find_one
|
57
55
|
|
58
56
|
# Same should apply when using :secondary_only
|
59
|
-
@second_only =
|
57
|
+
@second_only = MongoReplicaSetClient.new(build_seeds(3),
|
60
58
|
:require_primary => false, :read => :secondary_only)
|
61
59
|
|
62
60
|
# Find should fail
|
@@ -1,4 +1,5 @@
|
|
1
|
-
require
|
1
|
+
require 'test_helper'
|
2
|
+
require 'mongo'
|
2
3
|
|
3
4
|
# NOTE: these tests are run only if we can connect to a single MongoDB in slave mode.
|
4
5
|
class SlaveConnectionTest < Test::Unit::TestCase
|
@@ -6,8 +7,8 @@ class SlaveConnectionTest < Test::Unit::TestCase
|
|
6
7
|
|
7
8
|
def self.connect_to_slave
|
8
9
|
@@host = ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost'
|
9
|
-
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] ||
|
10
|
-
conn =
|
10
|
+
@@port = ENV['MONGO_RUBY_DRIVER_PORT'] || MongoClient::DEFAULT_PORT
|
11
|
+
conn = MongoClient.new(@@host, @@port, :slave_ok => true)
|
11
12
|
response = conn['admin'].command(:ismaster => 1)
|
12
13
|
Mongo::Support.ok?(response) && response['ismaster'] != 1
|
13
14
|
end
|
@@ -17,20 +18,20 @@ class SlaveConnectionTest < Test::Unit::TestCase
|
|
17
18
|
|
18
19
|
def test_connect_to_slave
|
19
20
|
assert_raise Mongo::ConnectionFailure do
|
20
|
-
@db =
|
21
|
+
@db = MongoClient.new(@@host, @@port, :slave_ok => false).db('ruby-mongo-demo')
|
21
22
|
end
|
22
23
|
end
|
23
24
|
|
24
25
|
def test_slave_ok_sent_to_queries
|
25
|
-
@con =
|
26
|
+
@con = MongoClient.new(@@host, @@port, :slave_ok => true)
|
26
27
|
assert_equal true, @con.slave_ok?
|
27
28
|
end
|
28
29
|
else
|
29
30
|
puts "Not connected to slave; skipping slave connection tests."
|
30
31
|
|
31
32
|
def test_slave_ok_false_on_queries
|
32
|
-
@
|
33
|
-
assert !@
|
33
|
+
@client = MongoClient.new(@@host, @@port)
|
34
|
+
assert !@client.slave_ok?
|
34
35
|
end
|
35
36
|
end
|
36
37
|
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
|
1
|
+
require 'test_helper'
|
2
2
|
require 'mongo'
|
3
3
|
require 'thread'
|
4
|
-
require 'test/unit'
|
5
|
-
require File.expand_path("../../test_helper", __FILE__)
|
6
4
|
|
7
5
|
# NOTE: This test requires bouncing the server.
|
8
6
|
# It also requires that a user exists on the admin database.
|
@@ -10,17 +8,17 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
10
8
|
include Mongo
|
11
9
|
|
12
10
|
def setup
|
13
|
-
@
|
14
|
-
@db1 = @
|
15
|
-
@db2 = @
|
16
|
-
@admin = @
|
11
|
+
@client = standard_connection(:pool_size => 10)
|
12
|
+
@db1 = @client.db('mongo-ruby-test-auth1')
|
13
|
+
@db2 = @client.db('mongo-ruby-test-auth2')
|
14
|
+
@admin = @client.db('admin')
|
17
15
|
end
|
18
16
|
|
19
17
|
def teardown
|
20
18
|
@db1.authenticate('user1', 'secret')
|
21
19
|
@db2.authenticate('user2', 'secret')
|
22
|
-
@
|
23
|
-
@
|
20
|
+
@client.drop_database('mongo-ruby-test-auth1')
|
21
|
+
@client.drop_database('mongo-ruby-test-auth2')
|
24
22
|
end
|
25
23
|
|
26
24
|
def threaded_exec
|
@@ -45,13 +43,13 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
45
43
|
|
46
44
|
threaded_exec do
|
47
45
|
assert_raise Mongo::OperationFailure do
|
48
|
-
@db1['stuff'].insert({:a => 2}
|
46
|
+
@db1['stuff'].insert({:a => 2})
|
49
47
|
end
|
50
48
|
end
|
51
49
|
|
52
50
|
threaded_exec do
|
53
51
|
assert_raise Mongo::OperationFailure do
|
54
|
-
@db2['stuff'].insert({:a => 2}
|
52
|
+
@db2['stuff'].insert({:a => 2})
|
55
53
|
end
|
56
54
|
end
|
57
55
|
|
@@ -59,11 +57,11 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
59
57
|
@db2.authenticate('user2', 'secret')
|
60
58
|
|
61
59
|
threaded_exec do
|
62
|
-
assert @db1['stuff'].insert({:a => 2}
|
60
|
+
assert @db1['stuff'].insert({:a => 2})
|
63
61
|
end
|
64
62
|
|
65
63
|
threaded_exec do
|
66
|
-
assert @db2['stuff'].insert({:a => 2}
|
64
|
+
assert @db2['stuff'].insert({:a => 2})
|
67
65
|
end
|
68
66
|
|
69
67
|
puts "Please bounce the server."
|
@@ -76,24 +74,24 @@ class AuthenticationTest < Test::Unit::TestCase
|
|
76
74
|
end
|
77
75
|
|
78
76
|
threaded_exec do
|
79
|
-
assert @db1['stuff'].insert({:a => 2}
|
77
|
+
assert @db1['stuff'].insert({:a => 2})
|
80
78
|
end
|
81
79
|
|
82
80
|
threaded_exec do
|
83
|
-
assert @db2['stuff'].insert({:a => 2}
|
81
|
+
assert @db2['stuff'].insert({:a => 2})
|
84
82
|
end
|
85
83
|
|
86
84
|
@db1.logout
|
87
85
|
threaded_exec do
|
88
86
|
assert_raise Mongo::OperationFailure do
|
89
|
-
@db1['stuff'].insert({:a => 2}
|
87
|
+
@db1['stuff'].insert({:a => 2})
|
90
88
|
end
|
91
89
|
end
|
92
90
|
|
93
91
|
@db2.logout
|
94
92
|
threaded_exec do
|
95
93
|
assert_raise Mongo::OperationFailure do
|
96
|
-
assert @db2['stuff'].insert({:a => 2}
|
94
|
+
assert @db2['stuff'].insert({:a => 2})
|
97
95
|
end
|
98
96
|
end
|
99
97
|
end
|
data/test/bson/binary_test.rb
CHANGED
data/test/bson/bson_test.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# encoding:utf-8
|
2
|
-
require
|
2
|
+
require 'test_helper'
|
3
3
|
require 'set'
|
4
4
|
|
5
5
|
if RUBY_VERSION < '1.9'
|
@@ -27,6 +27,18 @@ rescue LoadError
|
|
27
27
|
Zone = ActiveSupport::TimeWithZone.new(Time.now.utc, 'EST')
|
28
28
|
end
|
29
29
|
|
30
|
+
begin
|
31
|
+
require 'active_support/multibyte/chars'
|
32
|
+
rescue LoadError
|
33
|
+
warn 'Mocking ActiveSupport::Multibyte::Chars'
|
34
|
+
module ActiveSupport
|
35
|
+
module Multibyte
|
36
|
+
class Chars < String
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
30
42
|
class BSONTest < Test::Unit::TestCase
|
31
43
|
|
32
44
|
include BSON
|
@@ -70,6 +82,17 @@ class BSONTest < Test::Unit::TestCase
|
|
70
82
|
assert_doc_pass(doc)
|
71
83
|
end
|
72
84
|
|
85
|
+
def test_valid_active_support_multibyte_chars
|
86
|
+
unless RUBY_PLATFORM =~ /java/
|
87
|
+
doc = {'doc' => ActiveSupport::Multibyte::Chars.new('aé')}
|
88
|
+
assert_doc_pass(doc)
|
89
|
+
|
90
|
+
bson = @encoder.serialize(doc)
|
91
|
+
doc = @encoder.deserialize(bson)
|
92
|
+
assert_equal doc['doc'], 'aé'
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
73
96
|
def test_valid_utf8_key
|
74
97
|
doc = {'aé' => 'hello'}
|
75
98
|
assert_doc_pass(doc)
|
@@ -101,12 +124,11 @@ class BSONTest < Test::Unit::TestCase
|
|
101
124
|
# In 1.8 we test that other string encodings raise an exception.
|
102
125
|
# In 1.9 we test that they get auto-converted.
|
103
126
|
if RUBY_VERSION < '1.9'
|
104
|
-
|
127
|
+
unless RUBY_PLATFORM == 'java'
|
105
128
|
require 'iconv'
|
106
129
|
def test_non_utf8_string
|
107
130
|
string = Iconv.conv('iso-8859-1', 'utf-8', 'aé')
|
108
131
|
doc = {'doc' => string}
|
109
|
-
assert_doc_pass(doc)
|
110
132
|
assert_raise InvalidStringEncoding do
|
111
133
|
@encoder.serialize(doc)
|
112
134
|
end
|
@@ -121,48 +143,50 @@ class BSONTest < Test::Unit::TestCase
|
|
121
143
|
end
|
122
144
|
end
|
123
145
|
else
|
124
|
-
|
125
|
-
|
126
|
-
BSON::
|
146
|
+
unless RUBY_PLATFORM == 'java'
|
147
|
+
def test_non_utf8_string
|
148
|
+
assert_raise BSON::InvalidStringEncoding do
|
149
|
+
BSON::BSON_CODER.serialize({'str' => 'aé'.encode('iso-8859-1')})
|
150
|
+
end
|
127
151
|
end
|
128
|
-
end
|
129
152
|
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
153
|
+
def test_invalid_utf8_string
|
154
|
+
str = "123\xD9"
|
155
|
+
assert !str.valid_encoding?
|
156
|
+
assert_raise BSON::InvalidStringEncoding do
|
157
|
+
BSON::BSON_CODER.serialize({'str' => str})
|
158
|
+
end
|
135
159
|
end
|
136
|
-
end
|
137
160
|
|
138
|
-
|
139
|
-
|
140
|
-
|
161
|
+
def test_non_utf8_key
|
162
|
+
assert_raise BSON::InvalidStringEncoding do
|
163
|
+
BSON::BSON_CODER.serialize({'aé'.encode('iso-8859-1') => 'hello'})
|
164
|
+
end
|
141
165
|
end
|
142
|
-
end
|
143
166
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
167
|
+
def test_forced_encoding_with_valid_utf8
|
168
|
+
doc = {'doc' => "\xC3\xB6".force_encoding("ISO-8859-1")}
|
169
|
+
serialized = @encoder.serialize(doc)
|
170
|
+
deserialized = @encoder.deserialize(serialized)
|
171
|
+
assert_equal(doc['doc'], deserialized['doc'].force_encoding("ISO-8859-1"))
|
172
|
+
end
|
150
173
|
|
151
|
-
|
152
|
-
|
153
|
-
|
174
|
+
# Based on a test from sqlite3-ruby
|
175
|
+
def test_default_internal_is_honored
|
176
|
+
before_enc = Encoding.default_internal
|
154
177
|
|
155
|
-
|
156
|
-
|
178
|
+
str = "壁に耳あり、障子に目あり"
|
179
|
+
bson = BSON::BSON_CODER.serialize("x" => str)
|
157
180
|
|
158
|
-
|
159
|
-
|
181
|
+
silently { Encoding.default_internal = 'EUC-JP' }
|
182
|
+
out = BSON::BSON_CODER.deserialize(bson)["x"]
|
160
183
|
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
184
|
+
assert_equal Encoding.default_internal, out.encoding
|
185
|
+
assert_equal str.encode('EUC-JP'), out
|
186
|
+
assert_equal str, out.encode(str.encoding)
|
187
|
+
ensure
|
188
|
+
silently { Encoding.default_internal = before_enc }
|
189
|
+
end
|
166
190
|
end
|
167
191
|
end
|
168
192
|
|
@@ -287,7 +311,7 @@ class BSONTest < Test::Unit::TestCase
|
|
287
311
|
end
|
288
312
|
|
289
313
|
def test_date_before_epoch
|
290
|
-
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ then return true end
|
314
|
+
if RbConfig::CONFIG['host_os'] =~ /mswin|mingw|cygwin/ then return true end
|
291
315
|
begin
|
292
316
|
doc = {'date' => Time.utc(1600)}
|
293
317
|
bson = @encoder.serialize(doc)
|