Merge pull request #13 from strongloop/feature/discovery-test
Feature/discovery test
This commit is contained in:
commit
7b497b9a2e
|
@ -31,9 +31,7 @@ exports.initialize = function initializeDataSource(dataSource, callback) {
|
||||||
s.supportBigNumbers = (s.supportBigNumbers || false);
|
s.supportBigNumbers = (s.supportBigNumbers || false);
|
||||||
s.timezone = (s.timezone || 'local');
|
s.timezone = (s.timezone || 'local');
|
||||||
|
|
||||||
if(isNaN(s.connectionLimit)) {
|
if(!isNaN(s.connectionLimit)) {
|
||||||
s.connectionLimit = s.connectionLimit;
|
|
||||||
} else {
|
|
||||||
s.connectionLimit = 10;
|
s.connectionLimit = 10;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -473,7 +471,7 @@ MySQL.prototype.all = function all(model, filter, callback) {
|
||||||
if (!filter.order) {
|
if (!filter.order) {
|
||||||
var idNames = this.idNames(model);
|
var idNames = this.idNames(model);
|
||||||
if (idNames && idNames.length) {
|
if (idNames && idNames.length) {
|
||||||
filter.order = idNames.join(' ');
|
filter.order = idNames;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,6 +7,7 @@ var db;
|
||||||
|
|
||||||
before(function() {
|
before(function() {
|
||||||
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
|
var config = require('rc')('loopback', {dev: {mysql: {}}}).dev.mysql;
|
||||||
|
config.database = 'STRONGLOOP';
|
||||||
db = new DataSource(require('../'), config);
|
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();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue