From 412a46d6034ace0d17706ae418356f52174b530b Mon Sep 17 00:00:00 2001 From: Anatoliy Chakkaev Date: Sun, 10 Feb 2013 04:15:43 +0800 Subject: [PATCH] FIxed test for belongsTo --- test/common_test.js | 51 ++++++++++++++++++++------------------------- 1 file changed, 23 insertions(+), 28 deletions(-) diff --git a/test/common_test.js b/test/common_test.js index 2df25533..202518fa 100644 --- a/test/common_test.js +++ b/test/common_test.js @@ -533,43 +533,38 @@ function testOrm(schema) { }); it('should navigate variations of belongsTo regardless of column name', function(test){ - test.expect(7); - - var Schema = require('jugglingdb').Schema; - var schema = new Schema('memory', {}); - + var Dog = schema.define('Dog', { owner_id : { type: Number, allowNull: true }, name : { type: String, limit: 64, allowNull: false } }); - + var Log = schema.define('Log', { owner_id : { type: Number, allowNull: true }, name : { type: String, limit: 64, allowNull: false } }); - + Log.belongsTo(Dog, {as: 'owner', foreignKey: 'owner_id'}); - - schema.automigrate(function(){ - Dog.create({name: 'theDog'}, function(err, obj){ - test.ok(obj instanceof Dog); - Log.create({name: 'theLog', owner_id: 1}, function(err, obj){ - test.ok(obj instanceof Log); - obj.owner(function(err, obj){ - test.ok(!err, 'Should not have an error.'); // Before cba174b this would be 'Error: Permission denied' - if(err){ - console.log('Found: ' + err); - } - test.ok(obj, 'Should not find null or undefined.'); // Before cba174b this could be null or undefined. - test.ok(obj instanceof Dog, 'Should find a Dog.'); - if(obj){ // Since test won't stop on fail, have to check before accessing obj.name. - test.ok(obj.name, 'Should have a name.'); - } - if(obj && obj.name){ - test.equal(obj.name, 'theDog', 'The owner of theLog is theDog.'); - } - test.done(); - }); + + Dog.create({name: 'theDog'}, function(err, obj){ + test.ok(obj instanceof Dog); + Log.create({name: 'theLog', owner_id: obj.id}, function(err, obj){ + test.ok(obj instanceof Log); + obj.owner(function(err, obj){ + console.log(err, obj); + test.ok(!err, 'Should not have an error.'); // Before cba174b this would be 'Error: Permission denied' + if(err){ + console.log('Found: ' + err); + } + test.ok(obj, 'Should not find null or undefined.'); // Before cba174b this could be null or undefined. + test.ok(obj instanceof Dog, 'Should find a Dog.'); + if(obj){ // Since test won't stop on fail, have to check before accessing obj.name. + test.ok(obj.name, 'Should have a name.'); + } + if(obj && obj.name){ + test.equal(obj.name, 'theDog', 'The owner of theLog is theDog.'); + } + test.done(); }); }); });