Fix the test case with automigrate

This commit is contained in:
Raymond Feng 2015-07-30 11:24:47 -07:00
parent 78bb13db97
commit 6513d9658f
1 changed files with 35 additions and 31 deletions

View File

@ -1235,24 +1235,27 @@ module.exports = function(dataSource, should) {
});
it('applies updates from `persist` hook - for nested model instance', function(done) {
var Address = dataSource.createModel('Address', {
var Address = dataSource.createModel('NestedAddress', {
id: { type: String, id: true, default: 1 },
city: { type: String, required: true },
country: { type: String, required: true }
});
var User = dataSource.createModel('User', {
var User = dataSource.createModel('UserWithAddress', {
id: { type: String, id: true, default: uid() },
name: { type: String, required: true },
address: {type: Address, required: false}
address: {type: Address, required: false},
extra: {type: String}
});
dataSource.automigrate(['UserWithAddress', 'NestedAddress'], function(err) {
if (err) return done(err);
User.create({name: 'Joe'}, function(err, instance) {
if (err) return done(err);
var existingUser = instance;
User.observe('persist', pushContextAndNext(function(ctx){
User.observe('persist', pushContextAndNext(function(ctx) {
should.exist(ctx.data.address)
ctx.data.address.should.be.type('object');
ctx.data.address.should.not.be.instanceOf(Address);
@ -1266,7 +1269,7 @@ module.exports = function(dataSource, should) {
// which if set, will apply these changes to the model instance too.
User.settings.updateOnLoad = true;
existingUser.updateAttributes(
{ address: new Address({city: 'Springfield', country: 'USA'}) },
{address: new Address({city: 'Springfield', country: 'USA'})},
function(err, inst) {
if (err) return done(err);
@ -1285,6 +1288,7 @@ module.exports = function(dataSource, should) {
});
});
});
});
it('triggers `loaded` hook', function(done) {
TestModel.observe('loaded', pushContextAndNext());