diff --git a/test/findOne.js b/test/findOne.js index d6df239..1974fdf 100644 --- a/test/findOne.js +++ b/test/findOne.js @@ -50,7 +50,16 @@ describe('orm', function () { should.exist(obj); obj.should.have.ownProperty('name', 'Demo1'); done(); - }) + }); + }); + + it('should be able to infer the _id field', function(done) { + model.findOne('Demo1', function(err, obj) { + if(err) return done(err); + should.exist(obj); + obj.should.have.ownProperty('name', 'Demo1'); + done(); + }); }); it('should not throw an error if it couldn\'t find an object', function(done) { @@ -58,7 +67,50 @@ describe('orm', function () { if(err) return done(err); should.not.exist(obj); done(); - }) + }); + }); + + describe('with default model', function() { + before(function(done) { + model = new Model(db, 'model', { + name: /.+/ + }, { + + }); + + model.remove(function(err) { + if(err) return done(err); + + model.create({ + name: 'Demo1' + }, function(err, instance) { + if(err) return done(err); + return done(); + }); + }); + }); + + var d1instance = null; + + it('should correctly be able to find using conditions', function(done) { + model.findOne({ name: 'Demo1' }, function(err, obj) { + if(err) return done(err); + should.exist(obj); + obj.should.have.ownProperty('name', 'Demo1'); + d1instance = obj; + done(); + }); + }); + + it('should correctly infer the _id field and convert conditions', function(done) { + model.findOne(d1instance.id, function(err, obj) { + if(err) return done(err); + should.exist(obj); + obj.should.have.ownProperty('id').with.type('string'); + obj.should.have.ownProperty('name', 'Demo1'); + done(); + }); + }); }); }); }); diff --git a/test/model.js b/test/model.js index 6bdeadf..b60b6f9 100644 --- a/test/model.js +++ b/test/model.js @@ -43,7 +43,7 @@ describe('orm', function () { it('should provide the full model API', function() { var api = [ - 'preprocessors', + 'preprocessor', 'options', 'schema', 'database',