From f0766c9d2e660aeee0560cf4e4e1ea0652b6c491 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Fri, 4 Dec 2009 16:35:12 -0500 Subject: [PATCH] minor: allow oplog. collection --- lib/mongo/collection.rb | 4 ++-- test/test_collection.rb | 11 ++++++++++- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/lib/mongo/collection.rb b/lib/mongo/collection.rb index d717ed2..9a913a2 100644 --- a/lib/mongo/collection.rb +++ b/lib/mongo/collection.rb @@ -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 '.'" diff --git a/test/test_collection.rb b/test/test_collection.rb index 59130ad..bc0eea5 100644 --- a/test/test_collection.rb +++ b/test/test_collection.rb @@ -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()