diff --git a/test/instance.js b/test/instance.js index eaee25a..7ce94e4 100644 --- a/test/instance.js +++ b/test/instance.js @@ -32,44 +32,56 @@ describe('orm', function () { describe('constructor', function () { it('should present all properties of the document', function () { - var i = new Instance({}, { - _id: 'custom_id', + var model = new Model(null, 'model', { + name: String + }, { + preprocessors: [] + }) + + var i = new Instance(model, { + id: 'custom_id', name: 'name' - }, {}); + }); i.should.have.property('id', 'custom_id'); i.should.have.property('name', 'name'); }); it('should allow renaming of properties', function () { - var i = new Instance({}, { + var model = new Model(null, 'model', { + pretty: String + },{ + preprocessors: [ + new Database.Rename({ + uglyName: 'pretty' + }) + ] + }); + + var i = new Instance(model, { _id: 'custom_id', uglyName: 'value' - }, { - rename: { - uglyName: 'pretty' - } }); i.should.have.property('pretty', 'value'); }); it('should allow the creation of methods', function () { - var i = new Instance({}, { - _id: 'custom_id' - }, { + var model = new Model(null, 'model', {}, { methods: { - test: function () { return true; } + test: function() { return true; } } }); + var i = new Instance(model, { + _id: 'custom_id' + }); + i.test().should.equal(true); }); it('should correctly pass all arguments to a method', function () { - var i = new Instance({}, { - _id: 'custom_id' - }, { + var model = new Model(null, 'model', {}, { methods: { test: function (a, b, c) { should.equal(a, 'a'); @@ -79,41 +91,49 @@ describe('orm', function () { } }); + var i = new Instance(model, { + _id: 'custom_id' + }); + i.test('a', 'b', 'c'); }); it('should allow the creation of virtual properties', function () { - var i = new Instance({}, { - _id: 'custom_id', - firstname: 'Billy', - lastname: 'Bob' - }, { + var model = new Model(null, 'model', {}, { virtuals: { fullname: function () { return this.firstname + ' ' + this.lastname; } } }); + var i = new Instance(model, { + _id: 'custom_id', + firstname: 'Billy', + lastname: 'Bob' + }); + i.fullname.should.equal('Billy Bob'); }); it('should allow a custom schema', function () { - var i = new Instance({}, { - _id: 'custom_id', - name: 'name' - }, { - schema: { + var model = new Model(null, 'model', { name: String, age: { type: Number, required: false } - } + }, { + preprocessors: [] + }); + + var i = new Instance(model, { + id: 'custom_id', + name: 'name' }); (function () { i.age = 'hello'; }).should.throwError(); - i.should.have.property('id', 'custom_id'); - i.should.have.property('name', 'name'); - i.should.have.property('age', null); + i.should.have.ownProperty('id', 'custom_id'); + i.should.have.ownProperty('name', 'name'); + i.should.have.ownProperty('age', null); }); }); }); diff --git a/test/model.js b/test/model.js index 2269b28..5ea66f4 100644 --- a/test/model.js +++ b/test/model.js @@ -37,12 +37,7 @@ describe('orm', function () { model = new Model(db, 'model', { name: /.+/ }, { - rename: { - _id: 'name' - }, - transforms: { - _id: false - } + preprocessors: [new Database.Rename({ _id: 'name' })] }); model.remove(done);