Merge pull request #13 from strongloop/feature/discovery-test

Feature/discovery test
This commit is contained in:
Raymond Feng 2013-12-06 08:25:34 -08:00
commit 7b497b9a2e
2 changed files with 28 additions and 4 deletions

View File

@ -31,9 +31,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
s.supportBigNumbers = (s.supportBigNumbers || false);
s.timezone = (s.timezone || 'local');
if(isNaN(s.connectionLimit)) {
s.connectionLimit = s.connectionLimit;
} else {
if(!isNaN(s.connectionLimit)) {
s.connectionLimit = 10;
}
@ -473,7 +471,7 @@ MySQL.prototype.all = function all(model, filter, callback) {
if (!filter.order) {
var idNames = this.idNames(model);
if (idNames && idNames.length) {
filter.order = idNames.join(' ');
filter.order = idNames;
}
}

View File

@ -7,6 +7,7 @@ var db;
before(function() {
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
config.database = 'STRONGLOOP';
db = new DataSource(require('../'), config);
});
@ -192,3 +193,28 @@ describe('Discover LDL schema from a table', function () {
});
});
});
describe('Discover and build models', function () {
it('should discover and build models', function (done) {
db.discoverAndBuildModels('INVENTORY', {owner: 'STRONGLOOP', visited: {}, associations: true}, function (err, models) {
assert(models.Inventory, 'Inventory model should be discovered and built');
var schema = models.Inventory.definition;
assert(schema.settings.mysql.schema === 'STRONGLOOP');
assert(schema.settings.mysql.table === 'INVENTORY');
assert(schema.properties.productId);
assert(schema.properties.productId.type === String);
assert(schema.properties.productId.mysql.columnName === 'PRODUCT_ID');
assert(schema.properties.locationId);
assert(schema.properties.locationId.type === String);
assert(schema.properties.locationId.mysql.columnName === 'LOCATION_ID');
assert(schema.properties.available);
assert(schema.properties.available.type === Number);
assert(schema.properties.total);
assert(schema.properties.total.type === Number);
models.Inventory.findOne(function (err, inv) {
assert(!err, 'error should not be reported');
done();
});
});
});
});