Skip to content

Commit

Permalink
Fixed bug with DB.createCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
poiati committed Jul 3, 2010
1 parent 6b8f018 commit e9ff5db
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/main/groovy/com/gmongo/internal/DBPatcher.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ package com.gmongo.internal

class DBPatcher {

static final PATCHED_METHODS = [ 'command' ]
static final PATCHED_METHODS = [ 'command', 'createCollection' ]

static final AFTER_RETURN = [
createCollection: { defaultArgs, result ->
DBCollectionPatcher.patch result
}
]

static patch(db) {
if (db.hasProperty(Patcher.PATCH_MARK)) return
Expand All @@ -41,7 +47,7 @@ class DBPatcher {
delegate.requestDone()
}
}
Patcher._patchInternal db, PATCHED_METHODS
Patcher._patchInternal db, PATCHED_METHODS, [:], [:], AFTER_RETURN
}

private static _patchedCollection(c) {
Expand Down
12 changes: 12 additions & 0 deletions src/test/groovy/com/gmongo/DBTest.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class DBTest extends IntegrationTestCase {
void setUp() {
super.setUp()
db = mongo.getDB(DB_NAME)
db.dropDatabase()
}

void testGetCollection() {
Expand Down Expand Up @@ -67,6 +68,17 @@ class DBTest extends IntegrationTestCase {
assertTrue started && ended
}

void testCollectionExists() {
assertFalse db.collectionExists('baz')
db.baz.insert(foo: 10)
assertTrue db.collectionExists('baz')
}

void testCreateCollection() {
def c = db.createCollection("foo", [capped: true, size: 100000])
assert c.hasProperty(Patcher.PATCH_MARK)
}

void testInRequest() {
db.inRequest {->
db.foo.insert(bar: 10)
Expand Down

0 comments on commit e9ff5db

Please sign in to comment.