Permalink
Browse files

closer to alphaness

  • Loading branch information...
1 parent a95dd74 commit 1699632824df2d08ec2b527b4f0bc4cf67ab8d4d unknown committed Dec 30, 2009
Showing with 40 additions and 16 deletions.
  1. +10 −3 components/MongoDB.cfc
  2. +1 −3 components/MongoDocument.cfc
  3. +17 −0 test/MongoDocumentTest.cfc
  4. +12 −10 test/ObjectMappingTest.cfc
@@ -58,13 +58,20 @@ function config(){
builder = createObject('component','ExpressionBuilder');
-// TO DO: loose the reference to duplicate(this)!!!
-//This has a bad smell ...
+ // TO DO: loose the reference to duplicate(this)!!!
+ // This has a bad smell ...
function new_doc(collection_name){
var document = createObject('component','MongoDocument').factory_init( collection_name, duplicate(this) );
return document;
}
-
+
+//Returns a document object based on the model
+function build_doc(model){
+ var document = createObject('component','MongoDocument');
+ document.model = model;
+ return document;
+}
+
function getMongo(){
return mongo;
@@ -94,8 +94,6 @@
</cffunction>
-<cffunction name="validate" hint="Should be called before save() to perform any required validation. NOT IMPLEMENTED" returntype="void">
-
-</cffunction>
+<cffunction name="validate" hint="Should be called before save() to perform any required validation. NOT IMPLEMENTED" returntype="void"></cffunction>
</cfcomponent>
@@ -0,0 +1,17 @@
+<cfcomponent extends="BaseTest" output="false">
+<cfscript>
+function testBuild(){
+ mongo = createObject('component','cfmongodb.components.MongoDB');
+
+ prog = mongo.new_doc('programmers');
+ prog.set('name','bill');
+ prog.save();
+ debug(prog);
+ prog2 = mongo.build_doc( prog );
+ debug(prog2);
+ assertNotSame( prog, prog2 );
+ assertEquals( prog, prog2 );
+
+}
+</cfscript>
+</cfcomponent>
@@ -3,35 +3,37 @@
function dbRefTest(){
mongo = createObject('component','cfmongodb.components.MongoDB');
-
db = mongo.getDb('default_db');
-
-
+
prog = mongo.new_doc('programmers');
- // //should be in mongo wrapper!
prog.set('name','bill');
pid = prog.save();
prog2 = mongo.new_doc('programmers');
- // //should be in mongo wrapper!
prog2.set('name','pete');
pid2 = prog2.save();
- //ref = createObject('java','com.mongodb.DBRef').init( db, 'programmers', pid);
ref1 = mongo.dbRef('programmers', pid);
ref2 = mongo.dbRef('programmers', pid2);
+
refs = [ ref1, ref2 ];
proj = mongo.new_doc('projects');
proj.set('foo','bar');
proj.set('programers', refs);
id = proj.save();
- debug(id);
- debug(proj);
+ debug(prog);
+ // debug(proj);
+
+ progz = proj.get('programers'); //getDbRef() ???
+ bill = progz[1].fetch();
+ debug(bill);
+
+ assertEquals( 'bill' , bill.get('name') );
- progz = proj.get('programers');
- debug(progz[1].fetch());
+ bill = progz[1].fetch();
+ assertEquals( 'bill' , bill.get('name'));
proj.delete();
prog.delete();

0 comments on commit 1699632

Please sign in to comment.