Skip to content

Commit

Permalink
Added tests for new getter/setter virtuals
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Dec 5, 2013
1 parent 3a248cc commit 63e35cf
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/instance.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,32 @@ describe('orm', function () {
i.fullname.should.equal('Billy Bob');
});

it('should allow the creation of virtual getter/setters', function() {
var model = new Model(null, 'model', {}, {
virtuals: {
fullname: {
get: function () { return this.firstname + ' ' + this.lastname; },
set: function(value) {
this.firstname = value.split(' ')[0];
this.lastname = value.split(' ')[1];
}
}
}
});

var i = new Instance(model, {
_id: 'custom_id',
firstname: 'Billy',
lastname: 'Bob'
});

i.fullname.should.equal('Billy Bob');

i.fullname = 'Sally Jane';
i.firstname.should.equal('Sally');
i.lastname.should.equal('Jane');
});

it('should allow a custom schema', function () {
var model = new Model(null, 'model', {
name: String,
Expand Down

0 comments on commit 63e35cf

Please sign in to comment.