Skip to content

Commit

Permalink
Updated tests to match new preprocessors
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 3, 2013
1 parent 7a54337 commit 3460e87
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 35 deletions.
78 changes: 49 additions & 29 deletions test/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand All @@ -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);
});
});
});
Expand Down
7 changes: 1 addition & 6 deletions test/model.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 3460e87

Please sign in to comment.