added tests for copy_database

This commit is contained in:
Kyle Banker 2009-11-04 11:57:03 -05:00
parent ba51e345f9
commit 20ed768460
2 changed files with 14 additions and 7 deletions

View File

@ -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})

View File

@ -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)