minor: allow oplog. collection

This commit is contained in:
Kyle Banker 2009-12-04 16:35:12 -05:00
parent 4550389480
commit f0766c9d2e
2 changed files with 12 additions and 3 deletions

View File

@ -33,8 +33,8 @@ module Mongo
if name.empty? or name.include? ".."
raise InvalidName, "collection names cannot be empty"
end
if name.include? "$" and not name.match(/^\$cmd/)
raise InvalidName, "collection names must not contain '$'"
if name.include? "$"
raise InvalidName, "collection names must not contain '$'" unless name =~ /((^\$cmd)|(oplog\.\$main))/
end
if name.match(/^\./) or name.match(/\.$/)
raise InvalidName, "collection names must not start or end with '.'"

View File

@ -26,11 +26,20 @@ class TestCollection < Test::Unit::TestCase
assert @coll.pk_factory.is_a?(Object)
end
def test_collection
def test_valid_names
assert_raise InvalidName do
@@db["te$t"]
end
assert_raise InvalidName do
@@db['$main']
end
assert @@db['$cmd']
assert @@db['oplog.$main']
end
def test_collection
assert_kind_of Collection, @@db["test"]
assert_equal @@db["test"].name(), @@db.collection("test").name()
assert_equal @@db["test"].name(), @@db[:test].name()