diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index ad2309f..c0e057c 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -635,6 +635,8 @@ module Mongo # # @param [String] new_name the new name for this collection # + # @return [String] the name of the new collection. + # # @raise [Mongo::InvalidNSName] if +new_name+ is an invalid collection name. def rename(new_name) case new_name @@ -656,6 +658,7 @@ module Mongo end @db.rename_collection(@name, new_name) + @name = new_name end # Get information on the indexes for this collection. diff --git a/test/collection_test.rb b/test/collection_test.rb index e1c6f1c..b7acd00 100644 --- a/test/collection_test.rb +++ b/test/collection_test.rb @@ -67,6 +67,17 @@ class TestCollection < Test::Unit::TestCase assert_equal 5, @@db.collection("test.foo").find_one()["x"] end + def test_rename_collection + @@db.drop_collection('foo1') + @@db.drop_collection('bar1') + + @col = @@db.create_collection('foo1') + assert_equal 'foo1', @col.name + + @col.rename('bar1') + assert_equal 'bar1', @col.name + end + def test_nil_id assert_equal 5, @@test.insert({"_id" => 5, "foo" => "bar"}, {:safe => true}) assert_equal 5, @@test.save({"_id" => 5, "foo" => "baz"}, {:safe => true})