Bug fix on Collection#rename
This commit is contained in:
parent
87abd62615
commit
9d25efece4
|
@ -635,6 +635,8 @@ module Mongo
|
||||||
#
|
#
|
||||||
# @param [String] new_name the new name for this collection
|
# @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.
|
# @raise [Mongo::InvalidNSName] if +new_name+ is an invalid collection name.
|
||||||
def rename(new_name)
|
def rename(new_name)
|
||||||
case new_name
|
case new_name
|
||||||
|
@ -656,6 +658,7 @@ module Mongo
|
||||||
end
|
end
|
||||||
|
|
||||||
@db.rename_collection(@name, new_name)
|
@db.rename_collection(@name, new_name)
|
||||||
|
@name = new_name
|
||||||
end
|
end
|
||||||
|
|
||||||
# Get information on the indexes for this collection.
|
# Get information on the indexes for this collection.
|
||||||
|
|
|
@ -67,6 +67,17 @@ class TestCollection < Test::Unit::TestCase
|
||||||
assert_equal 5, @@db.collection("test.foo").find_one()["x"]
|
assert_equal 5, @@db.collection("test.foo").find_one()["x"]
|
||||||
end
|
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
|
def test_nil_id
|
||||||
assert_equal 5, @@test.insert({"_id" => 5, "foo" => "bar"}, {:safe => true})
|
assert_equal 5, @@test.insert({"_id" => 5, "foo" => "bar"}, {:safe => true})
|
||||||
assert_equal 5, @@test.save({"_id" => 5, "foo" => "baz"}, {:safe => true})
|
assert_equal 5, @@test.save({"_id" => 5, "foo" => "baz"}, {:safe => true})
|
||||||
|
|
Loading…
Reference in New Issue