Skip to content

Commit

Permalink
Added additional tests for _id inferrence
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 13, 2013
1 parent 1bafab7 commit 6b1b729
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 3 deletions.
56 changes: 54 additions & 2 deletions test/findOne.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,67 @@ 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) {
model.findOne({ name: 'NotFound' }, function(err, obj) {
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();
});
});
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ describe('orm', function () {

it('should provide the full model API', function() {
var api = [
'preprocessors',
'preprocessor',
'options',
'schema',
'database',
Expand Down

0 comments on commit 6b1b729

Please sign in to comment.