added tests for copy_database
This commit is contained in:
parent
ba51e345f9
commit
20ed768460
|
@ -120,18 +120,17 @@ module Mongo
|
|||
single_db_command(name, :dropDatabase => 1)
|
||||
end
|
||||
|
||||
# Copys the database +from+ on +host+ to +to+ on the executing server.
|
||||
# +host+ is optional and will use localhost host if no value is provided.
|
||||
def copy_database( from, to, host="localhost" )
|
||||
# Copies the database +from+ on the local server to +to+ on the specified +host+.
|
||||
# +host+ defaults to 'localhost' if no value is provided.
|
||||
def copy_database(from, to, host="localhost")
|
||||
oh = OrderedHash.new
|
||||
oh[:copydb]= 1
|
||||
oh[:copydb] = 1
|
||||
oh[:fromhost] = host
|
||||
oh[:fromdb] = from
|
||||
oh[:todb] = to
|
||||
oh[:fromdb] = from
|
||||
oh[:todb] = to
|
||||
single_db_command('admin', oh)
|
||||
end
|
||||
|
||||
|
||||
# Return the build information for the current connection.
|
||||
def server_info
|
||||
db("admin").command({:buildinfo => 1}, {:admin => true, :check_response => true})
|
||||
|
|
|
@ -53,6 +53,14 @@ class TestConnection < Test::Unit::TestCase
|
|||
@mongo.drop_database('ruby-mongo-info-test')
|
||||
end
|
||||
|
||||
def test_copy_database
|
||||
@mongo.db('old').collection('copy-test').insert('a' => 1)
|
||||
@mongo.copy_database('old', 'new')
|
||||
old_object = @mongo.db('old').collection('copy-test').find.next_object
|
||||
new_object = @mongo.db('new').collection('copy-test').find.next_object
|
||||
assert_equal old_object, new_object
|
||||
end
|
||||
|
||||
def test_database_names
|
||||
@mongo.drop_database('ruby-mongo-info-test')
|
||||
@mongo.db('ruby-mongo-info-test').collection('info-test').insert('a' => 1)
|
||||
|
|
Loading…
Reference in New Issue